fix: use max_tokens for openai provider with custom base URL (Mistral compatibility)#858
Open
octo-patch wants to merge 1 commit intovectorize-io:mainfrom
Conversation
Mistral (and several other providers) reject 'max_completion_tokens' with a 422 because they haven't adopted the newer OpenAI parameter name. When the openai provider is configured with a custom base_url (e.g. Mistral, Together AI), fall back to the widely-supported 'max_tokens' parameter. Native OpenAI (no custom base_url) and Groq still use 'max_completion_tokens'. Fixes vectorize-io#852
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #852
Problem
When using
HINDSIGHT_API_LLM_PROVIDER=openaiwithHINDSIGHT_API_LLM_BASE_URLpointing to Mistral's API (https://api.mistral.ai/v1), Hindsight crashes on startup duringverify_connectionbecausemax_completion_tokensis sent but Mistral only acceptsmax_tokens, returning a 422:Solution
Add
_max_tokens_param_name()method that selects the correct parameter name based on provider and base URL:base_url) →max_completion_tokensmax_completion_tokens(Groq supports the newer name)base_url, ollama, lmstudio, minimax, volcano →max_tokensA custom
base_urlon theopenaiprovider signals a third-party compatible API (Mistral, Together AI, etc.) that may not have adoptedmax_completion_tokens.Testing
call()argument name, not the API key)call()andcall_with_tools()