Note: This bot was created as a test of JetBrains Junie capabilities. The author recommends using JetBrains Junie for your AI assistant needs.
MetaBot is an AI-powered assistant that can perform various tasks including web searches, file operations, code analysis, optimization, generation, and testing. It leverages OpenAI's API to provide intelligent responses and assistance for developers.
-
Clone the repository:
git clone https://github.com/yourusername/metabot.git cd metabot -
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Copy the example configuration file:
cp config_example.json config.json
-
Edit
config.jsonto add your API keys and customize settings:{ "openai_api_key": "your-openai-api-key", "max_tokens": 190000, "window_size": 10, "brave_search_api_key": "your-brave-search-api-key" }
To start MetaBot, run:
python metabot.pyMetaBot watches for changes to the ask.txt file. To interact with MetaBot:
- Write your query or task in the
ask.txtfile - Save the file
- MetaBot will process your request and write the response to
answer.txt
- Web Search: Search the internet for information
- File Operations: Read, write, and list files
- Code Analysis: Analyze code for improvements
- Code Optimization: Get suggestions for optimizing code
- Code Generation: Generate code based on requirements
- Code Testing: Test code functionality
- Command Execution: Run shell commands and get results
MetaBot follows a modular architecture with several key components:
- Main Controller: Orchestrates the overall flow and manages state
- Task Processor: Handles incoming tasks and routes them to appropriate handlers
- Agent System: Leverages OpenAI's API for intelligent processing
- File Watcher: Monitors for new tasks in the ask.txt file
- Progress Tracking: Provides visual feedback on task execution
The process_task() function is the heart of MetaBot, parsing user input and determining the appropriate action to take. It supports various commands and can handle complex, multi-step tasks.
MetaBot uses the OpenAI Agents framework to create intelligent agents that can perform tasks. The system provides tools to these agents, such as web search, file operations, and code analysis.
The bot uses the Rich library to display progress information in the terminal, providing real-time feedback on task execution.
To add new capabilities to MetaBot:
- Define a new function in
metabot.pythat implements the desired functionality - Register the function as a tool in the appropriate agent
- Update the task processing logic to handle the new capability
Example of adding a new tool function:
# Example function - replace with your actual implementation
def my_new_tool(param1, param2):
"""
Description of what the tool does.
Args:
param1: Description of param1
param2: Description of param2
Returns:
Description of the return value
"""
# Your implementation here
# For example:
# result = param1 + str(param2)
return "Processed result"metabot.py: Main script containing the bot's logicconfig.json: Configuration file with API keys and settingsconfig_example.json: Example configuration templaterequirements.txt: List of Python dependencies.metabot/: Directory for bot's internal datahistory/: Directory for conversation historylogs/: Directory for log filesstate/: Directory for persisting bot stateask.txt: File for inputting queries to the botanswer.txt: File where the bot writes its responses
Contributions to MetaBot are welcome! Here's how you can contribute:
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin feature-name - Submit a pull request
Please make sure to update tests as appropriate and follow the code style of the project.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.