fix(core): Decouple provider prefix from model name in init_chat_mode… #34046
+11
−7
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.
:…l logic
Addresses Issue #34007.
Fixes a bug where aliases like 'mistral:' were inferred correctly as a provider but the prefix was not stripped from the model name, causing API 400 errors. Added logic to strip prefix when inference succeeds.
Description
This PR resolves a logic error in
init_chat_modelwhere inferred provider aliases (specificallymistral:) were correctly identified but not stripped from the model string.The Problem
When passing a string like
mistral:ministral-8b-latest, the factory logic correctly inferred the provider asmistralaibut failed to enter the string-splitting block because the aliasmistralwas not in the hardcoded_SUPPORTED_PROVIDERSlist. This caused the raw stringmistral:ministral-8b-latestto be passed to theChatMistralAIconstructor, resulting in a 400 API error.The Fix
I updated
_parse_modelinlibs/langchain/langchain/chat_models/base.py. The logic now attempts to infer the provider from the prefix before determining whether to split the string. This ensures that valid aliases trigger the stripping logic, passing only the cleanmodel_nameto the integration class.Issue
Fixes #34007
Dependencies
None.
Verification
Validated locally with a reproduction script:
mistral:ministral-8b-latestChatMistralAIwithmodel="ministral-8b-latest".gpt-4o) remain unaffected.