API Path
/aipaas/lm/v1/telechat/chat115b
请求协议
HTTPS
请求方法
POST
请求头部 :
| 头部标签 | 必填 | 说明 | 类型 | 数据字典 | 限制 | 头部内容 | 示例 |
|---|---|---|---|---|---|---|---|
| X-APP-ID | 是 | 控制台--应用管理--AppID | [string] | ||||
| Order-Num | 是 | 买家中心-订单管理-订单编号 | [string] | ||||
| Authorization | 是 | 鉴权信息 | [string] | ||||
| Content-Type | 是 | application/json | [string] |
请求参数 Json
Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| messages | 对话内容 | 是 | [array] | |||
| messages>>content | 系统消息的内容 string/array | 是 | [array] | 系例: “content”:”你好” “content”:[{“type”:”text”,”text”:”你好”}] | ||
| messages>>refusal | 助理的拒绝消息 | 否 | [string] | |||
| messages>>role | 消息作者的角色 | 是 | [string] | |||
| messages>>name | 参与者的可选名称 | 否 | [string] | |||
| messages>>tool_calls | 模型生成的工具调用 | 否 | [array] | |||
| messages>>tool_call_id | 此消息正在响应的工具调用 | 否 | [string] | |||
| model | 要使用的模型的ID | 是 | [string] | |||
| max_completion_tokens | 最大生成词元数量。输入词元和生成词元的总长度受模型上下文长度的限制,兼容传入max_tokens | 是 | [int] | |||
| presence_penalty | 默认值为 0,在 -2.0 到 2.0 之间。正值会基于新生成词是否已经出现在当前文本中进行惩罚,增加模型谈论新主题的可能性。 | 否 | [number] | |||
| stream | 默认值为 false,如果设置true,回答内容讲使用流式传输。 | 否 | [boolean] | |||
| stream_options | 流式响应的选项。仅当您设置stream: true时才设置此项 "stream_options":{"include_usage": true}。 如果设置,则在data: [DONE]之前流式传输的一个块中usage此块上的字段显示整个请求的token使用情况统计信息,所有其他块也将包含一个usage字段,但值为空。 | 否 | [object] | |||
| tools | 模型可以调用的工具列表。 | 否 | [array] | |||
| tools>>type | 工具的类型。该参数暂未生效 | 是 | [string] | |||
| tools>>function | 是 | [object] | ||||
| tools>>function>>description | 函数用途的描述,模型使用它来选择何时以及如何调用函数。 | 否 | [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 | 默认值为 1,使用的采样温度,范围在 0 到 2 之间。较高的值如 0.8 会使输出更随机,而较低的值如 0.2 会使输出更集中且具有确定性 | 否 | [number] | |||
| top_p | 默认值为 1,取值范围为0-1之间,作为温度采样的替代方法,称为核采样,该方法中模型考虑具有 top_p 概率质量的词元结果。 | 否 | [number] | |||
| extra_body | 额外参数 | 否 | [object] | |||
| extra_body>>top_k | 作用:随机候选数(不建议修改) 取值范围:12b模型:[1,120000] | 否 | [int] | |||
| extra_body>>repetition_penalty | 作用:生成重复惩罚(不建议修改) 取值范围:(0,+♾️) | 否 | [double] | |||
| traceId | 接口跟踪ID,每次调用需不同,可使用UUID, 用于日志排除、链路跟踪 | 否 | [string] | |||
| timestamp | 当前时间戳 | 否 | [long] |
响应内容 :
返回结果
> 流式响应结果-成功 (200)
> Json
> Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| id | 聊天补全的唯一标识符(uuid4)。 | 否 | [string] | |||
| choices | 聊天补全选项的列表。 | 否 | [array] | |||
| choices>>finish_reason | 模型停止生成标记的原因。原因可能是stop模型到达自然停止点或提供的停止序列、 length达到请求中指定的最大标记数。 如果模型调用了工具,tool_calls。 | 否 | [string] | |||
| choices>>index | 选择列表中的索引 | 否 | [int] | |||
| choices>>delta | 模型生成的聊天补全消息。 | 否 | [object] | |||
| choices>>delta>>content | 消息的内容 | 否 | [string] | |||
| choices>>delta>>role | 此消息作者的角色。【第一块携带、其他块不携带此参数】 | 否 | [string] | |||
| choices>>delta>>refusal | 模型生成的拒绝消息 | 否 | [string] | |||
| choices>>delta>>tool_calls | 工具列表 | 否 | [array] | |||
| choices>>delta>>tool_calls>>index | 选择列表中的索引 | 否 | [int] | |||
| choices>>delta>>tool_calls>>id | 工具调用的 ID | 否 | [string] | |||
| choices>>delta>>tool_calls>>type | 工具的类型。目前仅支持 function | 否 | [string] | |||
| choices>>delta>>tool_calls>>function | 模型调用的函数。 | 否 | [object] | |||
| choices>>delta>>tool_calls>>function>>name | 要调用的函数的名称 | 否 | [string] | |||
| choices>>delta>>tool_calls>>function>>arguments | 用于调用函数的参数,由模型以 JSON 格式生成。请注意,该模型并不总是生成有效的 JSON,并且可能会产生函数架构未定义的参数。在调用函数之前验证代码中的参数 | 否 | [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] | |||
| system_fingerprint | 代表模型运行时后端配置的指纹。【当前默认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 | 否 | [object] | |||
| usage>>total_tokens | 总tokens | 否 | [int] | |||
| system_fingerprint | 代表模型运行时后端配置的指纹。可以与请求参数 seed 结合使用,以了解可能影响确定性的后端更改何时发生。【当前默认null】 | 否 | [string] |
通用语义大模型35B通常指的是拥有350亿参数的大型预训练语言模型。这类模型通过在大规模文本数据上进行无监督学习,能够捕捉到语言的深层结构和语义信息,从而在多种自然语言处理任务中表现出色。
| 日期 | 版本 | 修订内容 |
|---|---|---|
| 2025-02-13 | v1.6.5.6 | 初始化API文档 |
服务接口调用时需要严格遵循服务鉴权规则,公网服务调用鉴权规则请参见:开发指南 - 接口签名认证.
流式请求示例
{
"model": "Chat",
"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": "aichat",
"object": "chat.completion.chunk"
}
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": "你好"
},
"logprobs": null
}],
"created": 1729666765,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
........中间省略消息块
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": "?"
},
"logprobs": null
}],
"created": 1729666765,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": null,
"index": 0,
"delta": {
"content": ""
},
"logprobs": null
}],
"created": 1729666765,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
data: {
"id": "277fd1f21c9e4b15bbbc6f28b0fc62ab",
"choices": [{
"finish_reason": "stop",
"index": 0,
"delta": {},
"logprobs": null
}],
"created": 1729666765,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion.chunk"
}
data: {
"id": "c86aff51e90442ed8c7e1ab5296189a8",
"choices": [],
"created": 1729666822,
"model": "aichat",
"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": "Chat",
"messages": [{
"role": "user",
"content": "你是什么模型,能处理什么问题"
}],
"max_completion_tokens": 150,
"stream": false
}
非流式响应示例
{
"id": "aacd0a837f244378812fa898d5094fe2",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"refusal": null,
"role": "assistant",
"content": " 你好,我很乐意为你解答问题。请问有什么我可以帮助你的吗?"
},
"logprobs": null
}
],
"created": 1729666692,
"model": "aichat",
"system_fingerprint": null,
"object": "chat.completion",
"usage": {
"completion_tokens": 41,
"prompt_tokens": 23,
"total_tokens": 64,
"completion_tokens_details": {
"reasoning_tokens": 0
}
}
}
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| content | 是 | string/array | 系统消息的内容 例:“content”:”你好”“content”:[{“type”:”text”,”text”:”你好”}] |
| role | 是 | string | 消息作者的角色,在本例中为 system |
| name | 否 | string | 参与者的可选名称。提供模型信息以区分同一角色的参与者。 |
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| content | 是 | string/array | 用户消息的内容。 |
| role | 是 | string | 消息作者的角色,在本例中为 user |
| name | 否 | string | 参与者的可选名称。提供模型信息以区分同一角色的参与者。 |
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| content | 是 | string/array | 用户消息的内容。 |
| refusal | 否 | string | 助理的拒绝消息。 |
| role | 是 | string | 消息作者的角色,在本例中assistant |
| name | 否 | string | 参与者的可选名称。提供模型信息以区分同一角色的参与者。 |
| tool_calls | 否 | array | 模型生成的工具调用。 |
| 字段 | 必填 | 类型 | 说明 |
|---|---|---|---|
| role | 是 | string | 消息作者的角色,在本例中为tool |
| content | 是 | string/array | 工具消息的内容。 |
| tool_call_id | 是 | string | 此消息正在响应的工具调用。 |
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-35b");
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();
}
}
}
import json
import requests
def build_request_dynamically():
"""动态构建请求体"""
# 初始化请求体
request_body = {}
request_body["model"] = "telechat-115b"
# 构建messages数组
messages = []
message = {
"role": "user",
"content": "你是什么模型,能处理什么问题"
}
messages.append(message)
request_body["messages"] = messages
request_body["max_completion_tokens"] = 150
request_body["stream"] = False
return request_body
def send_post_request_enhanced():
"""增强版的POST请求,包含更详细的日志和错误处理"""
try:
url = "算法调用地址"
headers = {
"X-APP-ID": "yourAppId",
"Order-Num": "yourOrderNum",
"Authorization": "yourAuthorization"
}
# 动态构建请求体
request_body = build_request_dynamically()
print(f"请求URL: {url}")
print(f"请求头: {headers}")
print(f"请求体: {json.dumps(request_body, indent=2, ensure_ascii=False)}")
# 发送POST请求
response = requests.post(
url=url,
headers=headers,
json=request_body,
timeout=30
)
# 处理响应
print(f"响应状态码: {response.status_code}")
if response.status_code == 200:
response_data = response.json()
print("请求成功完成")
print(f"响应数据: {json.dumps(response_data, indent=2, ensure_ascii=False)}")
return response_data
else:
print(f"POST请求失败,状态码: {response.status_code}")
print(f"响应内容: {response.text}")
return None
except requests.exceptions.Timeout:
print("请求超时")
except requests.exceptions.ConnectionError:
print("连接错误")
except requests.exceptions.HTTPError as e:
print(f"HTTP错误: {e}")
except json.JSONDecodeError as e:
print(f"JSON解析错误: {e}")
except Exception as e:
print(f"未预期的错误: {e}")
# 调用增强版函数
if __name__ == "__main__":
send_post_request_enhanced()