Metadata-Version: 2.4
Name: chatbot-oai
Version: 0.0.1
Summary: An out-of-the-box chat module supporting custom tool registration and invocation via OpenAI SDK
Project-URL: Homepage, https://github.com/axwhizee/chatbot-oai
Project-URL: Issues, https://github.com/axwhizee/chatbot-oai/issues
Author-email: OwlCat <richardcoles@qq.com>
License-Expression: MIT
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Requires-Dist: openai>=1.0
Description-Content-Type: text/markdown

# 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](https://github.com/openai/openai-python).

## 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

```bash
pip install chatbot-oai
```

## Quick Start

```python
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:

```python
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:

```bash
export OPENROUTER_API_KEY="your-api-key"
```

### Custom Tools

```python
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)
```
