Skip to content

Conversation

@huayaoyue6
Copy link

The validate_credentials method in OAICompatLargeLanguageModel uses a hardcoded max_tokens: 5 value when testing model connectivity. This can cause credential validation failures for models that have minimum token requirements higher than 5, even when the credentials are correct.

Pull Request Checklist

Thank you for your contribution! Before submitting your PR, please make sure you have completed the following checks:

Compatibility Check

  • [ ✓] I have checked whether this change affects the backward compatibility of the plugin declared in README.md
  • [ ✓] I have checked whether this change affects the forward compatibility of the plugin declared in README.md
  • [ ✓] If this change introduces a breaking change, I have discussed it with the project maintainer and specified the release version in the README.md
  • [ ✓] I have described the compatibility impact and the corresponding version number in the PR description
  • [ ✓] I have checked whether the plugin version is updated in the README.md

Available Checks

  • [ ✓] Code has passed local tests
  • [ ✓] Relevant documentation has been updated (if necessary)

…hardcoded value

The `validate_credentials` method in `OAICompatLargeLanguageModel` uses a hardcoded `max_tokens: 5` value when testing model connectivity. This can cause credential validation failures for models that have minimum token requirements higher than 5, even when the credentials are correct.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @huayaoyue6, 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 OAICompatLargeLanguageModel's credential validation process. Previously, a fixed max_tokens value of 5 could inadvertently cause valid credentials to fail validation for models requiring a higher minimum token count. The update introduces flexibility by allowing the max_tokens parameter to be dynamically set from the model's credentials, thereby enhancing the robustness and compatibility of the model connectivity checks.

Highlights

  • Credential Validation Fix: The validate_credentials method in OAICompatLargeLanguageModel no longer uses a hardcoded max_tokens value of 5 when testing model connectivity.
  • Configurable Max Tokens: The max_tokens value for credential validation is now configurable, defaulting to 20 if max_tokens_to_sample is not specified in the credentials.
  • Improved Model Compatibility: This change prevents credential validation failures for models that have minimum token requirements higher than 5, ensuring broader compatibility.
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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 aims to fix credential validation failures for models with minimum token requirements by making the max_tokens parameter configurable instead of hardcoded. The change correctly replaces the hardcoded value with a value from the credentials.

However, I've identified two issues:

  1. A critical issue where an invalid value for max_tokens_to_sample in the credentials can crash the request handler due to an unhandled NameError.
  2. A high-severity issue where the fix is incomplete, as the stream validation mode still uses a hardcoded max_tokens value, which can lead to the same validation failures this PR intends to solve.

Please see the detailed comments in the code.

# prepare the payload for a simple ping to the model
data = {"model": credentials.get("endpoint_model_name", model), "max_tokens": 5}
data = {"model": credentials.get("endpoint_model_name", model),
"max_tokens": int(credentials.get("max_tokens_to_sample", 20))}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This direct int() conversion is unsafe. If credentials.get('max_tokens_to_sample') returns a non-numeric string (e.g., from user configuration), this will raise a ValueError. This exception is caught by the generic except Exception block below, but the error message formatting at line 254 (f"... response body {response.text}") will then raise a NameError because the response variable has not been defined yet. This NameError is unhandled and will likely crash the request handler, providing a confusing stack trace to the user.

To fix this, you should validate the value and handle conversion errors gracefully before it's used. For example, you could use a try-except block around the conversion and raise a CredentialsValidateFailedError with a clear message if it fails.

Comment on lines +186 to +187
data = {"model": credentials.get("endpoint_model_name", model),
"max_tokens": int(credentials.get("max_tokens_to_sample", 20))}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While this change makes max_tokens configurable for the default validation path, the value is unconditionally overridden with a hardcoded 10 on line 206 when stream validation is enabled (stream_mode_auth == 'use'). This means that for models requiring more than 10 tokens, stream validation will still fail, making this fix incomplete. To fully address the issue described in the pull request, the max_tokens for stream validation should also be configurable or use the value you've set here.

@huayaoyue6 huayaoyue6 closed this Dec 7, 2025
@huayaoyue6 huayaoyue6 reopened this Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant