Skip to main content

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


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.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

concurrency_client-0.1.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file concurrency_client-0.1.1.tar.gz.

File metadata

  • Download URL: concurrency_client-0.1.1.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for concurrency_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b732601fe49e5cdc55d4bb98b6891e5b90b6ff05d79ecb3e582de9918e941cb0
MD5 e5c2ea84720780c7f64533a7c829428a
BLAKE2b-256 0ca38e4fec98208d75f612645532d3116346849560bbcd5bfcdd5cd5bc6172b4

See more details on using hashes here.

File details

Details for the file concurrency_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for concurrency_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52e24d1470923325ad925160f24921d45b6fd93597abbf44022b7c2dcac1cb75
MD5 ffc029024ad4e1eb9e29c6504e1ad9ec
BLAKE2b-256 9f9e798115e7a31ea88ad197f216040125934a98174e31f4b6ce7e500c7e89d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page