pydantic-ai-examples 1.24.0__py3-none-any.whl → 1.31.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.
- pydantic_ai_examples/bank_support.py +40 -34
- {pydantic_ai_examples-1.24.0.dist-info → pydantic_ai_examples-1.31.0.dist-info}/METADATA +3 -3
- {pydantic_ai_examples-1.24.0.dist-info → pydantic_ai_examples-1.31.0.dist-info}/RECORD +5 -5
- {pydantic_ai_examples-1.24.0.dist-info → pydantic_ai_examples-1.31.0.dist-info}/WHEEL +1 -1
- {pydantic_ai_examples-1.24.0.dist-info → pydantic_ai_examples-1.31.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -5,6 +5,7 @@ Run with:
|
|
|
5
5
|
uv run -m pydantic_ai_examples.bank_support
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
+
import sqlite3
|
|
8
9
|
from dataclasses import dataclass
|
|
9
10
|
|
|
10
11
|
from pydantic import BaseModel
|
|
@@ -12,25 +13,24 @@ from pydantic import BaseModel
|
|
|
12
13
|
from pydantic_ai import Agent, RunContext
|
|
13
14
|
|
|
14
15
|
|
|
16
|
+
@dataclass
|
|
15
17
|
class DatabaseConn:
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else:
|
|
33
|
-
return 100.00
|
|
18
|
+
"""A wrapper over the SQLite connection."""
|
|
19
|
+
|
|
20
|
+
sqlite_conn: sqlite3.Connection
|
|
21
|
+
|
|
22
|
+
async def customer_name(self, *, id: int) -> str | None:
|
|
23
|
+
res = cur.execute('SELECT name FROM customers WHERE id=?', (id,))
|
|
24
|
+
row = res.fetchone()
|
|
25
|
+
if row:
|
|
26
|
+
return row[0]
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
async def customer_balance(self, *, id: int) -> float:
|
|
30
|
+
res = cur.execute('SELECT balance FROM customers WHERE id=?', (id,))
|
|
31
|
+
row = res.fetchone()
|
|
32
|
+
if row:
|
|
33
|
+
return row[0]
|
|
34
34
|
else:
|
|
35
35
|
raise ValueError('Customer not found')
|
|
36
36
|
|
|
@@ -69,27 +69,33 @@ async def add_customer_name(ctx: RunContext[SupportDependencies]) -> str:
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
@support_agent.tool
|
|
72
|
-
async def customer_balance(
|
|
73
|
-
ctx: RunContext[SupportDependencies], include_pending: bool
|
|
74
|
-
) -> str:
|
|
72
|
+
async def customer_balance(ctx: RunContext[SupportDependencies]) -> str:
|
|
75
73
|
"""Returns the customer's current account balance."""
|
|
76
74
|
balance = await ctx.deps.db.customer_balance(
|
|
77
75
|
id=ctx.deps.customer_id,
|
|
78
|
-
include_pending=include_pending,
|
|
79
76
|
)
|
|
80
77
|
return f'${balance:.2f}'
|
|
81
78
|
|
|
82
79
|
|
|
83
80
|
if __name__ == '__main__':
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
with sqlite3.connect(':memory:') as con:
|
|
82
|
+
cur = con.cursor()
|
|
83
|
+
cur.execute('CREATE TABLE customers(id, name, balance)')
|
|
84
|
+
cur.execute("""
|
|
85
|
+
INSERT INTO customers VALUES
|
|
86
|
+
(123, 'John', 123.45)
|
|
87
|
+
""")
|
|
88
|
+
con.commit()
|
|
89
|
+
|
|
90
|
+
deps = SupportDependencies(customer_id=123, db=DatabaseConn(sqlite_conn=con))
|
|
91
|
+
result = support_agent.run_sync('What is my balance?', deps=deps)
|
|
92
|
+
print(result.output)
|
|
93
|
+
"""
|
|
94
|
+
support_advice='Hello John, your current account balance, including pending transactions, is $123.45.' block_card=False risk=1
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
result = support_agent.run_sync('I just lost my card!', deps=deps)
|
|
98
|
+
print(result.output)
|
|
99
|
+
"""
|
|
100
|
+
support_advice="I'm sorry to hear that, John. We are temporarily blocking your card to prevent unauthorized transactions." block_card=True risk=8
|
|
101
|
+
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pydantic-ai-examples
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.31.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
|
|
@@ -34,8 +34,8 @@ Requires-Dist: logfire[asyncpg,fastapi,httpx,sqlite3]>=3.14.1
|
|
|
34
34
|
Requires-Dist: mcp[cli]>=1.4.1
|
|
35
35
|
Requires-Dist: modal>=1.0.4
|
|
36
36
|
Requires-Dist: pandas>=2.2.3
|
|
37
|
-
Requires-Dist: pydantic-ai-slim[ag-ui,anthropic,groq,openai,vertexai]==1.
|
|
38
|
-
Requires-Dist: pydantic-evals==1.
|
|
37
|
+
Requires-Dist: pydantic-ai-slim[ag-ui,anthropic,groq,openai,vertexai]==1.31.0
|
|
38
|
+
Requires-Dist: pydantic-evals==1.31.0
|
|
39
39
|
Requires-Dist: python-multipart>=0.0.17
|
|
40
40
|
Requires-Dist: rich>=13.9.2
|
|
41
41
|
Requires-Dist: uvicorn>=0.32.0
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
pydantic_ai_examples/__main__.py,sha256=i0LEo2JBOZ-gnHED0ou5Bya43gi7KmOyQ_jKN7M5Ces,1647
|
|
2
|
-
pydantic_ai_examples/bank_support.py,sha256=
|
|
2
|
+
pydantic_ai_examples/bank_support.py,sha256=5y53eLwfRUu1Ys_qQxd8hzbSMbnkCnd5Cx27fpK8LEo,2937
|
|
3
3
|
pydantic_ai_examples/chat_app.html,sha256=90XhxrpDAT09mPVTn9edEn8PqAD-tHxWkeeMz9r_okQ,2580
|
|
4
4
|
pydantic_ai_examples/chat_app.py,sha256=AX28rI0TR9lTPLDOd0uEkmirvfIZCRyCGr_VdGiOkHM,7053
|
|
5
5
|
pydantic_ai_examples/chat_app.ts,sha256=2KfZ2rJU2o0iCPjelyqEi5sH6vfemzWaa5Evx_VcAE4,3307
|
|
@@ -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-1.
|
|
48
|
-
pydantic_ai_examples-1.
|
|
49
|
-
pydantic_ai_examples-1.
|
|
50
|
-
pydantic_ai_examples-1.
|
|
47
|
+
pydantic_ai_examples-1.31.0.dist-info/METADATA,sha256=-_KvoHoKdHE95jUwHoooC-v6ac7YT0bUFeQPRvLcHzA,2763
|
|
48
|
+
pydantic_ai_examples-1.31.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
|
|
49
|
+
pydantic_ai_examples-1.31.0.dist-info/licenses/LICENSE,sha256=vA6Jc482lEyBBuGUfD1pYx-cM7jxvLYOxPidZ30t_PQ,1100
|
|
50
|
+
pydantic_ai_examples-1.31.0.dist-info/RECORD,,
|
{pydantic_ai_examples-1.24.0.dist-info → pydantic_ai_examples-1.31.0.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|