Skip to content

Latest commit

 

History

History
62 lines (47 loc) · 1.02 KB

zhipuai.md

File metadata and controls

62 lines (47 loc) · 1.02 KB

智谱AI

通过环境变量设置API KEY

import os 
os.environ["ZHIPU_API_KEY"] = "your-zhipu-api-key"

非流式调用

from unionllm import unionchat

# model call
response = unionchat(
    provider="zhipuai",
    model="glm-4", 
    messages = [{ "content": "Hello, how are you?","role": "user"}],
    stream=False
)

print(response)

流式调用

from unionllm import unionchat

# model call
response = unionchat(
    provider="zhipuai",
    model="glm-4", 
    messages = [{ "content": "Hello, how are you?","role": "user"}],
    stream=True
)

for chunk in response:
    print(chunk)

直接传入API_Key调用

# model call
response = unionchat(
    provider="zhipuai",
    model="glm-4", 
    api_key="your-zhipu-api-key",
    messages = [{ "content": "Hello, how are you?","role": "user"}]
)

支持模型

支持天工的所有文本模型

参考文档: