This project implements a smart assistant using the pydantic-ai library. The assistant is capable of performing various tasks such as fetching weather information, evaluating mathematical expressions, planning trips, managing Google Calendar events, retrieving upcoming events, and performing web searches. The assistant is integrated with Gradio to provide a user-friendly chatbot interface.
- Fetches the current weather for a specified city using the WeatherAPI.
- Example: "What's the weather in Dhaka?"
- Evaluates mathematical expressions provided by the user.
- Example: "What is 2 + 3 * 4?"
- Plans a trip by providing details such as attractions, food recommendations, activities, and budget.
- Example: "Plan a 5-day trip to Paris."
- Performs intelligent web searches to retrieve relevant information quickly and efficiently.
- Example: "Add a trip to Sylhet from June 1 to June 5."
- Adds events to Google Calendar.
- Retrieves upcoming events from Google Calendar within a specified date range.
- Example: "what is the Current status of Bangladesh?"
- A Gradio-based chatbot interface for interacting with the assistant.
- Install the required dependencies:
pip install pydantic-ai ollama logfire devtools --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
- Create a
.envfile in the project directory and add your WeatherAPI key:weatherapicom_API_KEY=your-weather-api-key
- Ensure you have a
credentials.jsonfile for Google Calendar API authentication.
- Launch the assistant by running the notebook or script. The Gradio interface will open in your browser.
- Function:
get_weather - Description: Fetches the current weather temperature for a specified city using the WeatherAPI.
- API Used: WeatherAPI
- Example:
await get_weather(context, "Dhaka")
- Function:
calculate_expression - Description: Evaluates mathematical expressions provided as a string.
- Example:
await calculate_expression("2 + 3 * 4")
- Function:
tripPlanner - Description: Plans a trip by providing details such as attractions, food recommendations, activities, and budget.
- Example:
await tripPlanner("2024-06-01", "2024-06-05", "Paris")
- Function:
add_to_google_calendar - Description: Adds an event to Google Calendar with the provided details.
- Example:
await add_to_google_calendar("Trip to Sylhet", "Sylhet", "2024-06-01", "2024-06-05")
- Function:
get_upcoming_events - Description: Retrieves upcoming Google Calendar events within a given date range or defaults to the next month.
- Example:
await get_upcoming_events("2024-06-01", "2024-06-15")
- Function:
searchWeb - Description: Searches for a query using Google Search and returns the top 5 results with titles and descriptions.
- Example:
await searchWeb(What is the Current Status of Bangladesh?)
The assistant is integrated with Gradio to provide a chatbot interface. Users can:
- Ask questions or give commands in the text box.
- View the assistant's responses in the chat window.
- Clear the chat history using the "Clear Chat" button.
- The assistant uses the
pydantic-ailibrary to define tools and manage interactions. - Tools are registered with the agent to handle specific tasks.
- Dependencies like the WeatherAPI key and HTTP client are injected into the agent.
- The agent decides which tool to call based on the user's input.
- Tools are executed asynchronously, and their results are returned to the user.
- The chatbot interface is built using Gradio.
- User inputs are processed, and the assistant's responses are displayed in real-time.
- Input: "What's the weather in Dhaka?"
- Output: "The weather in Dhaka is 30°C."
- Input: "What is 10 / 2?"
- Output: "5.0"
- Input: "Plan a 3-day trip to Tokyo."
- Output: Details about attractions, food, activities, and budget.
- Input: "Add a trip to Sylhet from June 1 to June 5."
- Output: "✅ Trip added to your Google Calendar: [Event Link]"
- Input: "What are my events for the next week?"
- Output: List of upcoming events with dates and summaries.
- Input: "What is the status of Bangladesh now?"
- Output: List of search links with their title and descriptions.
- Ensure that the required API keys are set up in the
.envfile. - Google Calendar integration requires
credentials.jsonfor authentication. - The assistant uses
pydantic-aifor structured output and tool management.
This project is licensed under the MIT License. See the MIT LICENSE file for details.