智谱大模型开放接口SDK
智谱开放平台大模型接口 Python SDK(Big Model API SDK in Python),让开发者更便捷的调用智谱开放API
简介
- 对所有接口进行了类型封装。
- 初始化client并调用成员函数,无需关注http调用过程的各种细节,所见即所得。
- 默认缓存token。
安装
-
运行环境: Python>=3.7
-
使用 pip 安装
zhipuai软件包及其依赖
pip install zhipuai
使用
- 调用流程:
- 使用 APISecretKey 创建 Client
- 调用 Client 对应的成员方法
- 开放平台接口文档以及使用指南中有更多的 demo 示例,请在 demo 中使用自己的 ApiKey 进行测试。
创建Client
from zhipuai import ZhipuAI
client = ZhipuAI(
api_key="", # 填写您的 APIKey
)
同步调用
from zhipuai import ZhipuAI
client = ZhipuAI(api_key="") # 填写您自己的APIKey
response = client.chat.completions.create(
model="", # 填写需要调用的模型名称
messages=[
{"role": "user", "content": "你好"},
{"role": "assistant", "content": "我是人工智能助手"},
{"role": "user", "content": "你叫什么名字"},
{"role": "assistant", "content": "我叫chatGLM"},
{"role": "user", "content": "你都可以做些什么事"}
],
)
print(response.choices[0].message)
SSE 调用
from zhipuai import ZhipuAI
client = ZhipuAI(api_key="") # 请填写您自己的APIKey
response = client.chat.completions.create(
model="", # 填写需要调用的模型名称
messages=[
{"role": "system", "content": "你是一个人工智能助手,你叫叫chatGLM"},
{"role": "user", "content": "你好!你叫什么名字"},
],
stream=True,
)
for chunk in response:
print(chunk.choices[0].delta)
Release files for zhipuai 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zhipuai-2.0.1.tar.gz | 16.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zhipuai-2.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 43.1 kB
Release files / zhipuai-2.0.1.tar.gz
| Download URL | zhipuai-2.0.1.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
297bbdbe9393da2d1dc8066c39cf39bb2342f170d86f2b7b7a13ba368c53d701
|
|
BLAKE2b-256 checksum How to use checksums |
a490299e3456ee7ee1e118593552e03b86da2e9adaa0d454e467aeb4b22032a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|
Release files / zhipuai-2.0.1-py3-none-any.whl
| Download URL | zhipuai-2.0.1-py3-none-any.whl |
|---|---|
| Size | 26.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
738033d95696c3d5117dc4487e37d924e3ebbcdfa0072812b3f63a08ff72274a
|
|
BLAKE2b-256 checksum How to use checksums |
8f05c3d4556886b5c6cf8c0b96eb80448ee8154c0dcc87086df018e817779ed4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.9
|