API Path
/aipaas/lm/v1/excel/generate
请求协议
HTTP
请求方法
POST
请求头部:
| 头部标签 | 必填 | 说明 | 类型 | 数据字典 | 限制 | 头部内容 | 示例 |
|---|---|---|---|---|---|---|---|
| Content-Type | 是 | application/json | [string] | application/json | application/json | ||
| X-APP-ID | 是 | 买家中心-已购能力-【X-APP-ID】 | [string] | ||||
| Device-Uuid | 否 | 设备管理-设备uuid | [string] | ||||
| Authorization | 是 | 鉴权信息 | [string] |
请求参数 Json:
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| traceId | 请求ID,要求为最长64位的随机字符串 | 是 | [string] | |||
| timestamp | 时间戳 | 否 | [int] | |||
| messages | 对话内容,目前只支持一轮对话 | 是 | [array] | |||
| messages>>role | 输入角色,可选值: "user”,“assistant” | 是 | [string] | |||
| messages>>content | 输入内容 | 是 | [string] | |||
| max_tokens | 最大输出长度 | 否 | [int] | |||
| top_p | 候选概率综合(不建议修改,取值范围:(0,1)) | 否 | [float] | |||
| temperature | 生成温度系数(不建议修改,取值范围:(0,1)) | 否 | [float] | |||
| stream | 是否流式返回,true为流式返回,false为非流式返回 | 是 | [boolean] | |||
| extra_params | 额外参数 | 是 | [object] | |||
| extra_params>>file_uuids | 分析的文档uuid,最多支持20个文档 | 是 | [array] |
响应内容:
返回结果
> 成功-流式 (200)
> Json
> Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| id | 请求ID | 是 | [string] | |||
| created | 聊天补全的时间戳 | 是 | [int] | |||
| model | 调用的模型名称 | 是 | [string] | |||
| object | 始终是chat.completion | 是 | [string] | |||
| choices | 响应数据 | 否 | [array] | |||
| choices>>finish_reason | 模型停止生成词元的原因。可能值包括: lstop: 模型达到了自然停止点或提供的停止序列。 llength: 达到请求中指定的最大词元数。 | 否 | [string] | |||
| choices>>index | 选项在选项列表中的索引 | 否 | [int] | |||
| choices>>delta | 聊天生成的消息补全, 请求stream字段为true时返回 | 否 | [object] | |||
| choices>>delta>>role | 输出角色 | 否 | [string] | |||
| choices>>delta>>content | 输出内容 | 否 | [string] | |||
| choices>>type | 内容类型,流式输出时返回。该字段用于表示当前chunk块是“分析过程”还是“最终结果”,可选值:"source"(分析过程)、"report"(最终结果) | 否 | [string] | 1.描述:内容类。"source" | ||
| choices>>file_size | 文件大小属性,可选值:“small”/"large" | 否 | [string] | |||
| choices>>logprobs | 输出标记的对数概率 | 否 | [string] |
> 成功-非流式 (200)
> Json
> Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| id | 请求ID | 是 | [string] | a504324c-6e10 | ||
| created | 聊天补全的时间戳 | 是 | [number] | 1677652288 | ||
| model | 调用的模型名称 | 是 | [string] | opeanchat | ||
| object | 调用的模型名称对象类型 | 是 | [string] | chat.completion | ||
| choices | 响应数据 | 否 | [array] | [{"message":{"role":"assistant","content":"文档主要写了..."},"index":0,"finish_reason":"stop"}] | ||
| choices>>finish_reason | 模型停止生成词元的原因。可能值包括: lstop: 模型达到了自然停止点或提供的停止序列。 llength: 达到请求中指定的最大词元数。 | 否 | [string] | stop | ||
| choices>>index | 选项在选项列表中的索引 | 否 | [number] | 0 | ||
| choices>>message | 聊天生成的消息补全 | 否 | [object] | |||
| choices>>message>>role | 输出角色 | 否 | [string] | assistant | ||
| choices>>message>>content | 输出内容 | 否 | [string] | 文档主要写了... | ||
| choices>>type | 流式返回中区分该chunk块是“分析过程”还是“最终结果”"source"/"report" | 否 | [string] | |||
| choices>>file_size | 算法判定文件大小属性 | 否 | [string] | |||
| choices>>logprobs | 为null | 否 | [string] |
生成文档摘要可以从长文档中提取关键信息并生成简洁的摘要。
服务接口调用时需要严格遵循服务鉴权规则,服务调用鉴权规则请参见:开发指南 - 签名认证方式。
| 编码 | 描述信息 |
|---|---|
| 10000 | 正确返回 |
| 10001 | 文件格式错误 |
| 10002 | 上传文件列表为空 |
| 10003 | 文件不存在 |
| 10004 | 参数不正确 |
| 10005 | 已存在同名文件 |
| 10006 | 生成服务调用文件服务失败 |
| 10007 | 下载待分析的文件失败 |
| 10008 | 分析失败 |
| 10013 | 没有找到对应uuid的文件 |
| 10030 | 请求参数错误 |
通用状态码请参考【状态码】中的【网关认证】和【通用业务】
流式请求示例
{
"traceId": "a504324c-6e10",
"messages": [{
"role": "user",
"content": "帮忙分析一下这些excel文档"
}
],
"stream": true,
"temperature": 0,
"extra_params": {
"file_uuids": [
"d12fd037-19df-4973-a246-290673b6407a"
]
}
}
流式响应示例
{'choices': [{'finish_reason': None, 'delta': {'content': '中间结果1'}, 'index': 0, 'type':'source', 'file_size':'large'}], 'object': 'chat.completion.chunk', 'usage': None, 'created': 1730681150, 'model': 'openchat', 'id': 'chatcmpl-6f09deda-9b44-92f5-aa6d-5ee3e703658a'}
{'choices': [{'delta': {'content': '中间结果2'}, 'finish_reason': None, 'index': 0, 'type':'source', 'file_size':'large'}], 'object': 'chat.completion.chunk', 'usage': None, 'created': 1730681150, 'model': 'openchat', 'id': 'chatcmpl-6f09deda-9b44-92f5-aa6d-5ee3e703658a'}
{'choices': [{'delta': {'content': '报告1'}, 'finish_reason': None, 'index': 0, 'type':'report', 'file_size':'large'}], 'object': 'chat.completion.chunk', 'usage': None, 'created': 1730681150, 'model': 'openchat', 'id': 'chatcmpl-6f09deda-9b44-92f5-aa6d-5ee3e703658a'}
...
[DONE]
非流式请求示例
{
"traceId": "a504324c-6e10",
"messages": [{
"role": "user",
"content": "帮忙分析一下这些excel文档"
}
],
"stream": false,
"temperature": 0,
"extra_params": {
"file_uuids": [
"d12fd037-19df-4973-a246-290673b6407a"
]
}
}
非流式响应示例
{
"id": "a504324c-6e10",
"created": 1677652288,
"model": "opeanchat",
"object": "chat.completion",
"choices": [{
"message": {
"role": "assistant",
"content": "文档主要写了..."
},
"index": 0,
"finish_reason": "stop"
}]
}
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("Content-Type", "application/json");
headers.put("X-APP-ID", "yourAppId");
headers.put("Authorization", "yourAuthorization");
// 创建请求对象
Map request = new HashMap();
request.put("traceId", "a504324c-6e10");
Map message1 = new HashMap();
message1.put("role", "user");
message1.put("content", "帮忙分析一下这些excel文档");
request.put("messages", Arrays.asList(message1));
request.put("stream", true);
request.put("temperature", 0);
Map params = new HashMap();
params.put("file_uuids", Arrays.asList("d12fd037-19df-4973-a246-290673b6407a"));
request.put("extra_params", params);
// 将请求对象转换为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 hashlib
import hmac
import time
import re
import urllib.parse
import requests
import warnings
from datetime import datetime
import logging
# 配置日志,设置日志级别为INFO,并指定日志格式
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 配置环境变量
X_APP_ID = "yourAppId"
AUTHORIZATION = "yourAuthorization"
# URL 和请求数据
url = "算法调用地址" # 请求的URL
request_data = {
"traceId": "a504324c-6e10",
"messages": [
{
"role": "user",
"content": "帮我梳理一下文档的主要内容"
}],
"stream": True,
"temperature": 0,
"extra_params": {
"file_uuids": [
"d12fd037-19df-4973-a246-290673b6407a"
]
}
}
# 构建请求头
headers = {
"Content-Type": "application/json",
"X-APP-ID": X_APP_ID,
"Authorization": AUTHORIZATION
}
def timeSimple(timestamp):
# 将时间戳转换为HH:MM:SS格式的时间字符串
dt_object = datetime.fromtimestamp(timestamp)
formatted_time = dt_object.strftime("%H:%M:%S")
return formatted_time
def send_request(url):
try:
start_time = time.time()
logging.info(f"请求路径: {url}")
logging.info(f"开始发送: {timeSimple(start_time)}")
with requests.post(
url, json=request_data, headers=headers, stream=True, verify=False
) as response:
first_packet_time = None
if response.status_code == 200:
logging.info(f"接受到返回: {timeSimple(time.time())}")
for chunk in response.iter_content(chunk_size=1024):
if chunk:
if first_packet_time is None:
first_packet_time = time.time()
logging.info(
f"Received chunk: {timeSimple(time.time())} {chunk.decode('utf-8')}"
)
end_time = time.time()
logging.info(f"Time to first byte (TTFB): {first_packet_time - start_time:.3f} seconds")
logging.info(f"Request completed in {end_time - start_time:.3f} seconds")
else:
logging.error(f"Request failed with status code {response.status_code}")
except Exception as e:
logging.error(f"An error occurred: {e}")
# 发送请求
send_request(url)
logging.info(f"headers = {headers}")