A lightweight, reusable concurrency-friendly client facade for OpenAI-compatible chat APIs
Project description
concurrency-client
一个针对 OpenAI 兼容 Chat API 的轻量抽象与聚合门面,支持异步、密钥池与批量并发控制。
安装(本地打包后)
pip install .
# 或构建分发包:
python -m build
pip install dist/concurrency_client-0.1.0-py3-none-any.whl
快速开始
import asyncio
from concurrency_client import ChatClient, Platform
async def main():
# 使用内置平台(示例:chatapi)
client = ChatClient(platform="chatapi", model="gpt-4")
text, usage = await client.call_text("你好,简单自我介绍一下")
print(text, usage)
await client.aclose()
# 使用自定义平台
custom = Platform.create_client_custom(
api_url="https://api.chataiapi.com/v1",
api_key_file="./api_key_txt/chatapi.txt",
model="gpt-4",
strategy="round_robin",
)
text, usage = await custom.call(messages=[{"role": "user", "content": "说一句中文你好"}], stream=False)
print(text, usage)
await custom.aclose()
asyncio.run(main())
主要特性
- 统一门面:
ChatClient.call_text/call_json/call_with_single_image/call_with_multi_images/call_batch - 批量并发:
call_batch(max_concurrency, per_item_retries, backoff_*) - 密钥池:
ApiKeyPool(strategy=random|round_robin) - 自定义平台:
Platform.create_client_custom(api_url, api_key_file, model)
目录结构
concurrency_client/
concurrency_client/
__init__.py
api_pool.py
universal_api_client.py
platform.py
chat_client.py
api_key_txt/
chatapi.txt # 本地密钥,勿提交
demo_test.py # 本地演示脚本,勿打包
pyproject.toml
README.md
LICENSE
注意
- 不要将
api_key_txt/提交到版本库或打包到发布物。 - 示例依赖 OpenAI 兼容接口(如 ChatAPI)。不同平台的字段可能略有差异,建议优先使用
ChatClient与 OpenAI 风格消息体。
许可证
MIT
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 concurrency_client-0.1.0.tar.gz.
File metadata
- Download URL: concurrency_client-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40ce2b11175d0093d453d01882627b725fc567770b44c55b05cefcc1a7bddb1b
|
|
| MD5 |
51a70e131382aea2cd87613396190de9
|
|
| BLAKE2b-256 |
e7d1895a3612d5802b68d85441a8d040f94b2c4302b36bf5c7258bc882958e79
|
File details
Details for the file concurrency_client-0.1.0-py3-none-any.whl.
File metadata
- Download URL: concurrency_client-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de0048b0f9136b911532e2c3979a096e98589e7f02e7dd7439d8094253924f75
|
|
| MD5 |
dd819d89c09d2eb6989ecb1767e47930
|
|
| BLAKE2b-256 |
0b2a8c23b998390d8a85aa1ec2df14c87d1607be0bbc5fceb7f301cd6370997b
|