fix(core): set temperature to 1 on retry in sendMessageStream#10866
Conversation
Summary of ChangesHello @SandyTao520, 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 crucial enhancement to the Highlights
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
|
There was a problem hiding this comment.
Code Review
This pull request correctly implements a retry strategy for sendMessageStream by increasing the model's temperature to 1 on subsequent attempts after an invalid content failure. This should help in getting a different, hopefully valid, response from the model. The implementation is sound and includes a good unit test to verify the behavior. I have one suggestion to improve the robustness of the code against potentially invalid input types for the configuration object, which could prevent runtime errors for JavaScript users.
| currentParams.config = { | ||
| ...currentParams.config, | ||
| temperature: 1, | ||
| }; |
There was a problem hiding this comment.
The spread operator ...currentParams.config can throw a runtime TypeError if currentParams.config is not an object (e.g., if it's a string or any other primitive). While TypeScript provides some safety, JavaScript users could pass an invalid type for the config property, leading to an uncaught exception. To make this more robust, you should ensure currentParams.config is a spreadable object before using the spread operator.
| currentParams.config = { | |
| ...currentParams.config, | |
| temperature: 1, | |
| }; | |
| currentParams.config = { | |
| ...(currentParams.config && typeof currentParams.config === 'object' ? currentParams.config : {}), | |
| temperature: 1, | |
| }; |
|
Size Change: +255 B (0%) Total Size: 17.8 MB ℹ️ View Unchanged
|
|
/patch release |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
|
🚀 Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
❌ Patch creation failed! There was an error creating the patch release. 🔍 Troubleshooting:
🔗 Links: |
|
🚀 Patch Release Started! 📋 Release Details:
⏳ Status: The patch release is now running. You'll receive another update when it completes. 🔗 Track Progress: |
|
/patch preview |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
|
❌ Patch creation failed! There was an error creating the patch release. 🔍 Troubleshooting:
🔗 Links: |
|
❌ Patch creation failed! There was an error creating the patch release. 🔍 Troubleshooting:
🔗 Links: |
TLDR
Sets the
temperatureto 1 inGenerateContentConfigduring retries withinsendMessageStream.Dive Deeper
When
sendMessageStreamencounters invalid content and triggers a retry, increasing the temperature to 1 encourages the model to generate different output, potentially resolving the issue that caused the initial failure.Reviewer Test Plan
Reviewers can validate this by mocking
generateContentStreamto fail on the first attempt with invalid content and succeed on the second, verifying that the config passed to the second call hastemperature: 1.Testing Matrix
Linked issues / bugs