Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcd72aa0

Browse files
authored
Rename result type in some docs and tests (pydantic#1462)
1 parent1def7df commitcd72aa0

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

‎docs/agents.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ from pydantic_ai.exceptions import UsageLimitExceeded
418418
from pydantic_ai.usageimport UsageLimits
419419

420420

421-
classNeverResultType(TypedDict):
421+
classNeverOutputType(TypedDict):
422422
"""
423423
Never ever coerce data to this type.
424424
"""
@@ -429,7 +429,7 @@ class NeverResultType(TypedDict):
429429
agent= Agent(
430430
'anthropic:claude-3-5-sonnet-latest',
431431
retries=3,
432-
output_type=NeverResultType,
432+
output_type=NeverOutputType,
433433
system_prompt='Any time you get a response, call the `infinite_retry_tool` to produce another response.',
434434
)
435435

‎tests/test_agent.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,14 @@ def validate_output(ctx: RunContext[None], o: Any) -> Any:
437437
@pytest.mark.parametrize(
438438
'union_code',
439439
[
440-
pytest.param('ResultType = Union[Foo, Bar]'),
441-
pytest.param('ResultType = Foo | Bar',marks=pytest.mark.skipif(sys.version_info< (3,10),reason='3.10+')),
440+
pytest.param('OutputType = Union[Foo, Bar]'),
441+
pytest.param('OutputType = Foo | Bar',marks=pytest.mark.skipif(sys.version_info< (3,10),reason='3.10+')),
442442
pytest.param(
443-
'ResultType: TypeAlias = Foo | Bar',
443+
'OutputType: TypeAlias = Foo | Bar',
444444
marks=pytest.mark.skipif(sys.version_info< (3,10),reason='Python 3.10+'),
445445
),
446446
pytest.param(
447-
'typeResultType = Foo | Bar',marks=pytest.mark.skipif(sys.version_info< (3,12),reason='3.12+')
447+
'typeOutputType = Foo | Bar',marks=pytest.mark.skipif(sys.version_info< (3,12),reason='3.12+')
448448
),
449449
],
450450
)
@@ -470,7 +470,7 @@ class Bar(BaseModel):
470470
mod=create_module(module_code)
471471

472472
m=TestModel()
473-
agent=Agent(m,output_type=mod.ResultType)
473+
agent=Agent(m,output_type=mod.OutputType)
474474
got_tool_call_name='unset'
475475

476476
@agent.output_validator
@@ -983,7 +983,7 @@ class TestMultipleToolCalls:
983983

984984
pytestmark=pytest.mark.usefixtures('set_event_loop')
985985

986-
classResultType(BaseModel):
986+
classOutputType(BaseModel):
987987
"""Result type used by all tests."""
988988

989989
value:str
@@ -1002,7 +1002,7 @@ def return_model(_: list[ModelMessage], info: AgentInfo) -> ModelResponse:
10021002
]
10031003
)
10041004

1005-
agent=Agent(FunctionModel(return_model),output_type=self.ResultType,end_strategy='early')
1005+
agent=Agent(FunctionModel(return_model),output_type=self.OutputType,end_strategy='early')
10061006

10071007
@agent.tool_plain
10081008
defregular_tool(x:int)->int:# pragma: no cover
@@ -1058,7 +1058,7 @@ def return_model(_: list[ModelMessage], info: AgentInfo) -> ModelResponse:
10581058
]
10591059
)
10601060

1061-
agent=Agent(FunctionModel(return_model),output_type=self.ResultType,end_strategy='early')
1061+
agent=Agent(FunctionModel(return_model),output_type=self.OutputType,end_strategy='early')
10621062
result=agent.run_sync('test multiple final results')
10631063

10641064
# Verify the result came from the first final tool
@@ -1098,7 +1098,7 @@ def return_model(_: list[ModelMessage], info: AgentInfo) -> ModelResponse:
10981098
]
10991099
)
11001100

