This project implements an AI agent that can interact with Google's Gemini model, fetch summaries from Wikipedia, and retrieve news articles.
- Gemini Integration: Uses Google's Gemini model to answer prompts and generate text.
- Wikipedia Lookup: Fetches summaries from Wikipedia based on a given topic.
- News Retrieval: Retrieves recent news articles related to a specified keyword using the News API.
- Task History: Keeps track of executed tasks and their responses.
- Python 3.7 or higher
- Install the required packages:
pip install -r requirements.txt
- Set the following environment variables:
GOOGLE_API_KEY
: Your Google Gemini API key.NEWS_API_KEY
: Your News API key (optional, for news functionality).
- Clone the repository (if applicable).
- Navigate to the project directory.
- Create a
.env
file in the project root and add your API keys:GOOGLE_API_KEY=YOUR_GOOGLE_API_KEY NEWS_API_KEY=YOUR_NEWS_API_KEY
- Run the main script:
python main.py
- Import Statements: Added necessary import statements for
google.generativeai
,requests
,json
,datetime
,os
,sys
,dotenv
, andtyping
. - Environment Variable Loading: Implemented loading of environment variables using
dotenv
to securely store API keys. - AdvancedAgent Class:
- Added a class
AdvancedAgent
to encapsulate the AI agent's functionality. - Includes methods for interacting with Gemini (
ask_gemini
), fetching Wikipedia summaries (fetch_wikipedia_summary
), fetching news articles (fetch_news
), and executing tasks (execute_task
). - Includes a
task_log
to store executed tasks and their responses. - Includes a
_manage_memory
method to manage the agent's memory.
- Added a class
- Main Function:
- Initializes the AI agent and handles user input.
- Provides a command-line interface for interacting with the agent.
- Handles exceptions and provides informative error messages.
- Error Handling: Implemented comprehensive error handling throughout the code to catch potential issues with API requests, environment variables, and user input.