Skip to content

Conversation

@DavidMStraub
Copy link
Member

@DavidMStraub DavidMStraub commented Oct 30, 2025

Groundwork for tool calling in AI chat, see #586.

@DavidMStraub
Copy link
Member Author

@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.

@DavidMStraub DavidMStraub requested a review from Copilot November 9, 2025 16:52
Copy link
Contributor

Copilot AI left a 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_date and search_genealogy_database tools
  • Updated dependencies to use pydantic-ai[openai]>=1.0.0 instead of standalone openai package

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant