Metadata-Version: 2.4
Name: chatrelay
Version: 0.1.0
Summary: Chatbot library that calls Groq and Gemini with multi-key automatic failover.
Author-email: Prince Prajapati <prajapatiprince982@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/kingprince35/chatbot_library
Keywords: groq,gemini,llm,chatbot,failover
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28
Provides-Extra: cli
Requires-Dist: python-dotenv; extra == "cli"
Provides-Extra: api
Requires-Dist: fastapi; extra == "api"
Requires-Dist: uvicorn; extra == "api"
Requires-Dist: python-dotenv; extra == "api"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: build; extra == "dev"
Requires-Dist: twine; extra == "dev"
Dynamic: license-file

# chatrelay

Chatbot library for **Groq** and **Gemini**. Give it multiple API keys; when one hits its
rate limit it automatically switches to the next.

## Install
```bash
pip install chatrelay
```

## Setup
Set environment variables (comma-separated keys):
```bash
export GROQ_API_KEYS="groq_key_1,groq_key_2"
export GEMINI_API_KEYS="gemini_key_1,gemini_key_2"
```

## Use in code
```python
from chatrelay import Chatbot, build_providers

bot = Chatbot(build_providers(), system_prompt="You are a helpful assistant.")
result = bot.ask("What is Python?")
print(result["provider"], result["reply"])   # e.g. groq-1 ...

bot.ask("Explain more")                      # remembers the conversation
bot.ask("Hi", provider="gemini")             # prefer a provider ("gemini") or one key ("groq-2")
bot.reset()                                  # clear history
```

## Terminal chat
```bash
pip install "chatrelay[cli]"
chatrelay
```

## How failover works
Order: groq-1 -> groq-2 -> gemini-1 -> gemini-2. A key that returns HTTP 429 is skipped
for 60s (or the `Retry-After` time). If all keys fail, `LLMError` is raised.

## REST API example
See `examples/fastapi_app.py` (`pip install "chatrelay[api]"`).
