-
Notifications
You must be signed in to change notification settings - Fork 117
fix: use configurable max_tokens in credential validation instead of hardcoded value #260
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -183,7 +183,8 @@ def validate_credentials(self, model: str, credentials: dict) -> None: | |
| endpoint_url += "/" | ||
|
|
||
| # 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))} | ||
|
Comment on lines
+186
to
+187
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this change makes |
||
|
|
||
| completion_type = LLMMode.value_of(credentials["mode"]) | ||
|
|
||
|
|
||
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.
This direct
int()conversion is unsafe. Ifcredentials.get('max_tokens_to_sample')returns a non-numeric string (e.g., from user configuration), this will raise aValueError. This exception is caught by the genericexcept Exceptionblock below, but the error message formatting at line 254 (f"... response body {response.text}") will then raise aNameErrorbecause theresponsevariable has not been defined yet. ThisNameErroris 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-exceptblock around the conversion and raise aCredentialsValidateFailedErrorwith a clear message if it fails.