Skip to main content

Uniform access layer for LLMs of China

Project description

aisuite4cn

PyPI

简单、统一的接口,可连接多个生成式人工智能提供商。

aisuite4cn 针对于中国的各类大模型厂商提供通用的支持。学习了aisuite方案,并开发了该库。

aisuite4cn 使得开发者能够通过标准化的接口轻松使用多个大型语言模型(LLM)。使用类似于OpenAI的接口,aisuite4cn 使得与最受欢迎的LLM互动并比较结果变得简单。它是Python客户端库的轻量级包装器,允许创造者在不改变代码的情况下无缝切换并测试来自不同LLM提供商的响应。我们将在不久的将来扩展它以覆盖更多的用例。

当前支持的提供商包括: Moonshot(月之暗面)、 Doubao(火山引擎方舟大模型服务平台)、 Qwen(阿里云千问大模型)、 Hunyuan(腾讯混元大模型)、 Ernie(百度文心一言)、 ZhipuAI(BigModel智谱AI大模型开放平台)

安装

你可以只安装基础的 aisuite4cn 包,这只会安装基础包,而不会安装任何提供商的SDK。 或者同时安装某个提供商的包和 aisuite4cn包。

请注意,在 create() 调用中的模型名称使用格式为 <provider>:<model-name>aisuite4cn 将根据提供商值调用相应的提供商并传递正确的参数。 提供商的列表可以在目录 aisuite4cn/providers/ 中找到。 支持的提供商的格式为该目录下的 <provider>_provider.py

pip install aisuite4cn

安装通义千问大模型供应商的包

pip install 'aisuite4cn[qwen]'

安装所有大模型供应商的包

pip install 'aisuite4cn[all]'

配置

你需要为你打算使用的提供商获取 API 密钥。你需要单独安装或在安装 aisuite4cn 时安装特定提供商的库。 API 密钥可以设置为环境变量,也可以作为配置传递给 aisuite4cn 客户端构造函数。你可以使用工具如 python-dotenvdirenv 来手动设置环境变量。 以下是一个简短的示例,展示如何使用 aisuite4cn 从 qwen 和 moonshot 生成聊天完成响应。

设置API keys.

export MOONSHOT_API_KEY="your-moonshot-api-key" # 月之暗面开放平台api-key,支持moonshot
export DASHSCOPE_API_KEY="your-dashscope-api-key" # 百炼平台api-key,支持qwen
export ARK_API_KEY = "your-ark-api-key" #火山引擎api-key,支持doubao
export ARK_MODEL_MAP = "modlename1=endpointID&modlename2=endpointID" #火山引擎model map
export HUNYUAN_API_KEY = "your-hunyuan-api-key" #腾讯混元api-key,支持混元
export ZHIPUAI_API_KEY = "your-zhipuai-api-key" #智谱AI api-key,支持ChatGLM
export QIANFAN_ACCESS_KEY = "your-qianfan-access-key" #百度千帆 access key,支持文心一言
export QIANFAN_SECRET_KEY = "your-qianfan-secret-key" #百度千帆 secret key,支持文心一言
export DEEPSEEK_API_KEY="your-deepseek-api-key" # deepseek开放平台api-key,支持deepseek
export SPARK_API_KEY_MAP = "modlename1=your-modelname1-api-key&modlename2=your-modelname1-api-key"

使用python客户端

import aisuite4cn as ai
client = ai.Client()

models = [
    "spark:4.0Ultra",
    "spark:generalv3",
    "ark:Doubao-pro-32k",
    "qwen:qwen-max",
    "moonshot:moonshot-v1-8k",
    "hunyuan:hunyuan-standard",
    "qianfan:ernie-3.5-8k",
    "zhipuai:glm-4-flash",
    "deepseek:deepseek-chat"
]

messages = [
    {"role": "system", "content": "Respond in Pirate English."},
    {"role": "user", "content": "Tell me a joke."},
]

for model in models:
    response = client.chat.completions.create(
        model=model,
        messages=messages,
        temperature=0.75
    )
    print(response.choices[0].message.content)

License

aisuite4cn 在 MIT 许可证下发布。您可以自由地将代码用于商业和非商业目的。

Integrated Open source project

Special thanks to all contributors

aisuite

https://github.com/andrewyng/aisuite

openai-python

https://github.com/openai/openai-python

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

aisuite4cn-1.0.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

aisuite4cn-1.0.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file aisuite4cn-1.0.0.tar.gz.

File metadata

  • Download URL: aisuite4cn-1.0.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.9.22 Darwin/24.3.0

File hashes

Hashes for aisuite4cn-1.0.0.tar.gz
Algorithm Hash digest
SHA256 abe83762319de64537c2e2c380b32a10fb4b647e6e6230d37ce5115763a169e5
MD5 15cd7622327005e3b5c3f9a04cde0c3c
BLAKE2b-256 079a76821c11bdda26fa1823ba368c46e6707a2866c16f8bc6fef884f2976575

See more details on using hashes here.

File details

Details for the file aisuite4cn-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: aisuite4cn-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.9.22 Darwin/24.3.0

File hashes

Hashes for aisuite4cn-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b1f2ced8a8776e5c3410848e28d9f4fbe0a24bf28e02ebf9a5be18c960f3215
MD5 649790212a2c650be8f1a7123e7baae5
BLAKE2b-256 021b448fe6dd3f678ffb48d6b05c9939c0351637bcadac18145f2bbb6c3621a0

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