f51190e3ce740d7a99f9c990182c805f2a4210b6
Telegram Inference Bot Refactoring
This repository contains a refactored version of the Telegram Inference Bot, which now uses a more flexible and maintainable approach for handling different AI providers.
Changes
- Introduced an abstract
AIProviderclass and concrete implementations for Anthropic and OpenAI. - Refactored the main bot code to use the new AI provider classes.
- Implemented a factory function
create_ai_providerfor easy provider instantiation. - Updated command handlers to work with the new AI provider system.
How to Use
-
Set up your environment variables in a
.envfile:TELEGRAM_BOT_TOKEN=your_telegram_bot_token ANTHROPIC_API_KEY=your_anthropic_api_key OPENAI_API_KEY=your_openai_api_key -
Install the required dependencies:
pip install -r requirements.txt -
Run the bot:
python telegram_inference_bot.py
Commands
/start: Start the bot and receive a welcome message./clear: Clear the conversation history and any stored images./switch: Switch between smart and regular models (OpenAI only)./toggle: Toggle between Anthropic and OpenAI providers./status: Display the current AI provider and model being used.
Extending the Bot
To add a new AI provider:
- Create a new class in
ai_providers.pythat inherits fromAIProvider. - Implement the required methods:
get_chat_response,format_messages,format_tool_calls, etc. - Update the
create_ai_providerfunction to include the new provider.
Future Improvements
- Implement more robust error handling and logging.
- Add unit tests for the AI provider classes and main bot functionality.
- Extend the README with more detailed usage instructions and examples.
Description
Languages
Python
100%