Files
steve 97513141dc docs: examples for every hard requirement + mort migration blueprint
Phase 7: nine runnable examples/ programs (parse, failover chains with
trailing alias, tiers, LLM_* env providers, multimodal, tool loop,
Generate[T], agent, skills); docs/mort-migration.md mapping mort's
go-llm/go-agentkit usage onto majordomo APIs with the planned additive
library extensions and conversion order; README finalized with the
complete matrix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 13:17:20 +02:00

49 lines
1.4 KiB
Go

// Command structured demonstrates typed structured output: the JSON schema
// is derived from a Go struct, mapped to the provider's native mechanism,
// and the response is unmarshaled back into the struct.
package main
import (
"context"
"flag"
"fmt"
"log"
"gitea.stevedudenhoeffer.com/steve/majordomo"
)
// Recipe is the shape we want back. Field tags document and constrain the
// schema (`description`, `enum`); pointers mark nullable fields.
type Recipe struct {
Name string `json:"name"`
Servings int `json:"servings"`
Difficulty string `json:"difficulty" enum:"easy,medium,hard"`
Steps []string `json:"steps" description:"short imperative steps"`
WinePair *string `json:"wine_pairing" description:"null if none appropriate"`
}
func main() {
model := flag.String("model", "ollama-cloud/minimax-m3:cloud", "model spec")
flag.Parse()
m, err := majordomo.Parse(*model)
if err != nil {
log.Fatalf("parse: %v", err)
}
recipe, err := majordomo.Generate[Recipe](context.Background(), m, majordomo.Request{
Messages: []majordomo.Message{majordomo.UserText("A weeknight mushroom risotto.")},
})
if err != nil {
log.Fatalf("generate: %v", err)
}
fmt.Printf("%s (serves %d, %s)\n", recipe.Name, recipe.Servings, recipe.Difficulty)
for i, s := range recipe.Steps {
fmt.Printf(" %d. %s\n", i+1, s)
}
if recipe.WinePair != nil {
fmt.Printf("wine: %s\n", *recipe.WinePair)
}
}