Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion go/ai/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,15 @@ func (p *prompt) Execute(ctx context.Context, opts ...PromptExecuteOption) (*Mod

p.MessagesFn = mergeMessagesFn(p.MessagesFn, execOpts.MessagesFn)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to delete this line since it'll double up the messages from the prompt when we render the messages at the bottom.


input, err := buildVariables(execOpts.Input)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite see why this is necessary. Without this, we pipe through execOpts.Input to buildRequest() which does this as a first step.

if err != nil {
return nil, err
}

// Render() should populate all data from the prompt. Prompt fields should
// *not* be referenced in this function as it may have been loaded from
// the registry and is missing the options passed in at definition.
actionOpts, err := p.Render(ctx, execOpts.Input)
actionOpts, err := p.Render(ctx, input)
if err != nil {
return nil, err
}
Expand All @@ -166,6 +171,14 @@ func (p *prompt) Execute(ctx context.Context, opts ...PromptExecuteOption) (*Mod
actionOpts.ReturnToolRequests = *execOpts.ReturnToolRequests
}

if p.MessagesFn != nil {
msg, err := renderMessages(ctx, p.promptOptions, actionOpts.Messages, input, execOpts.Input, p.registry.Dotprompt())
if err != nil {
return nil, err
}
actionOpts.Messages = msg
}

return GenerateWithRequest(ctx, p.registry, actionOpts, execOpts.Middleware, execOpts.Stream)
}

Expand Down