basic-prompts

command
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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