Files
home_stack/notebooks/pydantic_test.py
T
furyhawk aac7383d2d Add Pydantic-based dice game implementation
- Introduced a new notebook `pydantic_embedding.py` for future enhancements.
- Created a `pydantic_test.py` notebook that implements a dice game using the Pydantic AI Agent.
- The game rolls a die and checks if the result matches the player's guess, incorporating the player's name in the response.
2026-05-04 19:34:26 +08:00

32 lines
789 B
Python

import random
from pydantic_ai import Agent, RunContext
agent = Agent(
# "deepseek:deepseek-v4-flash",
# 'openai:gpt-5.4-mini',
# 'alibaba:qwen-flash',
'groq:qwen/qwen3-32b',
deps_type=str,
instructions=(
"You're a dice game, you should roll the die and see if the number "
"you get back matches the user's guess. If so, tell them they're a winner. "
"Use the player's name in the response."
),
)
@agent.tool_plain
def roll_dice() -> str:
"""Roll a six-sided die and return the result."""
return str(random.randint(1, 6))
@agent.tool
def get_player_name(ctx: RunContext[str]) -> str:
"""Get the player's name."""
return ctx.deps
dice_result = agent.run_sync("My guess is 4", deps="Anne")
print(dice_result.output)