1101-
agent=Agent(FunctionModel(return_model),output_type=self.ResultType,end_strategy='exhaustive')
1101+
agent=Agent(FunctionModel(return_model),output_type=self.OutputType,end_strategy='exhaustive')
11021102

11031103
@agent.tool_plain
11041104
defregular_tool(x:int)->int:
@@ -1186,7 +1186,7 @@ def return_model(_: list[ModelMessage], info: AgentInfo) -> ModelResponse:
11861186
]
11871187
)
11881188

1189-
agent=Agent(FunctionModel(return_model),output_type=self.ResultType,end_strategy='early')
1189+
agent=Agent(FunctionModel(return_model),output_type=self.OutputType,end_strategy='early')
11901190

11911191
@agent.tool_plain
11921192
defregular_tool(x:int)->int:# pragma: no cover
@@ -1259,7 +1259,7 @@ def another_tool(y: int) -> int: # pragma: no cover
12591259
deftest_early_strategy_does_not_apply_to_tool_calls_without_final_tool(self):
12601260
"""Test that 'early' strategy does not apply to tool calls without final tool."""
12611261
tool_called= []
1262-
agent=Agent(TestModel(),output_type=self.ResultType,end_strategy='early')
1262+
agent=Agent(TestModel(),output_type=self.OutputType,end_strategy='early')
12631263

12641264
@agent.tool_plain
12651265
defregular_tool(x:int)->int:
@@ -1285,7 +1285,7 @@ def return_model(_: list[ModelMessage], info: AgentInfo) -> ModelResponse:
12851285
]
12861286
)
12871287

1288-
agent=Agent(FunctionModel(return_model),output_type=self.ResultType,end_strategy='early')
1288+
agent=Agent(FunctionModel(return_model),output_type=self.OutputType,end_strategy='early')
12891289
result=agent.run_sync('test multiple final results')
12901290

12911291
# Verify the result came from the second final tool

‎tests/test_streaming.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ async def ret_a(x: str) -> str: # pragma: no cover
391391
)
392392

393393

394-
classResultType(BaseModel):
394+
classOutputType(BaseModel):
395395
"""Result type used by all tests."""
396396

