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
concurrency_client-0.1.2.tar.gz
(10.7 kB
view details)
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.2.tar.gz.
File metadata
- Download URL: concurrency_client-0.1.2.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f992c01d83c9151d6615f013b3878f0fc7fd9565053209f4d3c6d5abe1429c87
|
|
| MD5 |
e9a1bbfb1ca3aced16aecb07105899c9
|
|
| BLAKE2b-256 |
4f99ba673833465311ad3cc7e51d371e303b8b21233f9e21becb923ead44d407
|
File details
Details for the file concurrency_client-0.1.2-py3-none-any.whl.
File metadata
- Download URL: concurrency_client-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.7 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 |
2938114e9b512d45eeb0230df18b0dfe5526b1ebf78afd5208d849f5b65ac779
|
|
| MD5 |
ae51b14a736a44dfa94999b584797fbc
|
|
| BLAKE2b-256 |
c26c1f8226b1e16fd762819db5891066cbf24447c37c4dd990dd4e8ac79e2801
|