深色模式
预置语言大模型服务接口说明
接口地址:https://platform.wair.ac.cn/maas/v1/chat/completions
请求方式:post 请求
语言大模型 Taichu-LLM
请求说明
Header 参数说明
字段 | 类型 | 必选 | 描述 | 示例值 |
Content-Type | string | 是 | 请求类型 | application/json |
Authorization | string | 是 | API Key,格式为 Bearer $API_KEY | Bearer ayvs***vufp |
Body 参数说明
参数名称 | 类型 | 是否必填 | 参数说明 |
model | string | 是 | 所要调用的模型编码,模型可选模型 taichu_llm |
messages | list | 是 | 一个由历史消息组成的列表,详细说明,参照 messages 信息说明 |
stream | bool | 否 | 使用同步调用时,此参数应当设置为 false。表示模型生成完所有内容后一次性返回所有内容。如果设置为 true,模型将通过标准 Event Stream ,逐块返回模型生成内容。Event Stream 结束时会返回一条 data: [DONE]消息。默认值为 true |
temperature | float | 否 | 生成过程中的温度值,取值范围[0.01,1.00] 闭区间,默认值为 0.8,调节最小细粒度为 0.01 |
top_p | float | 否 | 生成过程中的 token 几率阈值取值范围是:(0.0, 1.0) 开区间,默认值为 0.9,调节最小细粒度为 0.1 |
max_tokens | int | 否 | 模型输出最大 token 数,最大输出为 8192,默认值为 3000 |
messages 参数说明
参数名称 | 类型 | 是否必填 | 说明 |
role | string | 是 | system:系统,user:用户,assistant:模型,tool:工具调用 |
content | string | 是 | role 为 system 时为系统人设信息,role 为 user 时为用户输入信息,role 为 assistant 时为模型返回信息,role 为 tool 时为工具调用返回信息 |
curl 请求示例-模型服务
json
curl --location --request POST 'https://platform.wair.ac.cn/maas/v1/chat/completions' \
--header 'Authorization: Bearer $API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"messages": [
{
"content": "把文言文翻译成白话文“是故弟子不必不如师,师不必贤于弟子,闻道有先后,术业有专攻,如是而已。”",
"role": "user"
}
],
"temperature": 0.8,
"top_p": 0.9,
"repetition_penalty": 1,
"stream": false,
"max_tokens": 3000,
"model": "taichu_llm"
}'
python 调用示例
非流式调用
python
import requests
import requests
if __name__ == '__main__':
params = {
'model': 'taichu_llm',
'messages': [{"role": "user", "content": "你好"}],
'stream': False
}
api = 'https://platform.wair.ac.cn/maas/v1/chat/completions'
headers = {'Authorization': 'Bearer $API_KEY'}
response = requests.post(api, json=params, headers=headers)
if response.status_code == 200:
print(response.json())
else:
body = response.content.decode('utf-8')
print(f'request failed,status_code:{response.status_code},body:{body}')
流式调用
python
import requests
if __name__ == '__main__':
params = {
'model': 'taichu_llm',
'messages': [{"role": "user", "content": "你好"}],
'stream': True
}
api = 'https://platform.wair.ac.cn/maas/v1/chat/completions'
headers = {'Authorization': 'Bearer $API_KEY'}
response = requests.post(api, json=params, headers=headers, stream=True)
if response.status_code == 200:
response.encoding = 'utf-8'
for line in response.iter_lines(decode_unicode=True):
print(line)
else:
body = response.content.decode('utf-8')
print(f'request failed,status_code:{response.status_code},body:{body}')
返回说明
Body 参数说明
参数名称 | 类型 | 说明 |
id | string | 本次请求唯一标识 |
model | string | 本次使用的模型名称 |
choices | list | 本次请求模型服务返回的信息 |
+messages | object | 同步响应时,返回该字段,详细说明见 messages |
+index | object array | 当前可选路径序列号 |
+finish_reason | string | stop: 表示模型输出结束 length: 表示模型输出长度达到 max_tokens tool_calls: 表示模型命中函数 content_filter: 表示模型输出被安全审核拦截,针对此类内容,请用户自行判断并决定是否撤回已公开的内容。 |
usage | object | token 使用数量 |
+completion_tokens | int | 内容生成的 tokens 数量 |
+prompt_tokens | int | prompt 使用的 tokens 数量 |
+total_tokens | int | 总 tokens 用量 |
object | string | 生成的聊天响应 ID |
created | timestamp | 生成聊天响应时的 Unix 时间戳 |
messages 参数说明
参数名称 | 类型 | 是否必填 | 说明 |
role | string | 是 | system:系统,user:用户,assistant:模型,tool:工具调用 |
content | string | 是 | role 为 system 时为系统人设信息,role 为 user 时为用户输入信息,role 为 assistant 时为模型返回信息,role 为 tool 时为工具调用返回信息 |
返回示例
json
{
"id": "59492853-f336-4967-9691-f95e22181d78",
"object": "chat.completion",
"created": 2455355,
"model": "taichu_llm",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "因此学生不一定不如老师,老师也不一定比学生贤能,听到的道理有先有后,学问技艺各有专门研究,如此罢了。"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 110,
"total_tokens": 141,
"completion_tokens": 31
}
}