Skip to content

Commit f01f099

Browse files
authored
Added Missing allow request Check (#697)
1 parent a5dca23 commit f01f099

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

pydantic_ai_slim/pydantic_ai/models/gemini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ async def agent_model(
9999
allow_text_result: bool,
100100
result_tools: list[ToolDefinition],
101101
) -> GeminiAgentModel:
102+
check_allow_model_requests()
102103
return GeminiAgentModel(
103104
http_client=self.http_client,
104105
model_name=self.model_name,
@@ -151,7 +152,6 @@ def __init__(
151152
allow_text_result: bool,
152153
result_tools: list[ToolDefinition],
153154
):
154-
check_allow_model_requests()
155155
tools = [_function_from_abstract_tool(t) for t in function_tools]
156156
if result_tools:
157157
tools += [_function_from_abstract_tool(t) for t in result_tools]

pydantic_ai_slim/pydantic_ai/models/mistral.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
Model,
3737
StreamedResponse,
3838
cached_async_http_client,
39+
check_allow_model_requests,
3940
)
4041

4142
try:
@@ -130,6 +131,7 @@ async def agent_model(
130131
result_tools: list[ToolDefinition],
131132
) -> AgentModel:
132133
"""Create an agent model, this is called for each step of an agent run from Pydantic AI call."""
134+
check_allow_model_requests()
133135
return MistralAgentModel(
134136
self.client,
135137
self.model_name,

pydantic_ai_slim/pydantic_ai/models/ollama.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
AgentModel,
1111
Model,
1212
cached_async_http_client,
13+
check_allow_model_requests,
1314
)
1415

1516
try:
@@ -110,6 +111,7 @@ async def agent_model(
110111
allow_text_result: bool,
111112
result_tools: list[ToolDefinition],
112113
) -> AgentModel:
114+
check_allow_model_requests()
113115
return await self.openai_model.agent_model(
114116
function_tools=function_tools,
115117
allow_text_result=allow_text_result,

pydantic_ai_slim/pydantic_ai/models/vertexai.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .._utils import run_in_executor
1111
from ..exceptions import UserError
1212
from ..tools import ToolDefinition
13-
from . import Model, cached_async_http_client
13+
from . import Model, cached_async_http_client, check_allow_model_requests
1414
from .gemini import GeminiAgentModel, GeminiModelName
1515

1616
try:
@@ -114,6 +114,7 @@ async def agent_model(
114114
allow_text_result: bool,
115115
result_tools: list[ToolDefinition],
116116
) -> GeminiAgentModel:
117+
check_allow_model_requests()
117118
url, auth = await self.ainit()
118119
return GeminiAgentModel(
119120
http_client=self.http_client,

tests/models/test_vertexai.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def test_init_right_project_id(tmp_path: Path, allow_model_requests: None)
9292
assert model.auth is not None
9393

9494

95-
async def test_init_service_account_wrong_project_id(tmp_path: Path):
95+
async def test_init_service_account_wrong_project_id(tmp_path: Path, allow_model_requests: None):
9696
service_account_path = tmp_path / 'service_account.json'
9797
save_service_account(service_account_path, 'my-project-id')
9898

@@ -105,7 +105,7 @@ async def test_init_service_account_wrong_project_id(tmp_path: Path):
105105
)
106106

107107

108-
async def test_init_env_wrong_project_id(mocker: MockerFixture):
108+
async def test_init_env_wrong_project_id(mocker: MockerFixture, allow_model_requests: None):
109109
mocker.patch('pydantic_ai.models.vertexai.google.auth.default', return_value=(NoOpCredentials(), 'my-project-id'))
110110
model = VertexAIModel('gemini-1.5-flash', project_id='different')
111111

@@ -116,7 +116,7 @@ async def test_init_env_wrong_project_id(mocker: MockerFixture):
116116
)
117117

118118

119-
async def test_init_env_no_project_id(mocker: MockerFixture):
119+
async def test_init_env_no_project_id(mocker: MockerFixture, allow_model_requests: None):
120120
mocker.patch(
121121
'pydantic_ai.models.vertexai.google.auth.default',
122122
return_value=(NoOpCredentials(), None),

0 commit comments

Comments
 (0)