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")
- 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)
- 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)
- 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)
| File | Size | Uploaded | |
|---|---|---|---|
| AILink-0.0.7.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| AILink-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.1 kB
Release files / AILink-0.0.7.tar.gz
| Download URL | AILink-0.0.7.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7b7ef0f5667c54e6c37a03f4e8261b3a9822f3b7e522786a9c5a25abc8d407d5
|
|
BLAKE2b-256 checksum How to use checksums |
7732d6a3fc9885b4719b0f28ba8bfb6266a456708b3b437c2c8428e3013bf54d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.13
|
Release files / AILink-0.0.7-py3-none-any.whl
| Download URL | AILink-0.0.7-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4689428c2d8c60cd06d09e92f991e0907aea56884e69550cd4ecfb862d471e81
|
|
BLAKE2b-256 checksum How to use checksums |
f2fe452ea907bfbc34e2faaa8fc42e2388b56ca61412d86a46681c07b9fe8a91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.13
|