-
Notifications
You must be signed in to change notification settings - Fork 630
fix(go/ai): properly render dotprompt multi-message prompts #4035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @MichaelDoyle, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical issue in the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
e6db25a to
6d9391b
Compare
|
/gemini review |
6d9391b to
d346af3
Compare
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively refactors prompt rendering to occur at execution time, which correctly handles multi-message prompts defined in .prompt files. The core logic is sound, moving from pre-parsing templates at load time to a deferred rendering approach. This is achieved by modifying renderPrompt to work with []*Message instead of []*Part, thereby preserving message structures and roles. The associated test and sample code changes align well with this new approach. Overall, this is a solid improvement that increases correctness and simplifies the prompt loading logic.
d346af3 to
8605d20
Compare
|
Thanks Mike!! |
Add TestLoadPromptTemplateVariableSubstitution to verify that template variables are correctly substituted with actual input values at execution time, not load time. This test covers: 1. Single role prompts with template variables 2. Multi-role prompts (system + user) with template variables 3. Verification that consecutive renders use their own input values Related to firebase#3924 (fixed by firebase#4035)
This PR will properly handle rendering dotprompt(s) with multiple "messages" within, e.g. system prompts, message history, etc.
The primary fix is to move rendering from load time (incorrect) to execution time (correct).
However, I think there are some additional key changes (not implemented) that I believe we should make that I want opinions on, specifically with regards to bringing Go into parity with the TS implementation. I'll file an issue for these, as it will be a "breaking" change for sure.
In general, Go tries to merge all of the various options together. It tries to move system messages to the top, interleave history from various sources (Messages, PromptFn, etc), and then end with the User prompt.
In contrast, in Typescript, dotprompt has complete control over where messages (history) are rendered (via
{{history}}) helper. And if you provide aMessageFn, again that also getsmessages(history) as an argument and is responsible for injecting in the right place. I think without doing this, Go can interleave things in unexpected ways. Separately, any static list of messages (WithMessages), or a message function (WithMessageFn) should not try to render as templates as they do today. You want to accept these "as is", because they represent history in the former, and in the latter the Fn should have the control.Background
Currently, there is a lot of confusion here, which has led to some PR and issue churn. See below.
Issues:
role"helper (probably based on trying to investigate the following report, below)roleis not respected in Go dotprompt (issue still persists)PRs:
Executetime.role"helper"Checklist (if applicable):
Dev UI (after changes):

Fixes #3711