Toolkit for building AI-powered applications with OpenAI and other AI services
Project description
๐ AI Tools Core: Toolkit for Building AI-Powered Applications
A comprehensive toolkit for developers building applications with AI services like OpenAI. This package provides core functionality for tool registration, conversation management, and AI service integration to accelerate your AI development workflow.
โจ Key Features
- ๐ง Tool Registry System: Register, validate, and execute AI tools with a unified interface
- ๐ง AI Service Integration: Connect with OpenAI and other AI services with proper error handling
- ๐ Conversation History Management: Track and analyze AI interactions with proper tool call handling
- ๐ Comprehensive Logging: Monitor tool execution with detailed, non-duplicative logs
- ๐ Hot Reload Development: Rapid iteration with auto-reloading development server
- ๐ค Example Telegram Bot: Reference implementation showing how to use the toolkit in a real application
๐ฆ Package Structure
The project is organized as a proper Python package for easy installation and reuse:
ai_tools_core/ # Core package
โโโ __init__.py # Public API exports
โโโ tools.py # Tool registry implementation
โโโ logger.py # Logging utilities
โโโ cli/ # Command-line interface
โโโ history/ # Conversation history management
โโโ services/ # AI service integrations
โโโ utils/ # Utility functions
Installation
From PyPI (Recommended)
Once published, you can install the package directly from PyPI:
# Basic installation
pip install ai-tools-core
# With development dependencies
pip install ai-tools-core[dev]
# With Telegram bot integration
pip install ai-tools-core[telegram]
From Repository
You can also install the package directly from the repository:
pip install -e .
Or with extra dependencies:
# For development
pip install -e ".[dev]"
# For Telegram bot integration
pip install -e ".[telegram]"
๐ ๏ธ Why Use This Toolkit?
Developing with AI services and tools can be challenging. This toolkit provides:
- Modular Components: Use only the parts you need for your specific application
- Best Practices: Implement AI tools following industry best practices
- Conversation Management: Properly handle tool calls in multi-turn conversations
- Extensibility: Easily extend the toolkit with your own tools and integrations
- Production-Ready: Build applications that are ready for production use
๐ฆ Getting Started
Prerequisites
- Python 3.8+
- Telegram Bot Token (from @BotFather)
- OpenAI API Key
Basic Usage
After installation, you can import and use the package in your Python code:
# Import core components
from ai_tools_core import ToolRegistry, get_logger
from ai_tools_core.services import get_openai_service
from ai_tools_core.history import get_history_manager, MessageRole
# Create a tool registry
registry = ToolRegistry()
# Register a tool
@registry.register()
def hello_world(name: str) -> str:
"""Say hello to someone."""
return f"Hello, {name}!"
# Use the OpenAI service
openai_service = get_openai_service()
response = openai_service.generate_response([
{"role": "user", "content": "Tell me a joke"}
])
print(response)
Setup
-
Clone the repository:
git clone https://github.com/yourusername/ai-tools-playground.git cd ai-tools-playground
-
Create a virtual environment:
python -m venv .venv
-
Activate the virtual environment:
- Windows:
.venv\Scripts\activate - macOS/Linux:
source .venv/bin/activate
- Windows:
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile with your configuration:OPENAI_API_KEY=your_openai_api_key TELEGRAM_BOT_TOKEN=your_telegram_bot_token LOG_LEVEL=INFO
-
Run the application:
python src/main.py
๐ฎ How to Use This Toolkit
This toolkit is designed to be modular and flexible. Here are some ways to use it:
1. Creating and Registering Tools
from ai_tools_core import ToolRegistry, log_tool_execution
# Create a tool registry
registry = ToolRegistry()
# Register a tool with the decorator pattern
@registry.register()
def get_weather(location: str) -> str:
"""Get weather information for a location."""
# In a real implementation, you would call a weather API
return f"Weather for {location}: Sunny, 75ยฐF"
# Execute a tool
result = registry.execute_tool("get_weather", location="New York")
print(result) # Output: Weather for New York: Sunny, 75ยฐF
# Get OpenAI-compatible tool schemas
schemas = registry.get_openai_schemas()
2. Managing Conversation History
The toolkit includes a conversation history manager that properly handles tool calls:
from ai_tools_core.history import get_history_manager, MessageRole
# Get the history manager
history_manager = get_history_manager()
# Create a new conversation
user_id = "user123"
conversation_id = history_manager.create_conversation(user_id)
# Add messages to the conversation
history_manager.add_message(conversation_id, MessageRole.SYSTEM,
"You are a helpful assistant.")
history_manager.add_message(conversation_id, MessageRole.USER,
"What's the weather in New York?")
# Format messages for OpenAI
from ai_tools_core.history import create_message_formatter
formatter = create_message_formatter("openai")
openai_messages = formatter.format_messages(conversation)
3. Integrating with AI Services
from ai_tools_core.services import get_openai_service, get_tool_service
# Get the OpenAI service
openai_service = get_openai_service()
# Generate a response
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me a joke about programming."}
]
response = openai_service.generate_response(messages)
print(response)
# Process messages with tools
tool_service = get_tool_service()
tools = registry.get_openai_schemas()
response = tool_service.process_with_tools(messages, tools)
4. Example: Building a Telegram Bot
The toolkit includes a reference implementation of a Telegram bot that demonstrates how to use all the components together:
from ai_tools_core import ToolRegistry
from ai_tools_core.services import get_openai_service
from bot.telegram_bot import create_bot
# Create your tools
registry = ToolRegistry()
@registry.register()
def hello_world(name: str) -> str:
return f"Hello, {name}!"
# Create the bot with your tools
bot = create_bot(registry)
bot.run()
๐ป Development Mode
For faster development iterations:
python dev.py
This starts the server with hot-reload capability, automatically restarting when you make changes to the code.
๐ Project Structure
ai-tools-core/
โโโ .env # Environment variables (not in repo)
โโโ .env.example # Example environment variables
โโโ README.md # Project documentation
โโโ progress.md # Project progress tracking
โโโ pyproject.toml # Package configuration
โโโ setup.py # Package setup script
โโโ src/
โโโ ai_tools_core/ # Core package
โ โโโ __init__.py # Package exports
โ โโโ tools.py # Tool registry implementation
โ โโโ logger.py # Logging utilities
โ โโโ cli/ # Command-line interface
โ โโโ history/ # Conversation history management
โ โโโ services/ # AI service integrations
โ โโโ utils/ # Utility functions
โโโ bot/ # Example Telegram bot
โ โโโ telegram_bot.py # Bot implementation
โ โโโ handlers.py # Message handlers
โโโ main.py # Example application entry point
๐ Learn More
โ Troubleshooting
Common Issues
ImportError: No module named 'ai_tools_core'
Make sure the package is properly installed. Try reinstalling with:
pip uninstall ai-tools-core
pip install ai-tools-core
OpenAI API Key Issues
If you encounter errors related to the OpenAI API key:
- Check that your API key is correctly set in the
.envfile - Verify that your API key has sufficient credits
- Ensure you're using the correct environment variable name:
OPENAI_API_KEY
Tool Execution Errors
If tools are failing to execute:
- Check the logs for detailed error messages
- Verify that tool parameters match the expected types
- Ensure the tool is properly registered in the registry
Module Not Found When Using Entry Points
If you encounter issues with the ai-tools command:
- Make sure the package is installed in the active Python environment
- Try reinstalling with
pip install -e .from the repository root - Verify that your PATH includes the Python scripts directory
๐ License
MIT
โญ If you find this project helpful, please star it on GitHub! โญ
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_tools_core-0.1.0.tar.gz.
File metadata
- Download URL: ai_tools_core-0.1.0.tar.gz
- Upload date:
- Size: 33.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
396cb280fc4103c42c092d7bb6c4b40852becf52682e86a7969672e5a29c4fc3
|
|
| MD5 |
dea07e08bfe5495e456e74e3fdc5afbc
|
|
| BLAKE2b-256 |
e9932afd1b519d88dc53e64f33c42525a305f8fd04b1b7ad7b1733859f4deac9
|
File details
Details for the file ai_tools_core-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_tools_core-0.1.0-py3-none-any.whl
- Upload date:
- Size: 39.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30f2f5dee37fe07ed5c72cf83f405fe9368d2b1f9c1a4a6a0480adc57888f03c
|
|
| MD5 |
7f0f813465224bc77a00492620f5ad04
|
|
| BLAKE2b-256 |
82b7e2c973d682eeba7cedb1ab21d6a2741ca88d63e55c3704f39b87e7c65f27
|