// 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) } }