接口信息
API Path
/aipaas/lm/v1/telechat/completions115
请求协议
HTTP
请求方法
POST
请求头部:
| 头部标签 | 必填 | 说明 | 类型 | 数据字典 | 限制 | 头部内容 | 示例 |
|---|---|---|---|---|---|---|---|
| Content-Type | 是 | application/json | [string] | - | - | - | - |
| X-APP-ID | 是 | 系统管理--API Key,创建应用获取AppID 和AppKey,公网鉴权,公网调用时必传 | [string] | - | - | - | - |
| Order-Num | 是 | 订单编号 | [string] | - | - | - | - |
| Authorization | 是 | 鉴权信息 | [string] | - | - | - | - |
请求参数 Json Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| messages | 对话内容 | 是 | [array] | - | - | - |
| messages>>content | 系统消息的内容string/array类型,例: “content”:”你好” “content”:[{“type”:”text”,”text”:”你好”}] | 是 | [object] | - | - | - |
| messages>>refusal | 助理的拒绝消息 | 否 | [string] | - | - | - |
| messages>>role | 消息作者的角色 | 是 | [string] | - | - | - |
| messages>>name | 参与者的可选名称 | 否 | [string] | - | - | - |
| messages>>toolcallid | 此消息正在响应的工具调用 | 否 | [string] | - | - | - |
| messages>>tool_calls | 模型生成的工具调用 | 否 | [array] | - | - | - |
| model | 要使用的模型的ID(当前为telechat-115b),最大长度为 64 | 是 | [string] | - | - | - |
| maxcompletiontokens | 最大生成词元数量。输入词元和生成词元的总长度受模型上下文长度的限制。兼容传入max_tokens,但不允许两个参数同时存在,范围在1到模型最大输出长度(例如:2000) | 是 | [int] | - | - | - |
| presence_penalty | 默认值为 0,在 -2.0 到 2.0 之间。正值会基于新生成词是否已经出现在当前文本中进行惩罚,增加模型谈论新主题的可能性。 | 否 | [number] | - | - | - |
| stream | 默认值为 false,如果设置true,回答内容讲使用流式传输 | 否 | [boolean] | - | - | - |
| stream_options | 流式响应的选项。仅当您设置stream: true时设置此项才生效。 "streamoptions":{"includeusage": true} 如果设置,则在data: [DONE]之前流式传输的一个块中usage此块上的字段显示整个请求的token使用情况统计信息,所有其他块也将包含一个usage字段,但值为空。 | 否 | [object] | - | - | - |
| tools | 模型可以调用的工具列表。 | 否 | [array] | - | - | - |
| tools>>type | 工具的类型。目前仅支持function | 是 | [string] | - | - | - |
| tools>>function | 模型调用的函数 | 是 | [object] | - | - | - |
| tools>>function>>description | 函数用途的描述,模型使用它来选择何时以及如何调用函数,最大长度2000 | 否 | [string] | - | - | - |
| tools>>function>>name | 要调用的函数的名称。必须是 a-z、A-Z、0-9 或包含下划线和短划线,最大长度为 64 | 是 | [string] | - | - | - |
| tools>>function>>parameters | 函数接受的参数,描述为 JSON Schema 对象。请参阅 指南 有关示例,请参阅 JSON 架构参考 有关格式的文档 | 否 | [object] | - | - | - |
| tools>>function>>strict | 是否在生成函数调用时启用严格的架构遵循。如果设置为 true,则模型将遵循字段中定义的确切架构。当 is 时,仅支持 JSON 架构的子集。在函数调用指南中了解有关结构化输出的更多信息 | 否 | [boolean] | - | - | - |
| tool_choice | 控制模型调用工具。 none表示模型不会调用任何工具,而是生成一条消息。 auto表示模型可以在生成消息或调用一个或多个工具之间进行选择 | 否 | [string] | - | - | - |
| temperature | 默认值为 0.3,使用的采样温度,范围 [0,2]。较高的值如 0.8 会使输出更随机,而较低的值如 0.2 会使输出更集中且具有确定性,取0时会关闭采样,无随机输出。 | 否 | [number] | - | - | - |
| top_p | 默认值为 1,取值范围为[0,1]之间,作为温度采样的替代方法,称为核采样,该方法中模型考虑具有 top_p 概率质量的词元结果 | 否 | [number] | - | - | - |
| extra_body | 额外参数 | 否 | [object] | - | - | - |
| extrabody>>topk | 作用:随机候选数(不建议修改) 取值:大于0的值越大,输出的多元性越大。 取值范围:(0,10000] | 否 | [int] | - | - | - |
| extrabody>>repetitionpenalty | 默认值为1.01,作用:生成重复惩罚(不建议修改) 取值范围:(0,2] | 否 | [double] | - | - | - |
| extrabody>>frequencypenalty | 默认值为0,基于它们在生成文本中的频率。值>0鼓励模型使用新令牌,而值<0鼓励模型重复令牌。 TODO:值阈 | 否 | [double] | - | - | - |
| traceId | 接口跟踪ID,每次调用需不同,可使用UUID, 用于日志排除、链路跟踪,最大长度为 64 | 否 | [string] | - | - | - |
| timestamp | 当前时间戳 | 否 | [long] | - | - | - |
| knowledgeBase | 知识库编码 | 是 | [string] | - | - | - |
响应内容:
返回结果
流式响应结果-成功 (200) Json Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| data | 表⽰流式返回的数据块,包含⽣成的⽂本内容,[DONE]表⽰⽣成过程已完成 | 是 | [object] | - | - | - |
| data>>id | 聊天补全的唯一标识符(uuid4)。 | 是 | [object] | - | - | - |
| data>>choices | 聊天补全选项的列表。 | 是 | [array] | - | - | - |
| data>>choices>>finish_reason | 模型停止生成标记的原因。原因可能是stop模型到达自然停止点或提供的停止序列、 length达到请求中指定的最大标记数。 | 是 | [string] | - | - | - |
| data>>choices>>index | 选择列表中的索引 | 是 | [int] | - | - | - |
| data>>choices>>delta | 模型响应流生成的聊天补全增量。 | 是 | [object] | - | - | - |
| data>>choices>>delta>>content | 块消息的内容。 | 是 | [string] | - | - | - |
| data>>choices>>delta>>role | 此消息作者的角色。【第一块携带、其他块不携带此参数】 | 是 | [string] | - | - | - |
| data>>choices>>delta>>refusal | 模型生成的拒绝消息 | 是 | [string] | - | - | - |
| data>>choices>>delta>>tool_calls | 工具列表 | 是 | [array] | - | - | - |
| data>>choices>>delta>>tool_calls>>index | 选择列表中的索引 | 是 | [int] | - | - | - |
| data>>choices>>delta>>tool_calls>>id | 工具调用的 ID | 是 | [string] | - | - | - |
| data>>choices>>delta>>tool_calls>>type | 工具的类型。目前仅支持 function | 是 | [string] | - | - | - |
| data>>choices>>delta>>tool_calls>>function | 模型调用的函数。 | 是 | [object] | - | - | - |
| data>>choices>>delta>>tool_calls>>function>>name | 要调用的函数的名称 | 是 | [string] | - | - | - |
| data>>choices>>delta>>tool_calls>>function>>arguments | 用于调用函数的参数,由模型以 JSON 格式生成。请注意,该模型并不总是生成有效的 JSON,并且可能会产生函数架构未定义的参数。在调用函数之前验证代码中的参数 | 是 | [string] | - | - | - |
| data>>choices>>logprobs | 输出标记的对数概率。 | 是 | [object] | - | - | - |
| data>>created | 时间戳 | 是 | [int] | - | - | - |
| data>>model | 用于生成补全的模型。 | 是 | [string] | - | - | - |
| data>>object | 对象类型,始终为 chat.completion.chunk。 | 是 | [string] | - | - | - |
| data>>usage | token统计【当stream_options生效时,最后一个块携带usage信息、其他块携带的是null,其他情况默认不携带】 | 是 | [object] | - | - | - |
| data>>usage>>completion_tokens | 生成tokens | 是 | [int] | - | - | - |
| data>>usage>>prompt_tokens | prompt的tokens | 是 | [int] | - | - | - |
| data>>usage>>total_tokens | 总tokens | 是 | [int] | - | - | - |
| data>>usage>>completiontokensdetails | 忽略,该算法未使用 | 是 | [object] | - | - | - |
| data>>usage>>completiontokensdetails>>reasoning_tokens | 忽略,该算法未使用 | 是 | [int] | - | - | - |
| data>>system_fingerprint | 代表模型运行时后端配置的指纹。可以与请求参数 seed 结合使用,以了解可能影响确定性的后端更改何时发生。【当前默认null】 | 是 | [string] | - | - | - |
非流式响应结果-成功 (200) Json Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| id | 聊天补全的唯一标识符(uuid4)。 | 是 | [string] | - | - | - |
| choices | 聊天补全选项的列表。 | 是 | [array] | - | - | - |
| choices>>finish_reason | 模型停止生成标记的原因。原因可能是stop模型到达自然停止点或提供的停止序列、 length达到请求中指定的最大标记数。 如果模型调用了工具,tool_calls。 | 是 | [string] | - | - | - |
| choices>>index | 选择列表中的索引 | 是 | [int] | - | - | - |
| choices>>message | 模型生成的聊天补全消息。 | 是 | [object] | - | - | - |
| choices>>message>>content | 消息的内容 | 是 | [string] | - | - | - |
| choices>>message>>refusal | 模型生成的拒绝消息。 | 是 | [string] | - | - | - |
| choices>>message>>tool_calls | 模型生成的工具调用,例如函数调用。 | 是 | [array] | - | - | - |
| choices>>message>>tool_calls>>id | 工具调用的 ID。 | 是 | [string] | - | - | - |
| choices>>message>>tool_calls>>type | 工具的类型。目前仅支持 function。 | 是 | [string] | - | - | - |
| choices>>message>>tool_calls>>function | 模型调用的函数。 | 是 | [object] | - | - | - |
| choices>>message>>tool_calls>>function>>name | 要调用的函数的名称。 | 是 | [string] | - | - | - |
| choices>>message>>tool_calls>>function>>arguments | 用于调用函数的参数,由模型以 JSON 格式生成。请注意,该模型并不总是生成有效的 JSON,并且可能会产生函数架构未定义的参数。在调用函数之前验证代码中的参数。 | 是 | [string] | - | - | - |
| choices>>message>>role | 此消息作者的角色。 | 是 | [string] | - | - | - |
| choices>>logprobs | 输出标记的对数概率。 | 是 | [object] | - | - | - |
| created | 时间戳 | 是 | [int] | - | - | - |
| model | 用于聊天补全的模型。 | 是 | [string] | - | - | - |
| object | 对象类型,始终为 chat.completion。 | 是 | [string] | - | - | chat.completion.chunk |
| usage | token统计 | 是 | [object] | - | - | - |
| usage>>completion_tokens | 生成tokens | 是 | [int] | - | - | - |
| usage>>prompt_tokens | prompt的tokens | 是 | [int] | - | - | - |
| usage>>total_tokens | 总tokens | 是 | [int] | - | - | - |
| usage>>completiontokensdetails | 忽略,该算法未使用 | 是 | [object] | - | - | - |
| usage>>completiontokensdetails>>reasoning_tokens | 忽略,该算法未使用 | 是 | [int] | - | - | - |
| system_fingerprint | 代表模型运行时后端配置的指纹。可以与请求参数 seed 结合使用,以了解可能影响确定性的后端更改何时发生。【当前默认null】 | 是 | [string] | - | - | - |
功能介绍
TeleChat对话115B版本。
服务鉴权
服务接口调用时需要严格遵循服务鉴权规则,服务调用鉴权规则请参见:开发指南 - 接口签名认证。
状态码说明
通用状态码请参考【状态码】中的【网关认证】
{
"code": "10010003",
"message": "签名已过期"
}请求参数示例
流式请求示例
{
"model": "telechat-115b",
"messages": [{
"role": "user",
"content": "你是什么模型,能处理什么问题"
}],
"max_completion_tokens": 150,
"stream": true
}流式响应示例
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": "",
"role": "assistant",
"refusal": null
},
"logprobs": null
}],
"created": 1729666765,
"system_fingerprint": null,
"model": "telechat-115b",
"object": "chat.completion.chunk"
}
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": "你好"
},
"logprobs": null
}],
"created": 1729666765,
"model": "telechat-115b",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
........中间省略消息块
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": "?"
},
"logprobs": null
}],
"created": 1729666765,
"model": "telechat-115b",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": ""
},
"logprobs": null
}],
"created": 1729666765,
"model": "telechat-115b",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": "stop",
"index": 0,
"delta": {},
"logprobs": null
}],
"created": 1729666765,
"model": "telechat-115b",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
data: {
"id": "c86aff51e90442ed8c7e1ab5296189a8",
"choices": [],
"created": 1729666822,
"model": "telechat-115b",
"system_fingerprint": null,
"object": "chat.completion.chunk",
"usage": {
"completion_tokens": 40,
"prompt_tokens": 23,
"total_tokens": 63,
"completion_tokens_details": {
"reasoning_tokens": 0
}
}
}
此消息块在stream_option生效时产生
data: [DONE]非流式请求示例
{
"model": "telechat-115b",
"messages": [{
"role": "user",
"content": "你是什么模型,能处理什么问题"
}],
"max_completion_tokens": 150,
"stream": false
}非流式响应示例
{
"id": "chat-fb53de120a09438babb58fe3d8aba2e7",
"object": "chat.completion",
"created": 1730964205,
"model": "opencompass",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "Of course! How can I assist?"
},
"tool_calls": [],
"logprobs": null,
"finish_reason": "length",
"stop_reason": null
}],
"usage": {
"prompt_tokens": 34,
"total_tokens": 41,
"completion_tokens": 7,
"prompt_logprobs": null
}
}message参数说明
当message角色为system时
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| content | 是 | string/array | 系统消息的内容 例:“content”:”你好”“content”:[{“type”:”text”,”text”:”你好”}] |
| role | 是 | string | 消息作者的角色,在本例中为 system |
| name | 否 | string | 参与者的可选名称。提供模型信息以区分同一角色的参与者。 |
当message角色为user时
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| content | 是 | string/array | 用户消息的内容。 |
| role | 是 | string | 消息作者的角色,在本例中为 user |
| name | 否 | string | 参与者的可选名称。提供模型信息以区分同一角色的参与者。 |
当message角色为assistant时
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| content | 是 | string/array | 用户消息的内容。 |
| refusal | 否 | string | 助理的拒绝消息。 |
| role | 是 | string | 消息作者的角色,在本例中assistant |
| name | 否 | string | 参与者的可选名称。提供模型信息以区分同一角色的参与者。 |
| tool_calls | 否 | array | 模型生成的工具调用。 |
当message角色为tool时
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| role | 是 | string | 消息作者的角色,在本例中为tool |
| content | 是 | string/array | 工具消息的内容。 |
| toolcallid | 否 | string | 此消息正在响应的工具调用。 |
messages列表格式规则
messages 列表是一个包含多个消息对象的数组,每个消息对象包含一个 role 属性,该属性的值为 "system"、"user"、"assistant" 或 "tool" 中的一个。messages 列表必须遵守以下规则:
列表中第一个消息的
role必须是 "system" 或 "user",最后一个消息的role必须是 "user" 或 "tool"。如果一个消息的
role是 "system",那么它下一个消息的role必须是 "user"。如果一个消息的
role是 "user"且不是最后一个消息,那么它下一个消息的role必须是 "assistant"。如果一个消息的
role是 "tool"且不是最后一个消息,那么它下一个消息的role必须是 "tool"或"assistant"。如果一个消息的
role是 "assistant",那么它下一个消息的role可以是多个"tool" 或一个 "user"。"system"、"user"、"assistant" 不能连续多次出现,即不能有两个连续的消息拥有相同的这些角色。"tool" 可以连续多次出现。
调用示例
Java版本
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/** 主类,用于发起HTTP请求并处理响应 */
public class Example {
public static void main(String[] args) {
example();
}
/**
* 方法中使用到的 JSONUtil、HttpRequest、HttpResponse均来自Hutool工具类。
* 具体maven依赖为:
*
* cn.hutool
* hutool-all
* 5.8.29
*
*/
public static void example() {
try {
String url = "算法调用地址";
// 设置请求头,用于公网调用鉴权
Map headers = new HashMap<>();
headers.put("X-APP-ID", "yourAppId");
headers.put("Order-Num", "yourOrderNum");
headers.put("Authorization", "yourAuthorization");
// 创建请求对象
Map request = new HashMap<>();
request.put("model", "telechat-115b");
Map messages = new HashMap<>();
messages.put("role", "user");
messages.put("content", "你是什么模型,能处理什么问题");
request.put("messages", Arrays.asList(messages));
request.put("max_completion_tokens", 150);
request.put("stream", true);
// 将请求对象转换为JsonNode
String requestString = JSONUtil.toJsonStr(request);
// 发起HTTP请求
HttpResponse response =
HttpRequest.post(url)
.headerMap(headers, true)
.body(requestString)
.execute();
// 输出响应结果
System.out.println(response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}Python版本
import json
import requests
from typing import Dict, List, Any, Optional
def example():
"""
使用requests库实现HTTP请求,对应Java Hutool版本
"""
try:
url = "算法调用地址"
# 设置请求头,用于公网调用鉴权
headers = {
"X-APP-ID": "yourAppId",
"Order-Num": "yourOrderNum",
"Authorization": "yourAuthorization"
}
# 创建请求对象
request = {
"model": "telechat-115b",
"messages": [
{
"role": "user",
"content": "你是什么模型,能处理什么问题"
}
],
"max_completion_tokens": 150,
"stream": True
}
# 发起HTTP请求
response = requests.post(
url=url,
headers=headers,
json=request, # 自动转换为JSON并设置Content-Type
timeout=30
)
# 输出响应结果
print(response.text)
return response.text
except Exception as e:
print(f"请求异常: {e}")
return None
# 使用示例
def main():
result1 = example()
if __name__ == "__main__":
main()