An out-of-the-box chat module supporting custom tool registration and invocation via OpenAI SDK
Project description
chatbot-oai
An out-of-the-box chat module for OpenAI-compatible APIs, supporting custom tool registration and invocation. Based on the OpenAI Python SDK.
Features
- Easy-to-use chat interface with OpenAI-compatible APIs
- Custom tool registration and automatic tool call handling
- Token usage tracking
- Flexible configuration via
BotConfig
Installation
pip install chatbot-oai
Quick Start
from chatbot_oai import BotConfig, ChatBot
bot = ChatBot(BotConfig())
response = bot.chat("Hello! Introduce yourself.")
print(response)
Configuration
Custom API endpoints with openrouter as an example:
from chatbot_oai import BotConfig
# OpenRouter
bot_conf = BotConfig(
base_url="https://openrouter.ai/api/v1",
env_key_name="OPENROUTER_API_KEY",
model="qwen3.5-flash",
temperature=0.7,
extra_body={"reasoning": {"enabled": False}},
)
Set your API key via environment variable:
export OPENROUTER_API_KEY="your-api-key"
Custom Tools
def get_weather(city: str) -> str:
return f"The weather in {city} is sunny."
tool_schema = {
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"}
},
"required": ["city"],
},
},
}
bot.tool_register(tool_schema, "get_weather", get_weather)
response = bot.chat("What's the weather in Beijing?")
print(response)
Project details
Release history Release notifications | RSS feed
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 chatbot_oai-0.0.1.tar.gz.
File metadata
- Download URL: chatbot_oai-0.0.1.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31b19d5426c6c29db9a606a6b8afcf15b2b04d180218169cdc338e370a6526db
|
|
| MD5 |
0dc228809cb97d16cc9d5b213126e36b
|
|
| BLAKE2b-256 |
00b68e02b1dc36234c46d4aad3259c785bb7023bb357278a2b57b5f3b9aafbad
|
File details
Details for the file chatbot_oai-0.0.1-py3-none-any.whl.
File metadata
- Download URL: chatbot_oai-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4be647f6d7d775d5659a96468d7a72ae5d1d5ec77c5e2421915ddcd6c8aed84
|
|
| MD5 |
3b89ea67f395347955279bacd02a3655
|
|
| BLAKE2b-256 |
91f473e90f83a6bce5c89adcd75c4420179c2241aa966c83da989b02cefb3681
|