diff --git a/go/ai/prompt.go b/go/ai/prompt.go index 394932740..5fb25cfb8 100644 --- a/go/ai/prompt.go +++ b/go/ai/prompt.go @@ -38,7 +38,6 @@ func DefinePrompt(provider, name string, metadata map[string]any, render func(co mm = make(map[string]any) } mm["type"] = "prompt" - mm["prompt"] = true // required by genkit ui return core.DefineActionWithInputSchema(provider, name, atype.Prompt, mm, render, inputSchema) } diff --git a/go/plugins/dotprompt/dotprompt.go b/go/plugins/dotprompt/dotprompt.go index 457326342..8c1b5385f 100644 --- a/go/plugins/dotprompt/dotprompt.go +++ b/go/plugins/dotprompt/dotprompt.go @@ -63,9 +63,12 @@ type Prompt struct { Config - // The template for the prompt. + // The parsed prompt template. Template *raymond.Template + // The original prompt template text. + TemplateText string + // A hash of the prompt contents. hash string @@ -197,10 +200,11 @@ func newPrompt(name, templateText, hash string, config Config) (*Prompt, error) } template.RegisterHelpers(templateHelpers) return &Prompt{ - Name: name, - Config: config, - hash: hash, - Template: template, + Name: name, + Config: config, + hash: hash, + Template: template, + TemplateText: templateText, }, nil } diff --git a/go/plugins/dotprompt/genkit.go b/go/plugins/dotprompt/genkit.go index 814a1bbbe..6d20c67c4 100644 --- a/go/plugins/dotprompt/genkit.go +++ b/go/plugins/dotprompt/genkit.go @@ -52,8 +52,11 @@ func (p *Prompt) buildVariables(variables any) (map[string]any, error) { } v := reflect.Indirect(reflect.ValueOf(variables)) + if v.Kind() == reflect.Map { + return variables.(map[string]any), nil + } if v.Kind() != reflect.Struct { - return nil, errors.New("dotprompt: fields not a struct or pointer to a struct") + return nil, errors.New("dotprompt: fields not a struct or pointer to a struct or a map") } vt := v.Type() @@ -138,7 +141,18 @@ func (p *Prompt) Register() error { name += "." + p.Variant } - p.action = ai.DefinePrompt("dotprompt", name, nil, p.buildRequest, p.Config.InputSchema) + // TODO: Undo clearing of the Version once Monaco Editor supports newer than JSON schema draft-07. + p.InputSchema.Version = "" + + metadata := map[string]any{ + "prompt": map[string]any{ + "name": p.Name, + "input": map[string]any{"schema": p.InputSchema}, + "output": map[string]any{"format": p.OutputFormat}, + "template": p.TemplateText, + }, + } + p.action = ai.DefinePrompt("dotprompt", name, metadata, p.buildRequest, p.Config.InputSchema) return nil } diff --git a/go/samples/coffee-shop/main.go b/go/samples/coffee-shop/main.go index 92c857395..9cfda041f 100755 --- a/go/samples/coffee-shop/main.go +++ b/go/samples/coffee-shop/main.go @@ -109,11 +109,15 @@ func main() { log.Fatal(err) } + r := &jsonschema.Reflector{ + AllowAdditionalProperties: false, + DoNotReference: true, + } g := googleai.Model("gemini-1.5-pro") simpleGreetingPrompt, err := dotprompt.Define("simpleGreeting", simpleGreetingPromptTemplate, dotprompt.Config{ ModelAction: g, - InputSchema: jsonschema.Reflect(simpleGreetingInput{}), + InputSchema: r.Reflect(simpleGreetingInput{}), OutputFormat: ai.OutputFormatText, }, ) @@ -176,10 +180,6 @@ func main() { return text, nil }) - r := &jsonschema.Reflector{ - AllowAdditionalProperties: false, - DoNotReference: true, - } schema := r.Reflect(simpleGreetingOutput{}) jsonBytes, err := schema.MarshalJSON() if err != nil {