Skip to content

Commit 4242140

Browse files
authored
feat(model-profiles): support more providers (#33766)
1 parent b06bd6a commit 4242140

File tree

6 files changed

+99
-9
lines changed

6 files changed

+99
-9
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[profile]
2+
image_url_inputs = true
3+
pdf_inputs = true
4+
pdf_tool_message = true
5+
image_tool_message = true
6+
structured_output = false
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[profile]
2+
image_url_inputs = true
3+
pdf_inputs = true
4+
image_tool_message = true
5+
tool_choice = true
6+
structured_output = true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[profile]
2+
image_url_inputs = true
3+
pdf_inputs = true
4+
image_tool_message = true
5+
tool_choice = true
6+
structured_output = true

libs/model-profiles/langchain_model_profiles/model_profile.py

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Model profiles package."""
22

3+
import re
4+
35
from typing_extensions import TypedDict
46

57
from langchain_model_profiles._data_loader import _DataLoader
@@ -79,27 +81,67 @@ class ModelProfile(TypedDict, total=False):
7981

8082
_lc_type_to_provider_id = {
8183
"openai-chat": "openai",
84+
"azure-openai-chat": "azure",
8285
"anthropic-chat": "anthropic",
86+
"chat-google-generative-ai": "google",
87+
"vertexai": "google-vertex",
88+
"anthropic-chat-vertexai": "google-vertex-anthropic",
89+
"amazon_bedrock_chat": "amazon-bedrock",
90+
"amazon_bedrock_converse_chat": "amazon-bedrock",
91+
"chat-ai21": "ai21",
92+
"chat-deepseek": "deepseek",
93+
"fireworks-chat": "fireworks-ai",
94+
"groq-chat": "groq",
95+
"huggingface-chat-wrapper": "huggingface",
96+
"mistralai-chat": "mistral",
97+
"chat-ollama": "ollama",
98+
"perplexitychat": "perplexity",
99+
"together-chat": "togetherai",
100+
"upstage-chat": "upstage",
101+
"xai-chat": "xai",
83102
}
84103

85104

86-
def get_model_profile(provider_id: str, model_id: str) -> ModelProfile | None:
105+
def _translate_provider_and_model_id(provider: str, model: str) -> tuple[str, str]:
106+
"""Translate LangChain provider and model to models.dev equivalents.
107+
108+
Args:
109+
provider: LangChain provider ID.
110+
model: LangChain model ID.
111+
112+
Returns:
113+
A tuple containing the models.dev provider ID and model ID.
114+
"""
115+
provider_id = _lc_type_to_provider_id.get(provider, provider)
116+
117+
if provider_id in ("google", "google-vertex"):
118+
# convert models/gemini-2.0-flash-001 to gemini-2.0-flash
119+
model_id = re.sub(r"-\d{3}$", "", model.replace("models/", ""))
120+
elif provider_id == "amazon-bedrock":
121+
# strip region prefixes like "us."
122+
model_id = re.sub(r"^[A-Za-z]{2}\.", "", model)
123+
else:
124+
model_id = model
125+
126+
return provider_id, model_id
127+
128+
129+
def get_model_profile(provider: str, model: str) -> ModelProfile | None:
87130
"""Get the model capabilities for a given model.
88131
89132
Args:
90-
provider_id: Identifier for provider (e.g., `'openai'`, `'anthropic'`).
91-
model_id: Identifier for model (e.g., `'gpt-5'`,
133+
provider: Identifier for provider (e.g., `'openai'`, `'anthropic'`).
134+
model: Identifier for model (e.g., `'gpt-5'`,
92135
`'claude-sonnet-4-5-20250929'`).
93136
94137
Returns:
95138
The model capabilities or `None` if not found in the data.
96139
"""
97-
if not provider_id or not model_id:
140+
if not provider or not model:
98141
return None
99142

100-
data = _LOADER.get_profile_data(
101-
_lc_type_to_provider_id.get(provider_id, provider_id), model_id
102-
)
143+
provider_id, model_id = _translate_provider_and_model_id(provider, model)
144+
data = _LOADER.get_profile_data(provider_id, model_id)
103145
if not data:
104146
# If either (1) provider not found or (2) model not found under matched provider
105147
return None

libs/model-profiles/tests/unit_tests/test_chat_model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""End to end test for fetching model profiles from a chat model."""
22

3-
import pytest
43
from langchain.chat_models import init_chat_model
54

65

@@ -12,7 +11,7 @@ def test_chat_model() -> None:
1211
assert model.profile["structured_output"]
1312

1413

15-
def test_chat_model_no_data(monkeypatch: pytest.MonkeyPatch) -> None:
14+
def test_chat_model_no_data() -> None:
1615
"""Test that chat model handles missing profile data."""
1716
model = init_chat_model("openai:gpt-fake", api_key="foo")
1817
assert model.profile == {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Test provider and model ID mappings."""
2+
3+
import pytest
4+
5+
from langchain_model_profiles.model_profile import get_model_profile
6+
7+
8+
@pytest.mark.parametrize(
9+
("provider", "model_id"),
10+
[
11+
("openai-chat", "gpt-5"),
12+
("azure-openai-chat", "gpt-5"),
13+
("anthropic-chat", "claude-sonnet-4-5"),
14+
("vertexai", "models/gemini-2.0-flash-001"),
15+
("chat-google-generative-ai", "models/gemini-2.0-flash-001"),
16+
("amazon_bedrock_chat", "anthropic.claude-sonnet-4-20250514-v1:0"),
17+
("amazon_bedrock_converse_chat", "anthropic.claude-sonnet-4-20250514-v1:0"),
18+
# ("chat-ai21", "jamba-mini"), # no data yet # noqa: ERA001
19+
("chat-deepseek", "deepseek-reasoner"),
20+
("fireworks-chat", "accounts/fireworks/models/gpt-oss-20b"),
21+
("groq-chat", "llama-3.3-70b-versatile"),
22+
("huggingface-chat-wrapper", "Qwen/Qwen3-235B-A22B-Thinking-2507"),
23+
("mistralai-chat", "mistral-large-latest"),
24+
# ("chat-ollama", "llama3.1"), # no data yet # noqa: ERA001
25+
("perplexitychat", "sonar"),
26+
("xai-chat", "grok-4"),
27+
],
28+
)
29+
def test_id_translation(provider: str, model_id: str) -> None:
30+
"""Test translation from LangChain to model / provider IDs."""
31+
assert get_model_profile(provider, model_id)

0 commit comments

Comments
 (0)