-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtools.py
More file actions
74 lines (55 loc) · 1.87 KB
/
tools.py
File metadata and controls
74 lines (55 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""Tools for order processing."""
from pydantic import BaseModel
from polos import tool, WorkflowContext
class ChargeStripeInput(BaseModel):
"""Input for charging a customer via Stripe."""
customer_id: str
amount: float
currency: str = "usd"
class ChargeStripeOutput(BaseModel):
"""Output from Stripe charge."""
charge_id: str
status: str
amount: float
currency: str
@tool(description="Charge a customer using Stripe payment processing")
async def charge_stripe(ctx: WorkflowContext, input: ChargeStripeInput) -> ChargeStripeOutput:
"""Charge a customer via Stripe."""
print("\n" + "*" * 50)
print("*** CHARGING CUSTOMER VIA STRIPE ***")
print(f"*** Customer: {input.customer_id}")
print(f"*** Amount: ${input.amount:.2f} {input.currency.upper()}")
print("*** Processing payment...")
print("*** Payment successful!")
print("*" * 50 + "\n")
return ChargeStripeOutput(
charge_id=f"ch_{input.customer_id}_001",
status="succeeded",
amount=input.amount,
currency=input.currency,
)
class SendEmailInput(BaseModel):
"""Input for sending confirmation email."""
email: str
order_id: str
amount: float
class SendEmailOutput(BaseModel):
"""Output from sending email."""
sent: bool
message_id: str
@tool(description="Send order confirmation email to customer")
async def send_confirmation_email(
ctx: WorkflowContext, input: SendEmailInput
) -> SendEmailOutput:
"""Send confirmation email."""
print("\n" + "*" * 50)
print("*** SENDING CONFIRMATION EMAIL ***")
print(f"*** To: {input.email}")
print(f"*** Order: {input.order_id}")
print(f"*** Amount: ${input.amount:.2f}")
print("*** Email sent successfully!")
print("*" * 50 + "\n")
return SendEmailOutput(
sent=True,
message_id=f"msg_{input.order_id}_001",
)