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.0.tar.gz (8.6 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.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

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

Hashes for concurrency_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 40ce2b11175d0093d453d01882627b725fc567770b44c55b05cefcc1a7bddb1b
MD5 51a70e131382aea2cd87613396190de9
BLAKE2b-256 e7d1895a3612d5802b68d85441a8d040f94b2c4302b36bf5c7258bc882958e79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for concurrency_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de0048b0f9136b911532e2c3979a096e98589e7f02e7dd7439d8094253924f75
MD5 dd819d89c09d2eb6989ecb1767e47930
BLAKE2b-256 0b2a8c23b998390d8a85aa1ec2df14c87d1607be0bbc5fceb7f301cd6370997b

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