Skip to content

fix(core): set temperature to 1 on retry in sendMessageStream#10866

Merged
SandyTao520 merged 1 commit into
mainfrom
st/fix/retry-temperature
Oct 10, 2025
Merged

fix(core): set temperature to 1 on retry in sendMessageStream#10866
SandyTao520 merged 1 commit into
mainfrom
st/fix/retry-temperature

Conversation

@SandyTao520

Copy link
Copy Markdown
Contributor

TLDR

Sets the temperature to 1 in GenerateContentConfig during retries within sendMessageStream.

Dive Deeper

When sendMessageStream encounters 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 generateContentStream to fail on the first attempt with invalid content and succeed on the second, verifying that the config passed to the second call has temperature: 1.

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

@SandyTao520 SandyTao520 requested a review from a team as a code owner October 10, 2025 02:30
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @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 sendMessageStream functionality within the core package. It addresses scenarios where generative model calls might fail due to invalid content by implementing a retry strategy that modifies the temperature parameter. By increasing the temperature to 1 on subsequent attempts, the system aims to prompt the model to generate more varied and potentially valid responses, thereby improving the robustness of content generation. The change is accompanied by a dedicated test case to validate its effectiveness.

Highlights

  • Retry Mechanism Enhancement: The sendMessageStream function now explicitly sets the temperature parameter to 1 in the GenerateContentConfig when a retry attempt is initiated due to invalid content. This encourages the generative model to produce a different output, aiming to resolve the initial failure.
  • New Test Case: A new test has been added to geminiChat.test.ts to verify that the temperature is correctly set to 1 during retry attempts, ensuring the intended behavior.
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.

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

  1. 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 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.

Comment on lines +279 to +282
currentParams.config = {
...currentParams.config,
temperature: 1,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
currentParams.config = {
...currentParams.config,
temperature: 1,
};
currentParams.config = {
...(currentParams.config && typeof currentParams.config === 'object' ? currentParams.config : {}),
temperature: 1,
};

@github-actions

Copy link
Copy Markdown

Size Change: +255 B (0%)

Total Size: 17.8 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 17.7 MB +255 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 830 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

@SandyTao520 SandyTao520 added this pull request to the merge queue Oct 10, 2025
Merged via the queue into main with commit 8dc397c Oct 10, 2025
20 checks passed
@SandyTao520 SandyTao520 deleted the st/fix/retry-temperature branch October 10, 2025 16:21
thacio added a commit to thacio/auditaria that referenced this pull request Oct 11, 2025
@mrcabbage972

Copy link
Copy Markdown
Contributor

/patch release

@github-actions

Copy link
Copy Markdown

Patch workflow(s) dispatched successfully!

📋 Details:

  • Channels: stable,preview
  • Commit: 8dc397c0a50fed77d072bf889140f5f8876bcb30
  • Workflows Created: 2

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

🚀 Patch PR Created!

📋 Patch Details:

📝 Next Steps:

  1. Review and approve the hotfix PR: #11367
  2. Once merged, the patch release will automatically trigger
  3. You'll receive updates here when the release completes

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

Patch creation failed!

There was an error creating the patch release.

🔍 Troubleshooting:

  • Check the workflow logs for detailed error information
  • Verify the commit SHA is valid and accessible
  • Ensure you have permissions to create branches and PRs

🔗 Links:

@github-actions

Copy link
Copy Markdown

🚀 Patch Release Started!

📋 Release Details:

  • Channel: stable → publishing to npm tag latest
  • Version: v0.9.0
  • Hotfix PR: Merged ✅
  • Release Branch: release/v0.9.0-pr-10866

⏳ Status: The patch release is now running. You'll receive another update when it completes.

🔗 Track Progress:

@skeshive

Copy link
Copy Markdown
Contributor

/patch preview

@github-actions

Copy link
Copy Markdown

Patch workflow(s) dispatched successfully!

📋 Details:

  • Channels: preview
  • Commit: 8dc397c0a50fed77d072bf889140f5f8876bcb30
  • Workflows Created: 1

🔗 Track Progress:

@github-actions

Copy link
Copy Markdown

Patch creation failed!

There was an error creating the patch release.

🔍 Troubleshooting:

  • Check the workflow logs for detailed error information
  • Verify the commit SHA is valid and accessible
  • Ensure you have permissions to create branches and PRs

🔗 Links:

@github-actions

Copy link
Copy Markdown

Patch creation failed!

There was an error creating the patch release.

🔍 Troubleshooting:

  • Check the workflow logs for detailed error information
  • Verify the commit SHA is valid and accessible
  • Ensure you have permissions to create branches and PRs

🔗 Links:

@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants