-
Notifications
You must be signed in to change notification settings - Fork 99
Use Pydantic AI for LLM chat #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
@MPietrala FYI, I have tried reimplementing the chat endpoint using Pydantic AI, with the existing RAG functionality as a tool. It seems to work! Let me know if you have any comments. |
85b8c47 to
01e4e49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates the LLM chat functionality from using OpenAI's Python SDK directly to using Pydantic AI, a framework that provides structured agent-based interactions with LLMs. The migration introduces tool-based function calling capabilities and improves the overall architecture of AI interactions.
- Replaced direct OpenAI client usage with Pydantic AI agent framework
- Introduced new tool-based architecture with
get_current_dateandsearch_genealogy_databasetools - Updated dependencies to use
pydantic-ai[openai]>=1.0.0instead of standaloneopenaipackage
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Updated AI dependencies: added pydantic-ai[openai]>=1.0.0, added version constraint to sentence-transformers, removed boto3 version constraint, removed standalone openai package |
| gramps_webapi/api/resources/chat.py | Changed function call from answer_prompt_retrieve to answer_with_agent and improved error message to include exception details |
| gramps_webapi/api/llm/init.py | Added new answer_with_agent function with Pydantic AI agent support, message history conversion, moved raise statement, renamed variable from total to _, added docstring to answer_prompt_retrieve |
| gramps_webapi/api/llm/deps.py | New file defining AgentDeps dataclass for agent dependencies |
| gramps_webapi/api/llm/agent.py | New file defining agent creation logic with system prompt and tool registration |
| gramps_webapi/api/llm/tools.py | New file defining Pydantic AI tools: get_current_date and search_genealogy_database with logging decorator |
| tests/test_endpoints/test_chat.py | Updated test to mock create_agent instead of OpenAI client, simplified mock structure |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Groundwork for tool calling in AI chat, see #586.