Skip to content

Commit

Permalink
Feat: adiciona saída estruturada no gemini_extrair.R
Browse files Browse the repository at this point in the history
  • Loading branch information
jjesusfilho authored Oct 15, 2024
1 parent c465216 commit bd09a81
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions R/gemini_extrair.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @param perguntas Vetor de perguntas.
#' @param colunas Vetor de colunas.
#' @param modelo Modelo do Gemini
#' @param saida Padrão para "application/json"
#' @param temperatura Nível de aleatoriedade. Padrão: 0, ou seja, determinístico.
#' @param max_output_tokens = Número máximo na resposta.
#' @param top_p Máxima probabilidade cumulativa para a amostra de tokens.
Expand All @@ -21,7 +22,8 @@ gemini_extrair <- function(x,
instrucao,
perguntas,
colunas,
modelo = "gemini-1.5-pro-latest",
modelo = "gemini-1.5-flash",
saida = "application/json",
temperatura = 0,
max_output_tokens = 4000,
top_p = 0.4,
Expand All @@ -32,7 +34,7 @@ gemini_extrair <- function(x,
api_key = Sys.getenv("GEMINI_API_KEY")
}
uri <- glue::glue("https://generativelanguage.googleapis.com/v1beta/models/{modelo}:generateContent?key={api_key}")


headers <- c(`Content-Type`="application/json")

Expand All @@ -45,26 +47,27 @@ gemini_extrair <- function(x,
{perguntas}
Retorne as respostas em formato json com as seguintes chaves: {colunas}")
)),
`safetySettings` = list(
list(category = "HARM_CATEGORY_HARASSMENT",
threshold = "BLOCK_NONE"),
list(category = "HARM_CATEGORY_HATE_SPEECH",
threshold = "BLOCK_NONE"),
list(category = "HARM_CATEGORY_DANGEROUS_CONTENT",
threshold = "BLOCK_NONE"),
list(category = "HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold = "BLOCK_NONE")
),

`generationConfig` = list(
temperature = temperatura,
`maxOutputTokens` = max_output_tokens,
topP = top_p,
topK = top_k
)


)
`safetySettings` = list(
list(category = "HARM_CATEGORY_HARASSMENT",
threshold = "BLOCK_NONE"),
list(category = "HARM_CATEGORY_HATE_SPEECH",
threshold = "BLOCK_NONE"),
list(category = "HARM_CATEGORY_DANGEROUS_CONTENT",
threshold = "BLOCK_NONE"),
list(category = "HARM_CATEGORY_SEXUALLY_EXPLICIT",
threshold = "BLOCK_NONE")
),

`generationConfig` = list(
`response_mime_type` = saida,
temperature = temperatura,
`maxOutputTokens` = max_output_tokens,
topP = top_p,
topK = top_k
)


)


taxa <- purrr::rate_delay(0.2, max_times = 3)
Expand All @@ -89,4 +92,3 @@ Retorne as respostas em formato json com as seguintes chaves: {colunas}")
extrair <- purrr::insistently(.f, taxa, quiet = FALSE)
extrair()
}

0 comments on commit bd09a81

Please sign in to comment.