项目文件夹

文件
wehub-resource-sync 9201ef759e
Harness Compat / harness compat (push) Failing after 0s
CI / test on 3.12 (standard) (push) Has been cancelled
CI / test on 3.13 (standard) (push) Has been cancelled
CI / test on 3.14 (standard) (push) Has been cancelled
CI / test on 3.10 (all-extras) (push) Has been cancelled
CI / test on 3.11 (all-extras) (push) Has been cancelled
CI / test on 3.12 (all-extras) (push) Has been cancelled
CI / test on 3.14 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.10 (pydantic-evals) (push) Has been cancelled
CI / test on 3.11 (pydantic-evals) (push) Has been cancelled
CI / test on 3.12 (pydantic-evals) (push) Has been cancelled
CI / deploy-docs-preview (push) Has been cancelled
CI / build release artifacts (push) Has been cancelled
CI / publish to PyPI (push) Has been cancelled
CI / Send tweet (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / mypy (push) Has been cancelled
CI / docs (push) Has been cancelled
CI / test on 3.10 (standard) (push) Has been cancelled
CI / test on 3.11 (standard) (push) Has been cancelled
CI / test on 3.13 (all-extras) (push) Has been cancelled
CI / test on 3.14 (all-extras) (push) Has been cancelled
CI / test on 3.10 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.11 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.12 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-ai-slim) (push) Has been cancelled
CI / test on 3.13 (pydantic-evals) (push) Has been cancelled
CI / test on 3.14 (pydantic-evals) (push) Has been cancelled
CI / test on 3.10 (lowest-versions) (push) Has been cancelled
CI / test on 3.11 (lowest-versions) (push) Has been cancelled
CI / test on 3.12 (lowest-versions) (push) Has been cancelled
CI / test on 3.13 (lowest-versions) (push) Has been cancelled
CI / test on 3.14 (lowest-versions) (push) Has been cancelled
CI / test examples on 3.11 (push) Has been cancelled
CI / test examples on 3.12 (push) Has been cancelled
CI / test examples on 3.13 (push) Has been cancelled
CI / test examples on 3.14 (push) Has been cancelled
CI / coverage (push) Has been cancelled
CI / check (push) Has been cancelled
CI / deploy-docs (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:27:52 +08:00

68 行
1.6 KiB
Python

"""Example demonstrating how to use Pydantic AI to create a simple roulette game.
Run with:
uv run -m pydantic_ai_examples.roulette_wheel
"""
from __future__ import annotations as _annotations
import asyncio
from dataclasses import dataclass
from typing import Literal
from pydantic_ai import Agent, RunContext
# Define the dependencies class
@dataclass
class Deps:
winning_number: int
# Create the agent with proper typing
roulette_agent = Agent(
'groq:llama-3.3-70b-versatile',
deps_type=Deps,
retries=3,
output_type=bool,
system_prompt=(
'Use the `roulette_wheel` function to determine if the customer has won based on the number they bet on.'
),
)
@roulette_agent.tool
async def roulette_wheel(
ctx: RunContext[Deps], square: int
) -> Literal['winner', 'loser']:
"""Check if the bet square is a winner.
Args:
ctx: The context containing the winning number.
square: The number the player bet on.
"""
return 'winner' if square == ctx.deps.winning_number else 'loser'
async def main():
# Set up dependencies
winning_number = 18
deps = Deps(winning_number=winning_number)
# Run some example bets using streaming
async with roulette_agent.run_stream(
'Put my money on square eighteen', deps=deps
) as response:
result = await response.get_output()
print('Bet on 18:', result)
async with roulette_agent.run_stream(
'I bet five is the winner', deps=deps
) as response:
result = await response.get_output()
print('Bet on 5:', result)
if __name__ == '__main__':
asyncio.run(main())