397397
value:str
@@ -407,7 +407,7 @@ async def sf(_: list[ModelMessage], info: AgentInfo) -> AsyncIterator[str | Delt
407407
yield {2:DeltaToolCall('regular_tool','{"x": 1}')}
408408
yield {3:DeltaToolCall('another_tool','{"y": 2}')}
409409

410-
agent=Agent(FunctionModel(stream_function=sf),output_type=ResultType,end_strategy='early')
410+
agent=Agent(FunctionModel(stream_function=sf),output_type=OutputType,end_strategy='early')
411411

412412
@agent.tool_plain
413413
defregular_tool(x:int)->int:# pragma: no cover
@@ -476,7 +476,7 @@ async def sf(_: list[ModelMessage], info: AgentInfo) -> AsyncIterator[str | Delt
476476
yield {1:DeltaToolCall('final_result','{"value": "first"}')}
477477
yield {2:DeltaToolCall('final_result','{"value": "second"}')}
478478

479-
agent=Agent(FunctionModel(stream_function=sf),output_type=ResultType,end_strategy='early')
479+
agent=Agent(FunctionModel(stream_function=sf),output_type=OutputType,end_strategy='early')
480480

481481
asyncwithagent.run_stream('test multiple final results')asresult:
482482
response=awaitresult.get_output()
@@ -529,7 +529,7 @@ async def sf(_: list[ModelMessage], info: AgentInfo) -> AsyncIterator[str | Delt
529529
yield {4:DeltaToolCall('final_result','{"value": "second"}')}
530530
yield {5:DeltaToolCall('unknown_tool','{"value": "???"}')}
531531

532-
agent=Agent(FunctionModel(stream_function=sf),output_type=ResultType,end_strategy='exhaustive')
532+
agent=Agent(FunctionModel(stream_function=sf),output_type=OutputType,end_strategy='exhaustive')
533533

534534
@agent.tool_plain
535535
defregular_tool(x:int)->int:
@@ -606,7 +606,7 @@ async def sf(_: list[ModelMessage], info: AgentInfo) -> AsyncIterator[str | Delt
606606
yield {3:DeltaToolCall('another_tool','{"y": 2}')}
607607
yield {4:DeltaToolCall('unknown_tool','{"value": "???"}')}
608608

609-
agent=Agent(FunctionModel(stream_function=sf),output_type=ResultType,end_strategy='early')
609+
agent=Agent(FunctionModel(stream_function=sf),output_type=OutputType,end_strategy='early')
610610

611611
@agent.tool_plain
612612
defregular_tool(x:int)->int:# pragma: no cover
@@ -715,7 +715,7 @@ def another_tool(y: int) -> int: # pragma: no cover
715715
asyncdeftest_early_strategy_does_not_apply_to_tool_calls_without_final_tool():
716716
"""Test that 'early' strategy does not apply to tool calls without final tool."""
717717
tool_called:list[str]= []
718-
agent=Agent(TestModel(),output_type=ResultType,end_strategy='early')
718+
agent=Agent(TestModel(),output_type=OutputType,end_strategy='early')
719719

720720
@agent.tool_plain
721721
defregular_tool(x:int)->int:
@@ -777,17 +777,17 @@ async def test_custom_output_type_default_str() -> None:
777777
response=awaitresult.get_output()
778778
assertresponse==snapshot('success (no tool calls)')
779779

780-
asyncwithagent.run_stream('test',output_type=ResultType)asresult:
780+
asyncwithagent.run_stream('test',output_type=OutputType)asresult:
781781
response=awaitresult.get_output()
782-
assertresponse==snapshot(ResultType(value='a'))
782+
assertresponse==snapshot(OutputType(value='a'))
783783

784784

785785
asyncdeftest_custom_output_type_default_structured()->None:
786-
agent=Agent('test',output_type=ResultType)
786+
agent=Agent('test',output_type=OutputType)
787787

788788
asyncwithagent.run_stream('test')asresult:
789789
response=awaitresult.get_output()
790-
assertresponse==snapshot(ResultType(value='a'))
790+
assertresponse==snapshot(OutputType(value='a'))
791791

792792
asyncwithagent.run_stream('test',output_type=str)asresult:
793793
response=awaitresult.get_output()
@@ -880,21 +880,21 @@ def output_validator_simple(data: str) -> str:
880880

881881

882882
asyncdeftest_stream_iter_structured_validator()->None:
883-
classNotResultType(BaseModel):
883+
classNotOutputType(BaseModel):
884884
not_value:str
885885

886-
agent=Agent[None,Union[ResultType,NotResultType]]('test',output_type=Union[ResultType,NotResultType])# pyright: ignore[reportArgumentType]
886+
agent=Agent[None,Union[OutputType,NotOutputType]]('test',output_type=Union[OutputType,NotOutputType])# pyright: ignore[reportArgumentType]
887887

888888
@agent.output_validator
889-
defoutput_validator(data:ResultType|NotResultType)->ResultType|NotResultType:
890-
assertisinstance(data,ResultType)
891-
returnResultType(value=data.value+' (validated)')
889+
defoutput_validator(data:OutputType|NotOutputType)->OutputType|NotOutputType:
890+
assertisinstance(data,OutputType)
891+
returnOutputType(value=data.value+' (validated)')
892892

893-
outputs:list[ResultType]= []
893+
outputs:list[OutputType]= []
894894
asyncwithagent.iter('test')asrun:
895895
asyncfornodeinrun:
896896
ifagent.is_model_request_node(node):
897897
asyncwithnode.stream(run.ctx)asstream:
898898
asyncforoutputinstream.stream_output(debounce_by=None):
899899
outputs.append(output)
900-
assertoutputs== [ResultType(value='a (validated)'),ResultType(value='a (validated)')]
900+
assertoutputs== [OutputType(value='a (validated)'),OutputType(value='a (validated)')]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp