Add new feature: prompt templates #30
feature/add-prompt-templates into main Summary of Changes
Hello, 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 introduces a powerful new prompt templating feature, enabling users to define and reuse dynamic prompts for AI agents and models. This enhancement significantly improves the flexibility and maintainability of prompt management by allowing prompts to be configured with variables, functions, and external files, rather than being static strings. The change integrates a robust templating engine into the application's core, making it easier to create sophisticated and context-aware interactions with various AI providers.
Highlights
- New Prompt Templating System: Introduced a comprehensive prompt templating system allowing for dynamic and reusable system and user prompts. Templates can be defined directly in the configuration or loaded from external files.
- Flexible Template Configuration: Agents and models can now reference named templates, or define prompts inline, from files, or via templates. This provides a hierarchical and flexible way to manage prompt definitions.
- Go Template Engine Integration: The templating system leverages Go's
text/templatepackage, providing access to various data points like input, configuration, agent/model details, and environment variables, along with utility functions (e.g.,date,time,upper,lower). - Enhanced Prompt Resolution Logic: Updated the core controller logic to resolve and execute system and user prompts using the new templating mechanism before sending them to the AI provider, ensuring dynamic prompt generation.
Using Gemini Code Assist
The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
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.
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩︎
Code Review
Thank you for adding the prompt templating feature. This is a powerful addition. I've reviewed the changes and have identified a few areas for improvement, primarily in the new internal/app/prompt.go file. My comments focus on improving error handling, reducing code duplication for better maintainability, and addressing a design choice that could lead to inconsistent and unexpected behavior for users. Please take a look at the specific comments for details.
@ -0,0 +1,147 @@
packageapp
The errors returned from c.cfg.GetAgent and c.cfg.GetModel are being ignored. According to the repository's style guide, idiomatic Go error handling should be followed. While the controller's state management might prevent errors here in most cases, not handling them could lead to silent failures or unexpected behavior if an invalid agent or model is ever used. It's safer to check these errors and return them.
agent,err:=c.cfg.GetAgent(c.agentName)iferr!=nil{return"",fmt.Errorf("getting agent for template: %w",err)}model,err:=c.cfg.GetModel(agent.Model)iferr!=nil{return"",fmt.Errorf("getting model for template: %w",err)}References
- The code ignores errors returned by functions, which goes against the principle of idiomatic Go error handling. (link)
@ -0,0 +42,4 @@
}
return"",nil
}
There is significant code duplication in resolveSystemPrompt when resolving the prompt source from an agent and then from a model. The logic for checking inline content, a file path, and a template reference is repeated. This pattern also appears in resolveUserPromptTemplate. Consolidating this logic into a private helper function would reduce duplication and improve maintainability.
@ -0,0 +98,4 @@
func(c*Controller)executeTemplate(tmplStrstring,inputstring)(string,error){
iftmplStr==""{
returninput,nil
}
This logic, which treats the user's raw input as a template when no agent-specific template is defined, introduces inconsistency and potential for unexpected behavior.
- Inconsistent Behavior: When an agent has a template, user input is treated as data (via
{{.Input}}). When it doesn't, the user input itself is executed as a template. This switch in behavior can be confusing. - Unexpected Execution: A user might paste text containing
{{...}}(e.g., when asking about code) and not expect it to be executed, which could lead to errors or mangled output.
A safer and more consistent design would be to always treat user input as data. If no template is specified, the input should be used as-is.
iftmplStr==""{returninput,nil}
Mobile UI Screenshot
Resolved: user input is now treated as literal text when no template is specified. Added a test case to verify this behavior.
Resolved: added error handling for c.cfg.GetAgent and c.cfg.GetModel calls.
Resolved: consolidated prompt source resolution into a private resolvePromptSource helper function.
No due date set.
No dependencies set.
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?