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}}'
Click to show internal directories.
Click to hide internal directories.