Skip to content

Commit 248582c

Browse files
authored
Deprecate specifying a model name without a provider prefix, and the vertexai provider name (#2711)
1 parent 24f87a3 commit 248582c

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

docs/logfire.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ instrumentation_settings = InstrumentationSettings(
297297
event_logger_provider=EventLoggerProvider(),
298298
)
299299

300-
agent = Agent('gpt-4o', instrument=instrumentation_settings)
300+
agent = Agent('openai:gpt-4o', instrument=instrumentation_settings)
301301
# or to instrument all agents:
302302
Agent.instrument_all(instrumentation_settings)
303303
```
@@ -309,7 +309,7 @@ from pydantic_ai import Agent
309309
from pydantic_ai.models.instrumented import InstrumentationSettings, InstrumentedModel
310310

311311
settings = InstrumentationSettings()
312-
model = InstrumentedModel('gpt-4o', settings)
312+
model = InstrumentedModel('openai:gpt-4o', settings)
313313
agent = Agent(model)
314314
```
315315

@@ -320,7 +320,7 @@ from pydantic_ai.agent import Agent, InstrumentationSettings
320320

321321
instrumentation_settings = InstrumentationSettings(include_binary_content=False)
322322

323-
agent = Agent('gpt-4o', instrument=instrumentation_settings)
323+
agent = Agent('openai:gpt-4o', instrument=instrumentation_settings)
324324
# or to instrument all agents:
325325
Agent.instrument_all(instrumentation_settings)
326326
```
@@ -337,7 +337,7 @@ from pydantic_ai.models.instrumented import InstrumentationSettings
337337

338338
instrumentation_settings = InstrumentationSettings(include_content=False)
339339

340-
agent = Agent('gpt-4o', instrument=instrumentation_settings)
340+
agent = Agent('openai:gpt-4o', instrument=instrumentation_settings)
341341
# or to instrument all agents:
342342
Agent.instrument_all(instrumentation_settings)
343343
```

docs/multi-agent-applications.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ joke_selection_agent = Agent(
106106
),
107107
)
108108
joke_generation_agent = Agent(
109-
'gemini-1.5-flash',
109+
'google-gla:gemini-1.5-flash',
110110
deps_type=ClientAndKey, # (4)!
111111
output_type=list[str],
112112
system_prompt=(

pydantic_ai_slim/pydantic_ai/models/__init__.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from __future__ import annotations as _annotations
88

99
import base64
10+
import warnings
1011
from abc import ABC, abstractmethod
1112
from collections.abc import AsyncIterator, Iterator
1213
from contextlib import asynccontextmanager, contextmanager
@@ -684,19 +685,29 @@ def infer_model(model: Model | KnownModelName | str) -> Model: # noqa: C901
684685
try:
685686
provider, model_name = model.split(':', maxsplit=1)
686687
except ValueError:
688+
provider = None
687689
model_name = model
688-
# TODO(Marcelo): We should deprecate this way.
689690
if model_name.startswith(('gpt', 'o1', 'o3')):
690691
provider = 'openai'
691692
elif model_name.startswith('claude'):
692693
provider = 'anthropic'
693694
elif model_name.startswith('gemini'):
694695
provider = 'google-gla'
696+
697+
if provider is not None:
698+
warnings.warn(
699+
f"Specifying a model name without a provider prefix is deprecated. Instead of {model_name!r}, use '{provider}:{model_name}'.",
700+
DeprecationWarning,
701+
)
695702
else:
696703
raise UserError(f'Unknown model: {model}')
697704

698-
if provider == 'vertexai':
699-
provider = 'google-vertex' # pragma: no cover
705+
if provider == 'vertexai': # pragma: no cover
706+
warnings.warn(
707+
"The 'vertexai' provider name is deprecated. Use 'google-vertex' instead.",
708+
DeprecationWarning,
709+
)
710+
provider = 'google-vertex'
700711

701712
if provider == 'cohere':
702713
from .cohere import CohereModel

tests/models/test_model.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from importlib import import_module
23

34
import pytest
@@ -124,7 +125,9 @@ def test_infer_model(
124125
try:
125126
model_module = import_module(f'pydantic_ai.models.{module_name}')
126127
expected_model = getattr(model_module, model_class_name)
127-
m = infer_model(model_name)
128+
with warnings.catch_warnings():
129+
warnings.simplefilter('ignore', DeprecationWarning)
130+
m = infer_model(model_name)
128131
except ImportError:
129132
pytest.skip(f'{model_name} dependencies not installed')
130133

tests/test_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_agent_flag_set_model(
106106

107107
mocker.patch('pydantic_ai._cli.ask_agent')
108108

109-
assert cli(['--agent', 'test_module:custom_agent', '--model', 'gpt-4o', 'hello']) == 0
109+
assert cli(['--agent', 'test_module:custom_agent', '--model', 'openai:gpt-4o', 'hello']) == 0
110110

111111
assert 'using custom agent test_module:custom_agent with openai:gpt-4o' in capfd.readouterr().out.replace('\n', '')
112112

0 commit comments

Comments
 (0)