Skip to main content

AILink

AILink is a library that mainly connects to the use of domestic large models, which is encapsulated and implemented based on compatible OpenAI interfaces. Through the AILink library, users only need to configure a {PROVIDER}_API_KEY to quickly connect and use domestic large models, which is quite convenient.

The Supported Providers

their corresponding large models include:

  • 阿里云[aliyun], supporting Tongyi Qianwenllm
  • 百度[baidu], supporting ernie series llm
  • 腾讯[tencent], supporting hunyuan llm
  • 智谱[zhipu], supporting Zhipu llm
  • 科大讯飞[xfyun], supporting Spark llm
  • 百川智能[baichuan], supporting BaiChuan llm
  • 字节跳动[bytedance], supporting Doubao llm
  • 商汤[sensetime], supporting SenseChat llm
  • 月之暗面[moonshot], supporting Moonshot llm

For the model list corresponding to the provider, refer to the article OpenAI库牵手国产大模型,一键解锁!超全参数配置秘籍来袭

Install

The minimum required version of Python is >=3.10.

The installation command is as follows:

pip install AILink

Usage

AILink will retain the same interface as OpenAI, and is fully compatible with OpenAI's usage, except for the instantiation of objects.

Before executing the code, you need to set up environment variables, for example:

export BAICHUAN_API_KEY=sk-?

The environment variables for other providers are set in a similar pattern, following the {PROVIDER}_API_KEY format. Here, PROVIDER should be replaced with the name of the provider as listed in "The Supported Providers," using all uppercase letters.

For example, the following case:

# - 阿里云[aliyun]
export ALIYUN_API_KEY=sk-?
# AILink(model="aliyun:qwen-plus")

# - 百度[baidu]
export BAIDU_API_KEY=sk-?
# AILink(model="baidu:ernie-4.0-8k-latest")

#  - 智谱[zhipu]
export ZHIPU_API_KEY=sk-?
# AILink(model="zhipu:GLM-4-Plus")

#  - 字节跳动[bytedance]
export BYTEDANCE_API_KEY=sk-?
# AILink(model="bytedance:Doubao-lite-4k")
  1. Standard usage
from ailink import AILink

client = AILink(model="baichuan:Baichuan4-Turbo")
# 创建聊天请求
response = client.chat.completions.create(
    stream=True,
    messages=[{'role': 'user', 'content': '今天是星期几'}] # 用户输入的信息
)

for chunk in response:
    print(chunk.choices[0].delta.content, end="", flush=True)
  1. Another usage is to specify the api_key and base_url parameters in the code, which is generally used when working with providers that are not provided by the AILink library.
from ailink import AILink

client = AILink(api_key='sk-?', base_url='https://api.baichuan-ai.com/v1')
# 创建聊天请求
response = client.chat.completions.create(
    stream=True,
    messages=[{'role': 'user', 'content': '今天是星期几'}] # 用户输入的信息
)

for chunk in response:
    print(chunk.choices[0].delta.content, end="", flush=True)
  1. When connecting to specific providers and if you do not want to set up the environment, you can specify the key directly in the code. This scenario is typically seen during the debugging and testing phase of the code.
from ailink import AILink

client = AILink(model="baichuan:Baichuan4-Turbo", api_key='sk-?')
# 创建聊天请求
response = client.chat.completions.create(
    stream=True,
    messages=[{'role': 'user', 'content': '今天是星期几'}] # 用户输入的信息
)

for chunk in response:
    print(chunk.choices[0].delta.content, end="", flush=True)

Release files for AILink 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for AILink 0.0.7
File Size Uploaded
AILink-0.0.7.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for AILink 0.0.7
File Interpreter ABI Platform
AILink-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 11.1 kB

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page