Skip to content

The agent engineering platform.

fix(langchain): handle `gpt-5` model name in `init_chat_model` (#33148)

Mason Daugherty3325196be17b
diff --git a/libs/langchain/langchain/chat_models/base.py b/libs/langchain/langchain/chat_models/base.py
index 22f5174711..4de96a1a26 100644
--- a/libs/langchain/langchain/chat_models/base.py
+++ b/libs/langchain/langchain/chat_models/base.py
@@ -118,7 +118,7 @@ def init_chat_model(
Will attempt to infer model_provider from model if not specified. The
following providers will be inferred based on these model prefixes:
- - ``gpt-3...`` | ``gpt-4...`` | ``o1...`` -> ``openai``
+ - ``gpt-...`` | ``o1...`` | ``o3...`` -> ``openai``
- ``claude...`` -> ``anthropic``
- ``amazon...`` -> ``bedrock``
- ``gemini...`` -> ``google_vertexai``
@@ -497,7 +497,7 @@ _SUPPORTED_PROVIDERS = {
def _attempt_infer_model_provider(model_name: str) -> Optional[str]:
- if any(model_name.startswith(pre) for pre in ("gpt-3", "gpt-4", "o1", "o3")):
+ if any(model_name.startswith(pre) for pre in ("gpt-", "o1", "o3")):
return "openai"
if model_name.startswith("claude"):
return "anthropic"
diff --git a/libs/langchain_v1/langchain/chat_models/base.py b/libs/langchain_v1/langchain/chat_models/base.py
index a062d34823..765cffb4d1 100644
--- a/libs/langchain_v1/langchain/chat_models/base.py
+++ b/libs/langchain_v1/langchain/chat_models/base.py
@@ -109,7 +109,7 @@ def init_chat_model(
Will attempt to infer model_provider from model if not specified. The
following providers will be inferred based on these model prefixes:
- - 'gpt-3...' | 'gpt-4...' | 'o1...' -> 'openai'
+ - 'gpt-...' | 'o1...' | 'o3...' -> 'openai'
- 'claude...' -> 'anthropic'
- 'amazon....' -> 'bedrock'
- 'gemini...' -> 'google_vertexai'
@@ -474,7 +474,7 @@ _SUPPORTED_PROVIDERS = {
def _attempt_infer_model_provider(model_name: str) -> str | None:
- if any(model_name.startswith(pre) for pre in ("gpt-3", "gpt-4", "o1", "o3")):
+ if any(model_name.startswith(pre) for pre in ("gpt-", "o1", "o3")):
return "openai"
if model_name.startswith("claude"):
return "anthropic"