pydantic-ai-examples 0.8.1__py3-none-any.whl → 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pydantic-ai-examples might be problematic. Click here for more details.

@@ -7,7 +7,7 @@ Run with:
7
7
 
8
8
  from dataclasses import dataclass
9
9
 
10
- from pydantic import BaseModel, Field
10
+ from pydantic import BaseModel
11
11
 
12
12
  from pydantic_ai import Agent, RunContext
13
13
 
@@ -42,16 +42,19 @@ class SupportDependencies:
42
42
 
43
43
 
44
44
  class SupportOutput(BaseModel):
45
- support_advice: str = Field(description='Advice returned to the customer')
46
- block_card: bool = Field(description='Whether to block their card or not')
47
- risk: int = Field(description='Risk level of query', ge=0, le=10)
45
+ support_advice: str
46
+ """Advice returned to the customer"""
47
+ block_card: bool
48
+ """Whether to block their card or not"""
49
+ risk: int
50
+ """Risk level of query"""
48
51
 
49
52
 
50
53
  support_agent = Agent(
51
54
  'openai:gpt-4o',
52
55
  deps_type=SupportDependencies,
53
56
  output_type=SupportOutput,
54
- system_prompt=(
57
+ instructions=(
55
58
  'You are a support agent in our bank, give the '
56
59
  'customer support and judge the risk level of their query. '
57
60
  "Reply using the customer's name."
@@ -59,7 +62,7 @@ support_agent = Agent(
59
62
  )
60
63
 
61
64
 
62
- @support_agent.system_prompt
65
+ @support_agent.instructions
63
66
  async def add_customer_name(ctx: RunContext[SupportDependencies]) -> str:
64
67
  customer_name = await ctx.deps.db.customer_name(id=ctx.deps.customer_id)
65
68
  return f"The customer's name is {customer_name!r}"
@@ -10,14 +10,14 @@ from __future__ import annotations as _annotations
10
10
  import asyncio
11
11
  import json
12
12
  import sqlite3
13
- from collections.abc import AsyncIterator
13
+ from collections.abc import AsyncIterator, Callable
14
14
  from concurrent.futures.thread import ThreadPoolExecutor
15
15
  from contextlib import asynccontextmanager
16
16
  from dataclasses import dataclass
17
17
  from datetime import datetime, timezone
18
18
  from functools import partial
19
19
  from pathlib import Path
20
- from typing import Annotated, Any, Callable, Literal, TypeVar
20
+ from typing import Annotated, Any, Literal, TypeVar
21
21
 
22
22
  import fastapi
23
23
  import logfire
@@ -25,8 +25,7 @@ from fastapi import Depends, Request
25
25
  from fastapi.responses import FileResponse, Response, StreamingResponse
26
26
  from typing_extensions import LiteralString, ParamSpec, TypedDict
27
27
 
28
- from pydantic_ai import Agent
29
- from pydantic_ai.exceptions import UnexpectedModelBehavior
28
+ from pydantic_ai import Agent, UnexpectedModelBehavior
30
29
  from pydantic_ai.messages import (
31
30
  ModelMessage,
32
31
  ModelMessagesTypeAdapter,
@@ -1,6 +1,11 @@
1
1
  from dataclasses import dataclass
2
2
  from datetime import timedelta
3
3
 
4
+ from pydantic_ai_examples.evals.models import (
5
+ TimeRangeBuilderSuccess,
6
+ TimeRangeInputs,
7
+ TimeRangeResponse,
8
+ )
4
9
  from pydantic_evals.evaluators import (
5
10
  Evaluator,
6
11
  EvaluatorContext,
@@ -8,12 +13,6 @@ from pydantic_evals.evaluators import (
8
13
  )
9
14
  from pydantic_evals.otel import SpanQuery
10
15
 
11
- from pydantic_ai_examples.evals.models import (
12
- TimeRangeBuilderSuccess,
13
- TimeRangeInputs,
14
- TimeRangeResponse,
15
- )
16
-
17
16
 
18
17
  @dataclass
19
18
  class ValidateTimeRange(Evaluator[TimeRangeInputs, TimeRangeResponse]):
@@ -2,11 +2,10 @@ import asyncio
2
2
  from pathlib import Path
3
3
  from types import NoneType
4
4
 
5
+ from pydantic_ai_examples.evals.models import TimeRangeInputs, TimeRangeResponse
5
6
  from pydantic_evals import Dataset
6
7
  from pydantic_evals.generation import generate_dataset
7
8
 
8
- from pydantic_ai_examples.evals.models import TimeRangeInputs, TimeRangeResponse
9
-
10
9
 
11
10
  async def main():
12
11
  dataset = await generate_dataset(
@@ -1,8 +1,6 @@
1
1
  from pathlib import Path
2
2
  from types import NoneType
3
3
 
4
- from pydantic_evals import Dataset
5
-
6
4
  from pydantic_ai_examples.evals.custom_evaluators import (
7
5
  CUSTOM_EVALUATOR_TYPES,
8
6
  AgentCalledTool,
@@ -13,6 +11,7 @@ from pydantic_ai_examples.evals.models import (
13
11
  TimeRangeInputs,
14
12
  TimeRangeResponse,
15
13
  )
14
+ from pydantic_evals import Dataset
16
15
 
17
16
 
18
17
  def main():
@@ -2,7 +2,6 @@ from pathlib import Path
2
2
  from types import NoneType
3
3
 
4
4
  import logfire
5
- from pydantic_evals import Dataset
6
5
 
7
6
  from pydantic_ai_examples.evals import infer_time_range
8
7
  from pydantic_ai_examples.evals.custom_evaluators import (
@@ -12,6 +11,7 @@ from pydantic_ai_examples.evals.models import (
12
11
  TimeRangeInputs,
13
12
  TimeRangeResponse,
14
13
  )
14
+ from pydantic_evals import Dataset
15
15
 
16
16
  logfire.configure(
17
17
  send_to_logfire='if-token-present',
@@ -29,7 +29,9 @@ def evaluate_dataset():
29
29
  report = dataset.evaluate_sync(infer_time_range)
30
30
  print(report)
31
31
 
32
- assertion_pass_rate = report.averages().assertions
32
+ averages = report.averages()
33
+ assert averages is not None
34
+ assertion_pass_rate = averages.assertions
33
35
  assert assertion_pass_rate is not None, 'There should be at least one assertion'
34
36
  assert assertion_pass_rate > 0.9, (
35
37
  f'The assertion pass rate was {assertion_pass_rate:.1%}; it should be above 90%.'
@@ -2,7 +2,6 @@ from pathlib import Path
2
2
  from types import NoneType
3
3
 
4
4
  import logfire
5
- from pydantic_evals import Dataset
6
5
 
7
6
  from pydantic_ai_examples.evals import infer_time_range
8
7
  from pydantic_ai_examples.evals.agent import time_range_agent
@@ -13,6 +12,7 @@ from pydantic_ai_examples.evals.models import (
13
12
  TimeRangeInputs,
14
13
  TimeRangeResponse,
15
14
  )
15
+ from pydantic_evals import Dataset
16
16
 
17
17
  logfire.configure(
18
18
  send_to_logfire='if-token-present',
@@ -11,9 +11,8 @@ import logfire
11
11
  from pydantic import BaseModel, Field
12
12
  from rich.prompt import Prompt
13
13
 
14
- from pydantic_ai import Agent, ModelRetry, RunContext
14
+ from pydantic_ai import Agent, ModelRetry, RunContext, RunUsage, UsageLimits
15
15
  from pydantic_ai.messages import ModelMessage
16
- from pydantic_ai.usage import RunUsage, UsageLimits
17
16
 
18
17
  # 'if-token-present' means nothing will be sent (and the example will work) if you don't have logfire configured
19
18
  logfire.configure(send_to_logfire='if-token-present')
@@ -12,6 +12,9 @@ from pathlib import Path
12
12
 
13
13
  import logfire
14
14
  from groq import BaseModel
15
+
16
+ from pydantic_ai import Agent, format_as_xml
17
+ from pydantic_ai.messages import ModelMessage
15
18
  from pydantic_graph import (
16
19
  BaseNode,
17
20
  End,
@@ -20,9 +23,6 @@ from pydantic_graph import (
20
23
  )
21
24
  from pydantic_graph.persistence.file import FileStatePersistence
22
25
 
23
- from pydantic_ai import Agent, format_as_xml
24
- from pydantic_ai.messages import ModelMessage
25
-
26
26
  # 'if-token-present' means nothing will be sent (and the example will work) if you don't have logfire configured
27
27
  logfire.configure(send_to_logfire='if-token-present')
28
28
  logfire.instrument_pydantic_ai()
@@ -34,8 +34,7 @@ from openai import AsyncOpenAI
34
34
  from pydantic import TypeAdapter
35
35
  from typing_extensions import AsyncGenerator
36
36
 
37
- from pydantic_ai import RunContext
38
- from pydantic_ai.agent import Agent
37
+ from pydantic_ai import Agent, RunContext
39
38
 
40
39
  # 'if-token-present' means nothing will be sent (and the example will work) if you don't have logfire configured
41
40
  logfire.configure(send_to_logfire='if-token-present')
@@ -16,14 +16,13 @@ from collections.abc import AsyncGenerator
16
16
  from contextlib import asynccontextmanager
17
17
  from dataclasses import dataclass
18
18
  from datetime import date
19
- from typing import Annotated, Any, Union
19
+ from typing import Annotated, Any, TypeAlias
20
20
 
21
21
  import asyncpg
22
22
  import logfire
23
23
  from annotated_types import MinLen
24
24
  from devtools import debug
25
25
  from pydantic import BaseModel, Field
26
- from typing_extensions import TypeAlias
27
26
 
28
27
  from pydantic_ai import Agent, ModelRetry, RunContext, format_as_xml
29
28
 
@@ -91,7 +90,7 @@ class InvalidRequest(BaseModel):
91
90
  error_message: str
92
91
 
93
92
 
94
- Response: TypeAlias = Union[Success, InvalidRequest]
93
+ Response: TypeAlias = Success | InvalidRequest
95
94
  agent = Agent[Deps, Response](
96
95
  'google-gla:gemini-1.5-flash',
97
96
  # Type ignore while we wait for PEP-0747, nonetheless unions will work fine everywhere else
@@ -3,6 +3,7 @@ from __future__ import annotations as _annotations
3
3
  import json
4
4
 
5
5
  from httpx import AsyncClient
6
+ from pydantic import BaseModel
6
7
 
7
8
  from pydantic_ai.messages import ToolCallPart, ToolReturnPart
8
9
  from pydantic_ai_examples.weather_agent import Deps, weather_agent
@@ -48,9 +49,11 @@ async def stream_from_agent(prompt: str, chatbot: list[dict], past_messages: lis
48
49
  gr_message.get('metadata', {}).get('id', '')
49
50
  == call.tool_call_id
50
51
  ):
51
- gr_message['content'] += (
52
- f'\nOutput: {json.dumps(call.content)}'
53
- )
52
+ if isinstance(call.content, BaseModel):
53
+ json_content = call.content.model_dump_json()
54
+ else:
55
+ json_content = json.dumps(call.content)
56
+ gr_message['content'] += f'\nOutput: {json_content}'
54
57
  yield gr.skip(), chatbot, gr.skip()
55
58
  chatbot.append({'role': 'assistant', 'content': ''})
56
59
  async for message in result.stream_text():
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pydantic-ai-examples
3
- Version: 0.8.1
3
+ Version: 1.0.0
4
4
  Summary: Examples of how to use Pydantic AI and what it can do.
5
5
  Author-email: Samuel Colvin <samuel@pydantic.dev>, Marcelo Trylesinski <marcelotryle@gmail.com>, David Montague <david@pydantic.dev>, Alex Hall <alex@pydantic.dev>, Douwe Maan <douwe@pydantic.dev>
6
6
  License-Expression: MIT
7
7
  License-File: LICENSE
8
- Classifier: Development Status :: 4 - Beta
8
+ Classifier: Development Status :: 5 - Production/Stable
9
9
  Classifier: Environment :: Console
10
10
  Classifier: Environment :: MacOS X
11
11
  Classifier: Intended Audience :: Developers
@@ -17,26 +17,25 @@ Classifier: Operating System :: Unix
17
17
  Classifier: Programming Language :: Python
18
18
  Classifier: Programming Language :: Python :: 3
19
19
  Classifier: Programming Language :: Python :: 3 :: Only
20
- Classifier: Programming Language :: Python :: 3.9
21
20
  Classifier: Programming Language :: Python :: 3.10
22
21
  Classifier: Programming Language :: Python :: 3.11
23
22
  Classifier: Programming Language :: Python :: 3.12
24
23
  Classifier: Programming Language :: Python :: 3.13
25
24
  Classifier: Topic :: Internet
26
25
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
- Requires-Python: >=3.9
26
+ Requires-Python: >=3.10
28
27
  Requires-Dist: asyncpg>=0.30.0
29
28
  Requires-Dist: datasets>=4.0.0
30
29
  Requires-Dist: devtools>=0.12.2
31
30
  Requires-Dist: duckdb>=1.3.2
32
31
  Requires-Dist: fastapi>=0.115.4
33
- Requires-Dist: gradio>=5.9.0; python_version > '3.9'
32
+ Requires-Dist: gradio>=5.9.0
34
33
  Requires-Dist: logfire[asyncpg,fastapi,httpx,sqlite3]>=3.14.1
35
- Requires-Dist: mcp[cli]>=1.4.1; python_version >= '3.10'
34
+ Requires-Dist: mcp[cli]>=1.4.1
36
35
  Requires-Dist: modal>=1.0.4
37
36
  Requires-Dist: pandas>=2.2.3
38
- Requires-Dist: pydantic-ai-slim[ag-ui,anthropic,groq,openai,vertexai]==0.8.1
39
- Requires-Dist: pydantic-evals==0.8.1
37
+ Requires-Dist: pydantic-ai-slim[ag-ui,anthropic,groq,openai,vertexai]==1.0.0
38
+ Requires-Dist: pydantic-evals==1.0.0
40
39
  Requires-Dist: python-multipart>=0.0.17
41
40
  Requires-Dist: rich>=13.9.2
42
41
  Requires-Dist: uvicorn>=0.32.0
@@ -1,20 +1,20 @@
1
1
  pydantic_ai_examples/__main__.py,sha256=i0LEo2JBOZ-gnHED0ou5Bya43gi7KmOyQ_jKN7M5Ces,1647
2
- pydantic_ai_examples/bank_support.py,sha256=vJL2zLEq19OztP1fUGG7_6cYHllvxvzkafFMqukimMo,2726
2
+ pydantic_ai_examples/bank_support.py,sha256=TEy19B4iyB49A-ZMv1rOZIE_bOHml5er1Qaz700e2NU,2665
3
3
  pydantic_ai_examples/chat_app.html,sha256=90XhxrpDAT09mPVTn9edEn8PqAD-tHxWkeeMz9r_okQ,2580
4
- pydantic_ai_examples/chat_app.py,sha256=3rfU8ZTG_F14KxPE9stb9aJ7LhPFOL_pK4APEnwcWoQ,7112
4
+ pydantic_ai_examples/chat_app.py,sha256=Aeep1DoXSsY7-STFT0gfDHqT7QpID_r_0sHloVOix5c,7078
5
5
  pydantic_ai_examples/chat_app.ts,sha256=2KfZ2rJU2o0iCPjelyqEi5sH6vfemzWaa5Evx_VcAE4,3307
6
6
  pydantic_ai_examples/data_analyst.py,sha256=vSpfIWpxNgaZqKx2DJD721ZA3QgSjaZkTixy5OHz9xY,3753
7
- pydantic_ai_examples/flight_booking.py,sha256=YPCS6v6RtVggFawPMhAjTPFMuihPlecM5a5QB919Pqc,7450
7
+ pydantic_ai_examples/flight_booking.py,sha256=iwounbq5ej6kwmbot7Ayk3zye-JXKzD70Usqip19pQM,7421
8
8
  pydantic_ai_examples/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  pydantic_ai_examples/pydantic_model.py,sha256=EQsHBig2bvb0PG_2XDgP9Le5xJ4n8eZJzQDGQYhDykg,775
10
- pydantic_ai_examples/question_graph.py,sha256=POIBYGNDRyqAg08ReglBPcAZAcqHJMdcpCA2VOwiWNw,5107
11
- pydantic_ai_examples/rag.py,sha256=mFEnJqofVbx_1jru2FZWgskfyDP965IFfanwSlbQzMs,8005
10
+ pydantic_ai_examples/question_graph.py,sha256=XK5M-AshO402VDcwz12P4kU1-mRiZcESdfGZsyZCX_U,5107
11
+ pydantic_ai_examples/rag.py,sha256=lWIusQc1_CQ4GrXRJgteXfDpTfl2AZrd4qZcOXPBC5o,7976
12
12
  pydantic_ai_examples/roulette_wheel.py,sha256=2YHKbGzYOkLsd98hO3ntjM6pChR1UpmsRrLD36Qh5f0,1654
13
- pydantic_ai_examples/sql_gen.py,sha256=HLNR6-Ah_7T0IodE62Tk88-MP3_w_LOybTocyaIV3dU,5201
13
+ pydantic_ai_examples/sql_gen.py,sha256=rRp_C0ZvfLu6rkR5wrVvgah6wd92nh1vT4UYurx5pmU,5159
14
14
  pydantic_ai_examples/stream_markdown.py,sha256=rdhrR6XkqoeOpfv_xFbRpKDV4drEAd8ZrsFBXVrdvHs,2454
15
15
  pydantic_ai_examples/stream_whales.py,sha256=Yoa7IuqN_6fowfYSINW39uPCthYu9FKChF-QBmQqWb8,2721
16
16
  pydantic_ai_examples/weather_agent.py,sha256=E42RbuVDJzxlBw9lF2ARNSNAhL1HWVEmTt5MN70DyDU,3187
17
- pydantic_ai_examples/weather_agent_gradio.py,sha256=WVoRqD74jEvGyUs5VHmsRIGduLMu2sP7GHvc3E79T6A,4521
17
+ pydantic_ai_examples/weather_agent_gradio.py,sha256=sW1IV2B8ehrFrJKLDHv73ojosdpBI2h1S_HF662I6MQ,4728
18
18
  pydantic_ai_examples/ag_ui/__init__.py,sha256=ZZs2V-5e9RaLl_7hJAq9-0Juk_f0mk2Vr7a4QT2QB-k,1174
19
19
  pydantic_ai_examples/ag_ui/__main__.py,sha256=PMycatJt8Abb-Q8HXRGZoEY6vnOcvRebH7iI9MxLknA,225
20
20
  pydantic_ai_examples/ag_ui/api/__init__.py,sha256=Pe307_ET_ERKBP-8Vs4L1yZRkK3ILPpajwxDpeW8YiI,673
@@ -26,11 +26,11 @@ pydantic_ai_examples/ag_ui/api/shared_state.py,sha256=1ok84aE4H0J5pWRhcoftf26Y9B
26
26
  pydantic_ai_examples/ag_ui/api/tool_based_generative_ui.py,sha256=eT--lWjTzL0S3aIu9C14yeoixLjFXPWqwcdiuIlUAJk,219
27
27
  pydantic_ai_examples/evals/__init__.py,sha256=4f1v2o4F-gnUVtlkZU-dpwwwbLhqRxMcZv676atjNLg,115
28
28
  pydantic_ai_examples/evals/agent.py,sha256=KjCsUiL28RCNT6NwoQnQCwJ0xRw3EUGdIrYhlIjmVqI,2042
29
- pydantic_ai_examples/evals/custom_evaluators.py,sha256=Uz37_wbT4uA6s9fl46nTsH3NQKyS1KamMPPP860stww,2245
30
- pydantic_ai_examples/evals/example_01_generate_dataset.py,sha256=7fhTY4IMN0xEODGEKtrNlaEIYkqYRauC6w6NRIQnFWY,2369
31
- pydantic_ai_examples/evals/example_02_add_custom_evaluators.py,sha256=mNPEIDnuE3RcfdMtBKhs5aGUdcDtDQD-v7KoSuE1ZDk,978
32
- pydantic_ai_examples/evals/example_03_unit_testing.py,sha256=QNkfMQgBZrN8wWhj0ZRsq9XC46AgtFo9gklgh52e4iE,1151
33
- pydantic_ai_examples/evals/example_04_compare_models.py,sha256=H00BaMEF6etK5497kFjWmdEFbNgVhhq25RDw8KPrLuw,1201
29
+ pydantic_ai_examples/evals/custom_evaluators.py,sha256=siSpALUMrUGJ1DDrm0Ejniuxhmxhlvee_jubgXjOAeU,2244
30
+ pydantic_ai_examples/evals/example_01_generate_dataset.py,sha256=R-cV9bBHMA8EMIyveP5Yf2p3_VV-g_NSXtDa_zz0ODs,2368
31
+ pydantic_ai_examples/evals/example_02_add_custom_evaluators.py,sha256=pFX0bvVeyfbZGGb0LSajRW-g1ZiVID3e3-sEXZVcjv8,977
32
+ pydantic_ai_examples/evals/example_03_unit_testing.py,sha256=G4Ry7ykJfozaQ9GEXi6cnz0O-6pGBrZIkV4_6RNK194,1207
33
+ pydantic_ai_examples/evals/example_04_compare_models.py,sha256=aYCIkbwpD-O4MgAKDik3XlK9Y7xpq9DOFiXRWMes2aE,1201
34
34
  pydantic_ai_examples/evals/models.py,sha256=QYe_fNv03fmF4ssgSqutHgGx2YX5NLKhhth8-0XFnWo,1776
35
35
  pydantic_ai_examples/evals/datasets/time_range_v1.yaml,sha256=pSUawuDen4NQt2RqqJNmrVENgksTWxIFcw-Kkao_yo8,4193
36
36
  pydantic_ai_examples/evals/datasets/time_range_v1_schema.json,sha256=xS-wRRSvcoG2FcQZGdL0i332mbjsZh9MOSJAND6VkWU,19932
@@ -44,7 +44,7 @@ pydantic_ai_examples/slack_lead_qualifier/modal.py,sha256=f464AaeyP-n3UIfvEVVc4D
44
44
  pydantic_ai_examples/slack_lead_qualifier/models.py,sha256=WTp6D2WCASXqrjPVT3vGgTSYATLPBM3_cjq9wvXMRao,1586
45
45
  pydantic_ai_examples/slack_lead_qualifier/slack.py,sha256=VJVfMeUXYClWUJBLHNuaW8PB2sxjNzpTC-O_AJwcxQ4,833
46
46
  pydantic_ai_examples/slack_lead_qualifier/store.py,sha256=04vB4eZWKk_Tx0b9K4QuVI1U24JEyJyBS4X76cui7OI,896
47
- pydantic_ai_examples-0.8.1.dist-info/METADATA,sha256=q4_0xcptzJ9JLMmg4_XvX8QX78nWDsLFllw1QKt8A80,2846
48
- pydantic_ai_examples-0.8.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
49
- pydantic_ai_examples-0.8.1.dist-info/licenses/LICENSE,sha256=vA6Jc482lEyBBuGUfD1pYx-cM7jxvLYOxPidZ30t_PQ,1100
50
- pydantic_ai_examples-0.8.1.dist-info/RECORD,,
47
+ pydantic_ai_examples-1.0.0.dist-info/METADATA,sha256=nHiMaSooi4L7nLfBvt1J5WWqhBDRBjBPqbtA6_tDnek,2760
48
+ pydantic_ai_examples-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
49
+ pydantic_ai_examples-1.0.0.dist-info/licenses/LICENSE,sha256=vA6Jc482lEyBBuGUfD1pYx-cM7jxvLYOxPidZ30t_PQ,1100
50
+ pydantic_ai_examples-1.0.0.dist-info/RECORD,,