Prompt Templates

View as Markdown

Prompt Templates

Templates allow you to skip re-sending system prompts by storing them on the server.

1// Create a template (System and Model are *string)
2system := "You are a helpful agent for {{company}}."
3model := "openai/gpt-4o-mini"
4tmpl, _ := client.Templates.Create(ctx, meshapi.CreateTemplateParams{
5 Name: "support-agent",
6 System: &system,
7 Model: &model,
8})
9
10// Use it in a completion
11resp, _ := client.Chat.Completions.Create(ctx, meshapi.ChatCompletionParams{
12 Template: &tmpl.Name,
13 Variables: map[string]string{"company": "Acme Corp"},
14 Messages: []meshapi.ChatMessage{{Role: "user", Content: "Hi!"}},
15})

CRUD Operations

1// List
2list, _ := client.Templates.List(ctx)
3
4// Get
5t, _ := client.Templates.Get(ctx, "uuid-or-name")
6
7// Delete
8_ = client.Templates.Delete(ctx, t.ID)