Skip to content

Commit

Permalink
[Go] put render function last in DefinePrompt
Browse files Browse the repository at this point in the history
  • Loading branch information
jba committed Jun 24, 2024
1 parent a50d4f1 commit b3e7154
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go/ai/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type Prompt core.Action[any, *GenerateRequest, struct{}]
// The prompt expects some input described by inputSchema.
// DefinePrompt registers the function as an action,
// and returns a [Prompt] that runs it.
func DefinePrompt(provider, name string, metadata map[string]any, render func(context.Context, any) (*GenerateRequest, error), inputSchema *jsonschema.Schema) *Prompt {
func DefinePrompt(provider, name string, metadata map[string]any, inputSchema *jsonschema.Schema, render func(context.Context, any) (*GenerateRequest, error)) *Prompt {
mm := maps.Clone(metadata)
if mm == nil {
mm = make(map[string]any)
}
mm["type"] = "prompt"
return (*Prompt)(core.DefineActionWithInputSchema(provider, name, atype.Prompt, mm, render, inputSchema))
return (*Prompt)(core.DefineActionWithInputSchema(provider, name, atype.Prompt, mm, inputSchema, render))
}

// LookupPrompt looks up a [Prompt] registered by [DefinePrompt].
Expand Down
19 changes: 16 additions & 3 deletions go/core/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,24 @@ func DefineCustomAction[In, Out, Stream any](provider, name string, metadata map
// This differs from DefineAction in that the input schema is
// defined dynamically; the static input type is "any".
// This is used for prompts.
func DefineActionWithInputSchema[Out any](provider, name string, atype atype.ActionType, metadata map[string]any, fn func(context.Context, any) (Out, error), inputSchema *jsonschema.Schema) *Action[any, Out, struct{}] {
return defineActionWithInputSchema(globalRegistry, provider, name, atype, metadata, fn, inputSchema)
func DefineActionWithInputSchema[Out any](
provider, name string,
atype atype.ActionType,
metadata map[string]any,
inputSchema *jsonschema.Schema,
fn func(context.Context, any) (Out, error),
) *Action[any, Out, struct{}] {
return defineActionWithInputSchema(globalRegistry, provider, name, atype, metadata, inputSchema, fn)
}

func defineActionWithInputSchema[Out any](r *registry, provider, name string, atype atype.ActionType, metadata map[string]any, fn func(context.Context, any) (Out, error), inputSchema *jsonschema.Schema) *Action[any, Out, struct{}] {
func defineActionWithInputSchema[Out any](
r *registry,
provider, name string,
atype atype.ActionType,
metadata map[string]any,
inputSchema *jsonschema.Schema,
fn func(context.Context, any) (Out, error),
) *Action[any, Out, struct{}] {
a := newActionWithInputSchema(provider+"/"+name, atype, metadata, fn, inputSchema)
r.registerAction(a)
return a
Expand Down
2 changes: 1 addition & 1 deletion go/plugins/dotprompt/genkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (p *Prompt) Register() error {
"template": p.TemplateText,
},
}
p.prompt = ai.DefinePrompt("dotprompt", name, metadata, p.buildRequest, p.Config.InputSchema)
p.prompt = ai.DefinePrompt("dotprompt", name, metadata, p.Config.InputSchema, p.buildRequest)

return nil
}
Expand Down

0 comments on commit b3e7154

Please sign in to comment.