gemini_structured: Generate structured response from Gemini

View source: R/gemini_structured.R

gemini_structuredR Documentation

Generate structured response from Gemini

Description

Returns a structured (JSON) response from the Gemini API.

Usage

gemini_structured(
  prompt,
  schema,
  model = "2.5-flash",
  temperature = 1,
  maxOutputTokens = 8192,
  topK = 40,
  topP = 0.95,
  seed = 1234,
  timeout = 60
)

Arguments

prompt

The prompt (question) to send to the model.

schema

JSON schema (as a list) for the expected response.

model

Model to use. Default is '2.5-flash'.

temperature

Sampling temperature. Default is 1.

maxOutputTokens

Maximum number of output tokens. Default is 8192.

topK

Top-k value. Default is 40.

topP

Top-p value. Default is 0.95.

seed

Random seed. Default is 1234.

timeout

Request timeout in seconds. Default is 60.

Value

A structured list (parsed JSON).

Examples

## Not run: 
schema <- list(
  type = "ARRAY",
  items = list(
    type = "OBJECT",
    properties = list(
      recipeName = list(type = "STRING"),
      ingredients = list(
        type = "ARRAY",
        items = list(type = "STRING")
      )
    ),
    propertyOrdering = c("recipeName", "ingredients")
  )
)
gemini_structured(
  "List a few popular cookie recipes, and include the amounts of ingredients.",
  schema
)

## End(Not run)

gemini.R documentation built on June 20, 2025, 5:07 p.m.