basic-structured

command
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

This sample demonstrates typed output: the Go type you ask for is the schema the model is held to, so the answer comes back as a struct, not a string.

  • simpleJokesFlow streams plain text with WithStreaming.
  • structuredJokesFlow streams a typed Joke with GenerateDataStream.
  • recipeFlow does the same for a nested Recipe.

jsonschema tags describe each field to the model, which is what makes the generated values sensible.

Run it:

go run .

Or with the Dev UI, to call the flows from a browser and read a trace of every run at http://localhost:4000/traces:

curl -sL cli.genkit.dev | bash    # install the Genkit CLI, once
genkit start -- go run .

Or over HTTP. Streaming needs ?stream=true:

curl -N -X POST 'http://localhost:8080/structuredJokesFlow?stream=true' \
  -H "Content-Type: application/json" \
  -d '{"data": {"topic": "bananas"}}'

curl -N -X POST 'http://localhost:8080/recipeFlow?stream=true' \
  -H "Content-Type: application/json" \
  -d '{"data": {"dish": "tacos", "cuisine": "Mexican", "servingSize": 4, "maxPrepMinutes": 30}}'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL