Skip to contents

This function lets the user interact with Google's Gemini LLM Model using its API, and returns the rendered reply.

Usage

gemini_ask(
  ask,
  secret_key = get_creds("gemini")$api_key,
  url = Sys.getenv("LARES_GEMINI_API"),
  temperature = 0.5,
  max_tokens = 1024,
  quiet = FALSE,
  ...
)

gemini_image(
  ask,
  image,
  secret_key = get_creds("gemini")$api_key,
  url = Sys.getenv("LARES_GEMINI_API"),
  temperature = 0.5,
  max_tokens = 1024,
  quiet = FALSE,
  ...
)

Arguments

ask

Character. Redacted prompt to ask. If multiple asks are requested, they will be concatenated with "+" into a single request.

secret_key

Character. Secret Key. Get yours in: platform.openai.com for OpenAI or makersuite.google.com for Gemini.

url

Character. Base API URL.

temperature

Numeric. The temperature to use for generating the response. Default is 0.5. The lower the temperature, the more deterministic the results in the sense that the highest probable next token is always picked. Increasing temperature could lead to more randomness, which encourages more diverse or creative outputs. You are essentially increasing the weights of the other possible tokens. In terms of application, you might want to use a lower temperature value for tasks like fact-based QA to encourage more factual and concise responses. For poem generation or other creative tasks, it might be beneficial to increase the temperature value.

max_tokens

Integer. The maximum number of tokens in the response.

quiet

Boolean. Keep quiet? If not, message will be shown.

...

Additional parameters.

image

Character. Data to be encoded/decoded. It can be a raw vector, text connection or file name.

Value

(Invisible) list. Content returned from API POST and processed.

Examples

if (FALSE) {
api_key <- get_credentials()$gemini$api_key
# Open question:
gemini_ask("Can you write an R function to plot a dummy histogram?", api_key)
# Image question
image <- "man/figures/automl_map.png"
gemini_image("Can you explain this flow with more detail?", image, api_key)
}