basic-prompts

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: 14 Imported by: 0

Documentation

Overview

This sample demonstrates prompts, each defined twice: once inline in code with DefinePrompt, and once in a .prompt file (Dotprompt) looked up by name. Every pair behaves identically, so the files show what moves out of code.

  • joke: the simplest prompt, one interpolated field.
  • structured-joke: DefineDataPrompt, typed both ways from its parameters.
  • recipe: Handlebars conditionals and loops, plus a shared partial.
  • assistant: middleware attached to the prompt itself.
  • chat: a conversation passed per execution rather than declared.

The prompts directory is compiled into the binary with go:embed, so the program ships as one file. Partials and helpers are registered on the Genkit instance in main and are then usable from any prompt.

Run it:

go run .

Or with the Dev UI, whose Prompts page runs each .prompt file against edits to its template, alongside 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, and swapping PromptFlow for DotpromptFlow in any name below runs the .prompt file instead:

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

curl -N -X POST 'http://localhost:8080/chatPromptFlow?stream=true' \
  -H "Content-Type: application/json" \
  -d '{"data": {"question": "What did I just ask you?", "history": [{"role": "user", "text": "How do I read a file in Go?"}, {"role": "model", "text": "Use os.ReadFile."}]}}'

Jump to

Keyboard shortcuts

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