Skip to content

Commit 4ff576e

Browse files
authored
langchain: infer Perplexity provider for sonar model prefix (#30861)
**Description:** This PR adds provider inference logic to `init_chat_model` for Perplexity models that use the "sonar..." prefix (`sonar`, `sonar-pro`, `sonar-reasoning`, `sonar-reasoning-pro` or `sonar-deep-research`). This allows users to initialize these models by simply passing the model name, without needing to explicitly set `model_provider="perplexity"`. The docstring for `init_chat_model` has also been updated to reflect this new inference rule.
1 parent 085baef commit 4ff576e

File tree

1 file changed

+3
-0
lines changed
  • libs/langchain/langchain/chat_models

1 file changed

+3
-0
lines changed

libs/langchain/langchain/chat_models/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def init_chat_model(
133133
- 'mistral...' -> 'mistralai'
134134
- 'deepseek...' -> 'deepseek'
135135
- 'grok...' -> 'xai'
136+
- 'sonar...' -> 'perplexity'
136137
configurable_fields: Which model parameters are
137138
configurable:
138139
@@ -504,6 +505,8 @@ def _attempt_infer_model_provider(model_name: str) -> Optional[str]:
504505
return "deepseek"
505506
elif model_name.startswith("grok"):
506507
return "xai"
508+
elif model_name.startswith("sonar"):
509+
return "perplexity"
507510
else:
508511
return None
509512

0 commit comments

Comments
 (0)