业务API
Chat completions
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/v1/chat/completions
请求方式:POST
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer" + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| messages | array(message) | 是 | 聊天上下文信息。支持Qwen VL系列模型。 纯文本示例:messages=[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Knock knock."},{"role": "assistant", "content": "Who's there?"},{"role": "user", "content": "Orange."},] 多模态示例:{"messages":[{"role":"user","content":[{"type":"text","text":"describe the image in 100 words or less"},{"type":"image_url","image_url":{"url":"xxx","detail":"high"}}]}]}} |
| model | string | 是 | 模型 |
| tools | array | 否 | 工具列表,只支持function |
| stream | bool | 否 | 是否以流式接口的形式返回数据,默认false |
| max_tokens | integer | 否 | 模型回复最大长度(单位 token) |
| temperature | number | 否 | 较高的数值会使输出更加随机,而较低的数值会使其更加集中。默认值1.0,取值范围[0,2.0]。 |
| top_p | number | 否 | 影响输出文本的多样性,取值越大,生成文本的多样性越强。默认值1.0。 |
| stop | array(string) | 否 | 停止生成更多Tokens的最多4个字符串。 |
| presence_penalty | number | 否 | 通过对已生成的token增加惩罚,减少重复生成的现象。默认值0,取值范围:[-2.0, 2.0]。 |
| frequency_penalty | number | 否 | 根据新词在当前文本中的频率进行惩罚,降低模型逐字重复同一行的可能性。 默认值0,取值范围:[-2.0, 2.0]。 |
| logprobs | boolean | 否 | 默认值false。是否返回输出 tokens 的对数概率。 |
| top_logprobs | integer | 否 | 默认值0,取值范围为 [0, 20]。指定每个输出 token 位置最有可能返回的 token 数量,每个 token 都有关联的对数概率。仅当 logprobs为true 时可以设置 top_logprobs 参数。 |
| response_format | object | 否 | 指定模型必须输出的格式的对象。 默认值: { "type": "text" } 设置为 { "type": "json_object" } 可启用 JSON 模式,这保证模型生成的消息是有效的 JSON。 重要:使用 JSON 模式时,您还必须通过系统或用户消息提示模型自行生成JSON。 |
| chat_template_kwargs.enable_thinking | bool | 否 | 是否开启思考模式。 |
| thinking.type | string | 否 | 思考模式,此为兼容接口,效果同chat_template_kwargs.enable_thinking,可填"enabled","disabled",仅支持GLM-4.5系列模型 |
| enable_thinking | bool | 否 | 思考模式,此为兼容接口,效果同chat_template_kwargs.enable_thinking |
- 模型支持的超参和功能列表
| 模型 | enable_thinking | max_tokens | stop | temperature | top_p | frequency_penalty | presence_penalty |
|---|---|---|---|---|---|---|---|
| Qwen2-VL系列 | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen2.5-7B-Instruct | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen2.5-32B-Instruct | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen2.5-72B-Instruct | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen2.5-VL-7B-Instruct | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen2.5-VL-32B-Instruct | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen2.5-VL-72B-Instruct | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen3-14B | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen3-32B | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen3-235B-A22B | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen3-235B-A22B-Instruct-2507 | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Qwen3-Coder | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| QwQ-32B | ❌ | ✔️ | ❌ | ❌ | ❌ | ❌ | ❌ |
| DeepSeek-v3 | ❌ | ✔️ | ✔️ | ❌ | ✔️ | ❌ | ❌ |
| DeepSeek-V3-Fast | ❌ | ✔️ | ✔️ | ❌ | ✔️ | ❌ | ❌ |
| DeepSeek-R1 | ❌ | ✔️ | ❌ | ❌ | ❌ | ❌ | ❌ |
| DeepSeek-R1-0528 | ❌ | ✔️ | ❌ | ❌ | ❌ | ❌ | ❌ |
| DeepSeek-R1-Distill-Llama系列 | ❌ | ✔️ | ❌ | ❌ | ❌ | ❌ | ❌ |
| DeepSeek-R1-Distill-Qwen系列 | ❌ | ✔️ | ❌ | ❌ | ❌ | ❌ | ❌ |
| DeepSeek-Prover-V2 | ❌ | ✔️ | ✔️ | ❌ | ❌ | ❌ | ❌ |
| Kimi-K2 | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| Kimi-K2-0905 | ❌ | ✔️ | ✔️ | ✔️ | ✔️ | ❌ | ❌ |
| GLM-4.5 | ✔️ | ✔️ | ✔️ | ❌ | ✔️ | ❌ | ❌ |
| GLM-4.5V | ✔️ | ✔️ | ✔️ | ❌ | ✔️ | ❌ | ❌ |
| GLM-4.6 | ✔️ | ✔️ | ✔️ | ❌ | ✔️ | ❌ | ❌ |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | 流式:text/event-stream非流式:application/json |
- 响应体参数
a.非流式
| 名称 | 类型 | 描述 |
|---|---|---|
| object | string | 回包类型 chat.completion.chunk:多轮对话返回 |
| created | int | 时间戳 |
| model | string | 模型 示例值:Qwen/Qwen2.5-72B-Instruct |
| choices | array | |
| choices[0].index | int | 索引 |
| choices[0].finish_reason | string | 结束原因 正常结束:stop,token超长截断结束:length |
| choices[0].message | object | 模型回答 |
| choices[0].message.tool_calls | array | 工具列表 |
| choices[0].message.tool_calls[0].function | object | 函数调用信息 |
| choices[0].refs | array | 引用列表,调用自定义模型且模型输出包含文档引用时存在。在非流式调用中,会在最终结果内输出此次回答包含的所有引用来源信息。 |
| choices[0].refs[0].index | int | 引用来源出现顺序 |
| choices[0].refs[0].title | string | 引用数据标题 |
| choices[0].refs[0].content | string | 引用数据内容 |
| choices[0].refs[0].type | string | 引用数据类型,file/qa/web, 分别代表文件知识, Q&A Table和web搜索 |
| choices[0].refs[0].url | string | 引用数据url,其中,file和qa数据url访问需配置apikey,web数据url访问无需配置apikey |
b.流式
| 名称 | 类型 | 描述 |
|---|---|---|
| object | string | 回包类型 chat.completion.chunk:多轮对话返回 |
| created | int | 时间戳 |
| model | string | 模型 示例值:Qwen/Qwen2.5-72B-Instruct |
| choices | array | |
| choices[0].index | int | 索引 |
| choices[0].finish_reason | string | 结束原因 正常结束:stop,token超长截断结束:length |
| choices[0].delta | object | 模型回答 |
| choices[0].refs | array | 引用列表,调用自定义模型且模型输出包含文档引用时存在。在流式响应过程中,会实时于存在引用的位置输出引用来源信息,并在finish_reason不为空时输出此次回答包含的所有引用来源信息。 |
| choices[0].refs[0].index | int | 引用来源出现顺序 |
| choices[0].refs[0].title | string | 引用数据标题 |
| choices[0].refs[0].content | string | 引用数据内容 |
| choices[0].refs[0].type | string | 引用数据类型,file/qa/web, 分别代表文件知识, Q&A Table和web搜索 |
| choices[0].refs[0].url | string | 引用数据url,其中,file和qa数据url访问需配置apikey,web数据url访问无需配置apikey |
请求示例
示例如下,请将参数示例值替换为实际值。
- 纯文本请求示例
curl --location -g --request POST 'https://www.sophnet.com/api/open-apis/v1/chat/completions' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"messages": [
{
"role": "system",
"content": "你是SophNet的智能助手"
},
{
"role": "user",
"content": "你可以帮我做什么"
}
],
"model":"Qwen2.5-72B-Instruct"
}'Python SDK
# 支持兼容OpenAI Python SDK 终端运行:pip install OpenAI
from openai import OpenAI
### 初始化客户端
client = OpenAI(
api_key= "API_KEY",
base_url= "https://www.sophnet.com/api/open-apis/v1"
)
### 调用接口
response = client.chat.completions.create(
model="Qwen2.5-72B-Instruct",
messages=[
{"role": "system", "content": "你是SophNet智能助手"},
{"role": "user", "content": "你可以帮我做些什么"},
]
)
# 打印结果
print(response.choices[0].message.content)- Function Call请求示例
HTTP API
curl --location -g --request POST 'https://www.sophnet.com/api/open-apis/v1/chat/completions' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"messages": [
{
"role": "user",
"content": "今日上海天气如何?"
}
],
"model":"DeepSeek-v3",
"tools": [
{
"type": "function",
"function":
{
"name": "get_weather",
"description": "Get current temperature for provided coordinates in celsius.",
"parameters":
{
"type": "object",
"properties":
{
"latitude": {"type": "number"},
"longitude": {"type": "number"}
},
"required": ["latitude", "longitude"],
"additionalProperties": false
},
"strict": true
}
}
]
}'
# 请求成功后,从返回值的choices[0].message.tool_calls[0].function获取到函数调用信息
# 其中function.name是函数名,function.arguments中含有函数参数
# 假设已通过函数调用获取到返回值是20,且获取到choices[0].message.tool_calls[0].id = "call_f0j0i4meawn7kqx335d4fsj1"
# 接下来是第二次请求,其中messages列表的第一个与之前相同,第二个为choices[0].message.tool_calls,第三个的构造信息参考如下
curl --location -g --request POST 'https://www.sophnet.com/api/open-apis/v1/chat/completions' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"messages": [
{
"role": "user",
"content": "今日上海天气如何?"
},
{
"content": "",
"role": "assistant",
"tool_calls": [
{
"id": "call_f0j0i4meawn7kqx335d4fsj1",
"type": "function",
"function":
{
"name": "get_weather",
"arguments": "{\"latitude\":31.2304,\"longitude\":121.4737}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_f0j0i4meawn7kqx335d4fsj1",
"content": "20"
}
],
"model":"DeepSeek-v3",
"tools": [
{
"type": "function",
"function":
{
"name": "get_weather",
"description": "Get current temperature for provided coordinates in celsius.",
"parameters":
{
"type": "object",
"properties":
{
"latitude": {"type": "number"},
"longitude": {"type": "number"}
},
"required": ["latitude", "longitude"],
"additionalProperties": false
},
"strict": true
}
}
]
}'- 多模态请求示例(Qwen VL模型支持多模态参数请求)
HTTP API
curl --location -g --request POST 'https://www.sophnet.com/api/open-apis/projects/v1/chat/completions' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"messages": [{
"role": "user",
"content": [
{
"type": "text",
"text": "describe the image in 100 words or less"
},
{
"type": "image_url",
"image_url": {
"url": "xxx"
}
}
]
}],
"model":"Qwen2.5-VL-72B-Instruct",
"stream":false
}'Python SDK
# 支持兼容OpenAI Python SDK 终端运行:pip install OpenAI
from openai import OpenAI
### 初始化客户端
client = OpenAI(
api_key= "API_KEY",
base_url= "https://www.sophnet.com/api/open-apis/v1"
)
### 调用接口
response = client.chat.completions.create(
model="Qwen2.5-VL-72B-Instruct",
messages=[
{"role": "system", "content": "你是SophNet智能助手"},
{
"role": "user",
"content": [
{
"type":"text",
"text":"描述一下这张图片"
},
{
"type":"image_url",
"image_url":{"url":xxx}
}]
},
]
)
# 打印结果
print(response.choices[0].message.content)响应示例
流式 (event-stream)
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"我可以","role":"assistant"},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"提供","role":null},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"智能问答","role":null},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":"和帮助。","role":null},"finish_reason":null}]}
data:{"object":"chat.completion.chunk","created":1724651635,"model":"Qwen/Qwen2.5-72B-Instruct","choices":[{"index":0,"delta":{"content":null,"role":null},"finish_reason":"stop"}]}非流式 (Json)
{
"object": "chat.completion",
"created": 1724652804,
"model": "Qwen/Qwen2.5-72B-Instruct",
"choices": [
{
"index": 0,
"message": {
"content": "作为SophNet智能助手,我可以帮助你完成多种任务。如果你有具体的需求或问题,请告诉我!",
"role": "assistant"
},
"finish_reason": "stop"
}
]
}Function Call (Json) 首次返回
{
"object":"chat.completion",
"created":1744967746,
"model":"DeepSeek-v3",
"choices":[
{
"index":0,
"message":
{
"content":"",
"role":"assistant",
"tool_calls":[
{
"id":"call_f0j0i4meawn7kqx335d4fsj1",
"type":"function",
"function":
{
"name":"get_weather",
"arguments":"{\"latitude\":31.2304,\"longitude\":121.4737}"
}
}
]
},
"finish_reason":"tool_calls"
}
]
}第二次返回
{
"object":"chat.completion",
"created":1744967193,
"model":"DeepSeek-v3",
"choices":[
{
"index":0,
"message":
{
"content":"今日上海的天气温度为20°C。",
"role":"assistant"
},
"finish_reason":"stop",
}
]
}Speech to text
创建Task
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/{ProjectId}/easyllms/speechtotext/transcriptions
请求方式:POST
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| ProjectId | String | 是 | 项目id |
支持两种请求方式
音频文件链接模式Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer " + Apikey |
- 音频文件链接模式Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| audio_url | string | 是 | 语音url路径 支持音频格式:wav、mp3、m4a、flv、mp4、wma、3gp、amr、aac、ogg-opus、flac 音频限制:音频 URL 时长不能大于5小时,文件大小不超过1GB 识别有效时间:识别结果在服务端保存24小时 |
| easyllm_id | string | 是 | Easyllm ID |
- 音频文件上传模式Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值multipart/form-data |
| Authorization | String | 是 | "Bearer " + Apikey |
- 音频文件链接模式form-data参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| data | JSON字符串 | 是 | 与 JSON 模式下的 body 一致,需为字符串形式的 JSON |
| audio_file | 文件 | 是 | 本地音频文件 |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| task_id | string | 任务id |
| created | int | 时间戳 |
请求示例
HTTP API 音频文件链接模式
curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/speechtotext/transcriptions' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"audio_url":"YOUR_AUDIO_URL",
"easyllm_id":"YOUR_SERVICE_ID"
}'音频文件上传模式
curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/speechtotext/transcriptions' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: multipart/form-data" \
-F 'data={"easyllm_id":"YOUR_SERVICE_ID"};type=application/json' \
-F "audio_file=@/path/to/your_audio_file.wav;type=audio/wav"响应示例
{
"taskId": "10047816884",
"created": 1724652804
}查询Task状态、结果
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/{project_id}/easyllms/speechtotext/transcriptions/{taskId}
请求方式:GET
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| project_id | String | 是 | 项目id |
| task_id | String | 是 | 语音转文本task_id |
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer" + Apikey |
- Body参数
无
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| task_id | string | 任务id |
| status | string | 任务状态,waiting:任务等待,doing:任务执行中,success:任务成功,failed:任务失败。 示例值:waiting |
| result | string | 转录结果 |
| errorMsg | string | 错误码 |
请求示例
HTTP API
curl --location --request GET 'https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/speechtotext/transcriptions/{taskId}' \
--header "Authorization: Bearer $API_KEY" \响应示例
{
"taskId": "10045132157",
"status": "success",
"result": "[0:5.840,0:6.690,0] 哎,张总。\n[0:7.520,0:8.270,1] 还要打吗?\n[0:8.700,0:8.925,0] 哎。\n[0:8.925,0:12.550,1] 我能听到这给你们发了有3张图。\n"
}流式Speech to text
连接请求说明
- 基本信息
请求地址:wss://www.sophnet.com/api/open-apis/projects/{ProjectId}/easyllms/stream-speech
请求方式:Websocket
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| ProjectId | String | 是 | 项目id |
- Request参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| easyllm_id | String | 是 | easyllm id |
| apikey | String | 是 | Apikey |
| format | String | 是 | 输入音频格式,支持pcm、wav、mp3、opus、speex、aac、amr |
| sample_rate | int | 是 | 音频采样率,任意音频采样率,但16k效果更好 |
| heartbeat | bool | 是 | 是否开启心跳,若为false即使发送静音音频也会在60s后超时关闭连接,需要在60s内包含人声音频,若为true,发送静音音频将保持连接,需要在60s内发送音频。 |
音频数据发送请求说明
- 音频数据发送说明:音频bytes数据,可按照3200的数量发送。
关闭连接请求说明
- 关闭连接请求说明:发送一个字符串"BYE"来主动关闭连接。
连接响应说明
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| status | string | 连接成功返回'ok',失败则直接关闭连接 |
音频识别结果响应说明
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| text | string | 句子级识别结果,当is_sentence_end为false时,包含流式识别的输出结果,而为true则表示最终句子识别结果,下一个消息将是新的句子 |
| begin_time | int | 句子开始的时刻,单位为毫秒 |
| end_time | int | 句子结束的时刻,单位为毫秒 |
| words | string | 字级别的预测结果 |
| is_sentence_end | bool | 表示句子是否结束 |
连接请求示例
Websocket API
const url = `wss://www.sophnet.com/api/open-apis/projects/${ProjectId}/easyllms/stream-speech`
+ `?easyllm_id=${model}`
+ `&apikey=${apikey}`
+ `&format=${format}`
+ `&sample_rate=${sampleRate}`
+ `&heartbeat=true`;
ws = new WebSocket(url);
ws.binaryType = 'arraybuffer';
ws.onopen = () => {
log('WebSocket 已连接: ' + url);
};
ws.onmessage = (evt) => {
if (typeof evt.data === 'string') {
log('<- ASR_RESULT: ' + evt.data);
} else {
log('<- binary message (' + evt.data.byteLength + ' bytes)');
}
};
ws.onerror = (err) => {
log('WebSocket 错误: ' + err);
};
ws.onclose = (evt) => {
log(`WebSocket 已关闭: [${evt.code}] ${evt.reason}`);
};音频数据发送请求示例
Websocket API
ws.send(byteData);连接响应示例
{"status": "ok"}音频识别结果响应示例
{"text":"这是深度神经网络的语音","begin_time":660,"end_time":null,"words": ["Word(beginTime=660, endTime=1148, text=这是, punctuation=, fixed=false)", "Word(beginTime=1148, endTime=1636, text=深度, punctuation=, fixed=false)", "Word(beginTime=1636, endTime=2124, text=神经, punctuation=, fixed=false)", "Word(beginTime=2124, endTime=2612, text=网络的, punctuation=, fixed=false)", "Word(beginTime=2612, endTime=3100, text=语音, punctuation=, fixed=false)"], "is_sentence_end": false}
{"text":"这是深度神经网络的语音识别","begin_time":660,"end_time":null,"words": ["Word(beginTime=660, endTime=1148, text=这是, punctuation=, fixed=false)", "Word(beginTime=1148, endTime=1636, text=深度, punctuation=, fixed=false)", "Word(beginTime=1636, endTime=2124, text=神经, punctuation=, fixed=false)", "Word(beginTime=2124, endTime=2612, text=网络的, punctuation=, fixed=false)", "Word(beginTime=2612, endTime=3100, text=语音, punctuation=, fixed=false)", "Word(beginTime=3100, endTime=3500, text=识别, punctuation=, fixed=false)"], "is_sentence_end": false}
{"text":"这是深度神经网络的语音识别","begin_time":660,"end_time":null,"words": ["Word(beginTime=660, endTime=1148, text=这是, punctuation=, fixed=false)", "Word(beginTime=1148, endTime=1636, text=深度, punctuation=, fixed=false)", "Word(beginTime=1636, endTime=2124, text=神经, punctuation=, fixed=false)", "Word(beginTime=2124, endTime=2612, text=网络的, punctuation=, fixed=false)", "Word(beginTime=2612, endTime=3100, text=语音, punctuation=, fixed=false)", "Word(beginTime=3100, endTime=3588, text=识别, punctuation=, fixed=false)"], "is_sentence_end": false}
{"text":"这是深度神经网络的语音识别模型。","begin_time":660,"end_time":5540,"words": ["Word(beginTime=660, endTime=1148, text=这是, punctuation=, fixed=false)", "Word(beginTime=1148, endTime=1636, text=深度, punctuation=, fixed=false)", "Word(beginTime=1636, endTime=2124, text=神经, punctuation=, fixed=false)", "Word(beginTime=2124, endTime=2612, text=网络的, punctuation=, fixed=false)", "Word(beginTime=2612, endTime=3100, text=语音, punctuation=, fixed=false)", "Word(beginTime=3100, endTime=3588, text=识别, punctuation=, fixed=false)", "Word(beginTime=3588, endTime=4076, text=模型, punctuation=, fixed=false)"], "is_sentence_end": true}
{"text":"请","begin_time":6001,"end_time":null,"words": ["Word(beginTime=6001, endTime=6502, text=请, punctuation=, fixed=false)"], "is_sentence_end": false}非流式同步Speech to text
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/speechtotext/non-stream
请求方式:POST
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| ProjectId | String | 是 | 项目id |
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer" + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| audio_url | String | 是 | 设置待识别音频路径 |
| speech_recognition_param | Object | 否 | 识别参数 |
| speech_recognition_param.model | String | 否 | 设置识别模型。仅支持内部默认模型,不可选择,后续将支持多模型。 |
| speech_recognition_param.sample_rate | Integer | 否 | 设置待识别音频采样率。支持任意采样率。 |
| speech_recognition_param.format | String | 否 | 设置待识别音频格式。支持的音频格式:wav。 |
| easyllm_id | String | 是 | Easyllm ID |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| result | String | 模型推理结果 |
| audio_duration | Float | 音频总时长,单位为秒 |
请求示例
HTTP API
curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/speechtotext/non-stream' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"easyllm_id": "{YOUR_EASYLLM_ID}",
"audio_url": "{YOUR_AUDIO_URL}"
}'响应示例
{
"result":"你好,算能。",
"audio_duration":2.471
}Embeddings
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/embeddings
请求方式:POST
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| ProjectId | String | 是 | 项目id |
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer" + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| model | string | 否 | 支持:text-embeddings、clip-embeddings、bge-m3,默认为text-embeddings |
| input_texts | array(string) | 是 | 数组中每一个元素是一个文本,每个文本最大支持8192个Tokens。text-embeddings模型最大支持10个文本,bge-m3模型最大支持1个文本。 |
| input_images | array(string) | 否 | 数组中每一个元素是一个base64 图像或 URL,仅对clip-embeddings模型有效 |
| dimensions | integer | 是 | 输出Embeddings的维度,text-embeddings模型支持1,024/768/512/256/128/64,clip-embeddings模型支持64到1024维,bge-m3模型仅支持1024维。 |
| easyllm_id | string | 是 | Easyllm ID |
| normalized | bool | 否 | 是否使用L2规范化,仅对clip-embeddings模型有效 |
| encoding_type | string | 否 | 输出数据的格式,仅对clip-embeddings模型有效 |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| id | string | 任务id |
| usage | dict | 模型推理时Token使用情况 |
| data | array | 模型推理结果,按顺序输出,文本Embedding在前,图片Embedding在后 |
请求示例
HTTP API
# sample1
curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/embeddings' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"easyllm_id": "{YOUR_EASYLLM_ID}",
"input_texts": ["你好", "很高兴认识你"],
"dimensions": 1024
}'
# sample2
curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/embeddings' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $API_KEY' \
--data-raw '{
"model": "clip-embeddings",
"easyllm_id": "{YOUR_EASYLLM_ID}",
"input_texts": ["海滩上美丽的日落"],
"input_images": ["https://i.ibb.co/nQNGqL0/1beach1.jpg", "https://i.ibb.co/r5w8hG8/beach2.jpg", "iVBORw0KGgoAAAANSUhEUgAAABwAAAA4CAIAAABhUg/jAAAAMklEQVR4nO3MQREAMAgAoLkoFreTiSzhy4MARGe9bX99lEqlUqlUKpVKpVKpVCqVHksHaBwCA2cPf0cAAAAASUVORK5CYII="],
"dimensions": 1024
}'响应示例
// sample1
{
"id": "",
"object": "list",
"usage": {
"prompt_tokens": 4,
"completion_tokens": null,
"total_tokens": 4,
"prompt_tokens_details": null,
"completion_tokens_details": null
},
"data": [
{
"embedding": [
-0.08296291530132294,
0.03833295777440071,
...
],
"index": 0,
"object": "embedding"
},
{
"embedding": [
-0.05998880788683891,
0.04025664180517197,
...
],
"index": 1,
"object": "embedding"
}
]
}
// sample2
{
"object": "list",
"usage": {
"prompt_tokens": 20008,
"completion_tokens": null,
"total_tokens": 20008,
"prompt_tokens_details": null,
"completion_tokens_details": null
},
"data": [
{
"embedding": [
0.02087402,
0.06689453,
-0.07763672,
-0.10253906,
...
],
"index": 0,
"object": "embedding"
},
{
"embedding": [
0.01507568,
0.16015625,
-0.08837891,
...
],
"index": 1,
"object": "embedding"
},
{
"embedding": [
0.04882812,
0.20214844,
-0.07861328,
0.00276184,
...
],
"index": 2,
"object": "embedding"
},
{
"embedding": [
-0.00939941,
0.18164062,
0.02038574,
0.01239014,
...
],
"index": 3,
"object": "embedding"
}
]
}Document Parse
请求说明
- 基本信息
功能描述:高效转换主流格式文档至精准、易用的Markdown文本内容。上传文件(form-data),输出文档内容(Markdown)
请求地址:https://www.sophnet.com/api/open-apis/projects/{ProjectId}/easyllms/doc-parse
请求方式:POST
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| ProjectId | String | 是 | 项目id |
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值multipart/form-data |
| Authorization | String | 是 | "Bearer " + Apikey |
- form-data参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| file | file | 是 | 文档,支持pdf,docx,doc,xlsx,txt,pptx格式,大小<50MB |
| easyllm_id | string | 是 | Easyllm ID |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 值 |
|---|---|---|
| data | string | 文档解析结果(Markdown) |
请求示例
HTTP API
curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/doc-parse' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: multipart/form-data" \
--form 'file=@"YOUR_DOCUMENT"' \
--form 'easyllm_id="YOUR_SERVICE_ID"'Python SDK
# 使用SDK前需要安装python库 终端运行:pip install fastmodels-kit
from fastmodels import Client
# 初始化客户端
client = Client(
api_key= "YOUR_API_KEY",
project_id= "YOUR_PROJECT_ID"
)
# 调用接口
response = client.easyllm.doc_parse.create(
easyllm_id="YOUR_SERVICE_ID",
file_path="YOUR_FILE_PATH"
)
# 打印输出
print(response.data)响应示例
{
"data": "文件编号:HR-2023-06-3-1\n\n发布单位:AMT\n\n发布对象:全员\n\n发布日期:2023.11.16\n\n生效日期:2023.11.16\n\n**管理制度**\n\n......"
}Text to voice
流式/非流式 Text to voice
请求说明
- 基本信息
功能描述:文字转语音服务。发送文件,输出语音(默认为mp3格式)。
请求地址:
流式接口:https://www.sophnet.com/api/open-apis/projects/{ProjectId}/easyllms/voice/synthesize-audio-stream
非流式接口:https://www.sophnet.com/api/open-apis/projects/{ProjectId}/easyllms/voice/synthesize-audio
请求方式:POST
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| ProjectId | String | 是 | 项目id |
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer" + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| text | array(string) | 是 | 需要转语音的字符串列表 |
| synthesis_param | object | 是 | 转语音参数 |
| synthesis_param.model | string | 是 | 指定模型,默认值为"cosyvoice-v1",支持"cosyvoice-v1"、"cosyvoice-v2" |
| synthesis_param.voice | string | 否 | 指定音色,默认值为"longxiaochun" |
| synthesis_param.format | string | 否 | 指定音频编码格式及采样率,格式为"文件格式_采样率_通道_比特率",例如MP3_16000HZ_MONO_128KBPS代表音频格式为mp3,采样率为16kHz。若未指定format,系统将根据voice参数自动选择该音色的推荐格式。各个文件格式对应的示例:WAV_16000HZ_MONO_16BIT、MP3_16000HZ_MONO_128KBPS、PCM_16000HZ_MONO_16BIT,其他文件格式暂未支持。 |
| synthesis_param.volume | number | 否 | 指定音量,默认值为50,取值范围:[0-100] |
| synthesis_param.speechRate | number | 否 | 指定语速,默认值为1,输入范围:[0.5,2] |
| synthesis_param.pitchRate | number | 否 | 指定语调,默认值为1,取值范围:[0.5,2] |
| easyllm_id | string | 是 | Easyllm ID |
响应说明
流式接口
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | text/event-stream |
- 响应体参数
| 名称 | 类型 | 值 |
|---|---|---|
| data | string | base64编码的语音数据 |
非流式接口
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | audio/mpeg, audio/wav, audio/L16, application/octet-stream | 二进制音频流,依据具体格式返回对应类型 |
请求示例
HTTP API
curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/voice/synthesize-audio-stream' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"easyllm_id": "YOUR_SERVICE_ID",
"text": ["这是要合成的文本", "第二段文本"],
"synthesis_param": {
"model": "cosyvoice-v1",
"voice": "longxiaochun",
"format": "WAV_16000HZ_MONO_16BIT",
"volume": 80,
"speechRate": 1.2,
"pitchRate": 1.0
}
}'Python requests
- NOTE: 这里演示如何输出为音频文件
流式接口
import requests
import json
import base64
projectId = "YOUR_PROJECT_ID"
easyllmId = "YOUR_EASYLLM_SERVICE_ID"
API_KEY = "YOUR_API_KEY"
url = f"https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/voice/synthesize-audio-stream"
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + API_KEY,
}
payload = json.dumps({
"easyllm_id": easyllmId,
"text": [
"测试",
],
"synthesis_param": {
"model": "cosyvoice-v1",
"voice": "longxiaochun",
"format": "MP3_16000HZ_MONO_128KBPS",
"volume": 80,
"speechRate": 1.2,
"pitchRate": 1
}
})
response = requests.request("POST", url, headers=headers, data=payload)
for chunk in response.iter_lines(decode_unicode=True):
with open("output.mp3","ab") as f:
if chunk:
if (frame:=json.loads(chunk[5:])["audioFrame"]):
f.write(base64.b64decode(frame))非流式接口
import requests
import json
import base64
projectId = "YOUR_PROJECT_ID"
easyllmId = "YOUR_EASYLLM_SERVICE_ID"
API_KEY = "YOUR_API_KEY"
url = f"https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/voice/synthesize-audio"
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + API_KEY,
}
payload = json.dumps({
"easyllm_id": easyllmId,
"text": [
"测试",
],
"synthesis_param": {
"model": "cosyvoice-v1",
"voice": "longxiaochun",
"format": "MP3_16000HZ_MONO_128KBPS",
"volume": 80,
"speechRate": 1.2,
"pitchRate": 1
}
})
response = requests.request("POST", url, headers=headers, data=payload)
with open("output.mp3","wb") as f:
f.write(response.content)响应示例
{'status': 'accepting', 'usage': None, 'audioFrame': '{BASE64 encoded data}'}声音复刻
音色创建
请求说明
- 基本信息
功能描述:为某个服务的某个模型下创建音色,以便在Text to voice接口中使用。
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/voice/upload
请求方式:POST
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值multipart/form-data |
| Authorization | String | 是 | "Bearer" + Apikey |
- Form参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| audio_file | File | 是 | 用于创建音色的文件,建议10-20s,不得超过60s,文件不得超过10MB。 |
| tts_speaker_voice_generate_req | object | 是 | 音色创建参数。 |
| tts_speaker_voice_generate_req.easyllm_id | string | 是 | 指定服务下去创建音色。 |
| tts_speaker_voice_generate_req.model | string | 是 | 指定模型下去创建音色,支持的模型类型可参考:Text to voice。 |
| tts_speaker_voice_generate_req.name | string | 否 | 指定音色名称,能辨别不同音色即可。 |
| tts_speaker_voice_generate_req.des | string | 否 | 音色的描述。 |
| tts_speaker_voice_generate_req.prompt_text | string | 是 | 用于创建音色的音频文件中对应的文字内容。 |
- 限制:单个组织下最多能创建100个音色。
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 值 |
|---|---|---|
| status | int | 返回状态,0为成功。 |
| message | string | 返回消息。 |
| result | null | 固定为null。 |
| timestamp | int | 时间戳。 |
请求示例
import requests
from requests_toolbelt.multipart.encoder import MultipartEncoder
import json
easyllmId = "YOUR_EASYLLM_SERVICE_ID"
API_KEY = "YOUR_API_KEY"
AUDIO_FILE_NAME = ""
AUDIO_FILE_PATH = ""
AUDIO_FILE_FORMAT = "" # 例如audio/wav
PROMPT_TEXT = "YOUR_AUDIO_CONTENT"
voice_data = {
"easyllm_id": easyllmId,
"model": "cosyvoice-v1",
"name": "voice1",
"prompt_text": PROMPT_TEXT
}
# 使用MultipartEncoder更精确地控制multipart/form-data
multipart_data = MultipartEncoder(
fields={
"audio_file": (AUDIO_FILE_NAME, open(AUDIO_FILE_PATH, "rb"), AUDIO_FILE_FORMAT),
"tts_speaker_voice_generate_req": (None, json.dumps(voice_data), "application/json")
}
)
url = "https://www.sophnet.com/api/open-apis/projects/easyllms/voice/upload"
headers = {
"Authorization": f"Bearer {API_KEY}"
}
headers["Content-Type"] = multipart_data.content_type
response = requests.post(url, headers=headers, data=multipart_data)
print(response)响应示例
{
"status": 0,
"message": "请求成功",
"result": null,
"timestamp": 1765420402078
}音色查询
请求说明
- 基本信息
功能描述:查询某个服务的某个模型下所有可用音色,以便在Text to voice接口中使用。
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/voice/{easyllmId}
请求方式:GET
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| easyllmId | String | 是 | 服务id |
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Authorization | String | 是 | "Bearer" + Apikey |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 值 |
|---|---|---|
| status | int | 返回状态,0为成功。 |
| message | string | 返回消息。 |
| result | list | 音色列表。 |
| result[x].model | string | 音色所属模型。 |
| result[x].des | string | 音色描述。 |
| result[x].name | string | 音色名称。 |
| result[x].voice_id | string | 音色的唯一标识,用于TTS请求。 |
| result[x].bucket_name | string | 总是null。 |
| result[x].file_name | string | 总是null。 |
| result[x].last_used_at | string | 音色上次使用的时间。 |
| timestamp | int | 时间戳。 |
请求示例
import requests
easyllmId = "YOUR_EASYLLM_SERVICE_ID"
API_KEY = "YOUR_API_KEY"
url = f"https://www.sophnet.com/api/open-apis/projects/easyllms/voice/{easyllmId}"
headers = {
'Authorization': f'Bearer {API_KEY}'
}
response = requests.request("GET", url, headers=headers)
print(response.text)响应示例
{
"status": 0,
"message": "请求成功",
"result": [
{
"model": "xx",
"des": null,
"name": "xx",
"voice_id": "xx",
"bucket_name": null,
"file_name": null,
"last_used_at": "xx"
}
],
"timestamp": 1765423576409
}音色删除
请求说明
- 基本信息
功能描述:删除某个服务的某个模型下的某个可用音色,调用后音色不能在Text to voice接口中继续使用。
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/voice/remove
请求方式:DELETE
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Authorization | String | 是 | "Bearer" + Apikey |
| Content-Type | String | 是 | application/json |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| easyllm_id | string | 是 | 待删除音色所属的服务id。 |
| model | string | 是 | 待删除音色所属的模型名。 |
| voice_id | string | 是 | 待删除音色的唯一标识。 |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 值 |
|---|---|---|
| status | int | 返回状态,0为成功。 |
| message | string | 返回消息。 |
| result | null | 固定为null。 |
| timestamp | int | 时间戳。 |
请求示例
import requests
import json
easyllmId = "YOUR_EASYLLM_SERVICE_ID"
API_KEY = "YOUR_API_KEY"
VOICE_ID = "YOUR_VOICE"
MODEL = "YOUR_MODEL_NAME"
url = "https://www.sophnet.com/api/open-apis/projects/easyllms/voice/remove"
payload = json.dumps({
"easyllm_id": easyllmId,
"model": MODEL,
"voice_id": VOICE_ID
})
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {API_KEY}'
}
response = requests.request("DELETE", url, headers=headers, data=payload)
print(response.text)响应示例
{
"status": 0,
"message": "请求成功",
"result": null,
"timestamp": 1765423576409
}Text to image
创建Task
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/texttoimage/task
请求方式:POST
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer " + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| model | string | 是 | 模型,当前支持qwen-image, z-image-turbo |
| input.prompt | string | 是 | 正向提示词,用来描述生成图像中期望包含的元素和视觉特点。 |
| input.negative_prompt | string | 否 | 反向提示词,用来描述不希望在画面中看到的内容,可以对画面进行限制。支持qwen-image。 |
| parameters.size | string | 否 | 生成图像的分辨率。qwen-image目前支持1328*1328, 1664*928, 928*1664, 1472*1104, 1104*1472, 1056*1584,默认为1328*1328。z-image-turbo目前支持1024*1024, 1024*768, 768*1024, 默认值为1024*1024 |
| parameters.seed | int | 否 | 图片生成时候的种子值,如果不提供,则算法自动用一个随机生成的数字作为种子。 |
| parameters.prompt_extend | bool | 否 | 是否开启prompt智能改写。开启后会使用大模型对输入prompt进行智能改写,仅对正向提示词有效。对于较短的输入prompt生成效果提升明显,但会增加3-4秒耗时。默认值为True。仅支持qwen-image。 |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| output.taskId | string | 任务id |
| output.taskStatus | string | 任务状态,包括SUCCEEDED, FAILED, CANCELED, PENDING, SUSPENDED, RUNNING |
查询task列表
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/imagegenerator/task
请求方式:GET
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Authorization | String | 是 | "Bearer " + Apikey |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| [0].task_id | string | 任务id |
| [0].model | string | 任务模型 |
| [0].status | string | 任务状态 |
获取task结果
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/texttoimage/task/{TaskId}
请求方式:GET
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| TaskId | String | 是 | 任务id |
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer " + Apikey |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| output.taskId | string | 任务id |
| output.taskStatus | string | 任务状态,包括SUCCESSED, FAILED, CANCELED, PENDING, SUSPENDED, RUNNING |
| output.results[0].url | string | 生成的图片链接 |
请求示例
HTTP API
#!/bin/bash
# 请配置变量API_KEY
# Step 1: 发起异步请求
response=$(curl --silent --request POST 'https://www.sophnet.com/api/open-apis/projects/easyllms/texttoimage/task' \
--header "Authorization: Bearer ${API_KEY}" \
--header 'Content-Type: application/json' \
--data '{
"model": "qwen-image",
"input": {
"prompt": "奔跑的小猫"
},
"parameters": {
"size": "1328*1328",
"seed": 42,
"steps": 4
}
}')
echo
echo $response
echo
taskId=$(echo "$response" | grep -oP '(?<="taskId":")[^"]+')
if [ -z "$taskId" ]; then
echo "任务提交失败,未获取到 taskId"
exit 1
fi
echo "任务已提交,taskId: $taskId"
# Step 2: 轮询任务状态,直到完成
status="PENDING"
while [ "$status" = "PENDING" ] || [ "$status" = "RUNNING" ]; do
sleep 2
poll_response=$(curl --silent --location "https://www.sophnet.com/api/open-apis/projects/easyllms/texttoimage/task/${taskId}" \
--header "Authorization: Bearer ${API_KEY}")
status=$(echo "$poll_response" | grep -oP '(?<="taskStatus":")[^"]+')
echo "当前状态: $status"
done
echo
echo $poll_response
echo
# Step 3: 成功后下载图片
if [ "$status" = "SUCCEEDED" ]; then
image_url=$(echo "$poll_response" | grep -oP '(?<="url":")[^"]+')
if [ -n "$image_url" ]; then
echo "下载图片: $image_url"
curl --silent "$image_url" -o "${taskId}.png"
echo "图片已保存为 ${taskId}.png"
else
echo "未找到图片 URL"
fi
else
echo "任务失败,状态为: $status"
echo "完整响应: $poll_response"
fiVideo generator
创建Task
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/videogenerator/task
请求方式:POST
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer " + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| model | string | 是 | 模型名称,当前支持: - Wan2.2-T2V-A14B:文本生成视频模型- Wan2.2-I2V-A14B:图像生成视频模型 |
| content | array | 是 | 内容列表,包含生成视频所需的提示词或图像信息 |
| content[x].type | string | 是 | 内容类型,支持: - text:文本提示词- image_url:图像URL |
| content[x].text | string | 条件 | 当type=text时必填,文本提示词,用于描述期望生成的视频内容 |
| content[x].negative_prompt | string | 否 | 反向提示词,用来描述不希望在画面中看到的内容,可以对画面进行限制。 |
| content[x].image_url.url | string | 条件 | type=image_url时必填,表示图片,支持以下格式:- Base64编码:例如: data:image/jpeg;base64,{BASE64_IMG}- 公网可访问的图片URL |
| parameters.size | string | 否 | 视频分辨率,支持多种预设尺寸: - 480P: 832*480, 480*832, 640*640- 720P: 1280*720, 720*1280, 960*960, 1088*832, 832*1088- 1080P: 1920*1080, 1080*1920, 1440*1440, 1632*1248, 1248*1632 |
| parameters.duration | number | 否 | 视频时长(秒),支持: - 1:1秒- 5:5秒 |
| parameters.seed | string | 否 | 种子值(整数字符串),用于控制生成内容的随机性。取值范围:[0, 2^32-1]之间的整数。默认随机生成一个值 |
- Note: 传入的图片需满足以下条件
- 图片格式:jpeg、png、webp、bmp、tiff、gif。
- 宽高比(宽/高):在范围 (0.4, 2.5) 。
- 宽高长度(px):(300, 6000)。
- 大小:小于30MB。
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | text/plain | 直接返回taskId |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| taskId | string | 任务id |
查询task列表
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/videogenerator/task
请求方式:GET
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Authorization | String | 是 | "Bearer " + Apikey |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| [0].task_id | string | 任务id |
| [0].model | string | 任务模型 |
| [0].status | string | 任务状态 |
获取task结果
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/videogenerator/task/{TaskId}
请求方式:GET
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| TaskId | String | 是 | 任务id |
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer " + Apikey |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
说明: 所有值为null的字段将不会出现在响应中。usage对象包含用于计费的原始数据,具体计费方式请参考费用与价格文档。
| 名称 | 类型 | 描述 |
|---|---|---|
| id | string | 任务UUID(内部标识) |
| model | string | 使用的模型名称 |
| status | string | 任务状态,包括queued, running, cancelled, succeeded, failed |
| content | object | 生成内容(任务成功时返回) |
| content.video_url | string | 生成的视频链接 |
| usage | object | 计费原始数据(任务完成后返回) |
| usage.duration | int | 视频时长(秒) |
| usage.resolution | string | 视频分辨率(如720p、832*480) |
| usage.video_count | int | 视频数量 |
| usage.ratio | string | 视频宽高比(如16:9) |
| created_at | int | 任务创建时间(Unix时间戳,秒) |
| updated_at | int | 任务更新时间(Unix时间戳,秒) |
取消Task
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/videogenerator/task/{taskId}
请求方式:DELETE
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| taskId | String | 是 | 待取消的任务id |
- Header参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Authorization | String | 是 | "Bearer " + Apikey |
(DELETE 无请求体,本接口不需要 Content-Type 和 Body)
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json | 返回 JSON 格式数据 |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| success | bool | 是否取消成功 |
| taskId | string | 请求取消的任务id |
| message | string | 文本说明,描述取消结果/失败原因 |
示例响应:
{
"success": true,
"taskId": "a2b9f8c0-1234-4d8f-9b22-9a82f0c9c001",
"message": "任务取消成功"
}请求示例
HTTP API
#!/bin/bash
# 请配置变量API_KEY
# Step 1: 提交任务
response=$(curl -s -X POST 'https://www.sophnet.com/api/open-apis/projects/easyllms/videogenerator/task' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${API_KEY}" \
-d '{
"model": "Wan2.2-T2V-A14B",
"content": [
{
"type": "text",
"text": "旋转镜头,小猫在草原上奔跑"
}
],
"parameters": {
"size": "1280*720",
"watermark": true,
"seed": 16
}
}')
echo
echo $response
echo
taskId=$response
if [ -z "$taskId" ]; then
echo "任务提交失败,未获取到任务 ID"
exit 1
fi
echo "任务已提交,ID: $taskId"
# Step 2: 轮询状态
status="queued"
while [[ "$status" == "queued" || "$status" == "running" ]]; do
sleep 2
poll_response=$(curl -s -X GET "https://www.sophnet.com/api/open-apis/projects/easyllms/videogenerator/task/${taskId}" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${API_KEY}")
status=$(echo "$poll_response" | grep -oP '(?<="status":")[^"]+')
echo "当前状态: $status"
done
echo
echo $poll_response
echo
# Step 3: 下载视频
if [ "$status" == "succeeded" ]; then
video_url=$(echo "$poll_response" | grep -oP '(?<="video_url":")[^"]+')
if [ -n "$video_url" ]; then
echo "下载视频: $video_url"
curl -s "$video_url" -o "${taskId}.mp4"
echo "视频已保存为 ${taskId}.mp4"
else
echo "任务成功但未获取到视频链接"
fi
else
echo "任务失败,状态: $status"
echo "完整响应: $poll_response"
fiImage OCR
请求说明
- 基本信息
功能描述:图片OCR服务。发送图片,输出图片中的文本信息。
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/image-ocr
请求方式:POST
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer" + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| model | string | 是 | 使用的模型,可选PaddleOCR-VL-0.9B或者DeepSeek-OCR |
| prompt | string | 否 | 模型prompt参数,仅支持DeepSeek-OCR,默认值为<image>\nFree OCR. |
| type | string | 是 | 图片类型,固定为"image_url" |
| image_url | object | 是 | 图片参数 |
| image_url.url | string | 是 | 图片,可以是base64图片,固定格式为"data:image/jpeg;base64,{base64_data}";也可以是图片url链接 |
| prettify_markdown | bool | 否 | 是否输出美化后的 Markdown 文本。默认为 true。 |
| show_formula_number | bool | 否 | 输出的 Markdown 文本中是否包含公式编号。默认为 false。 |
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 值 |
|---|---|---|
| status | int | 0表示成功,其他值表示失败 |
| message | string | 调用成功返回请求成功,否则返回错误信息 |
| result | array(object) | 返回的结果,有一个个的段落组成,如果是use_html_out我1,则list的长度为1,有每个段落包含以下字段 |
| result[0].label | string | 段落的类型,可以是text,table,html等 |
| result[0].texts | string | 段落的文本 |
| result[0].position | array(int) | 段落的位置,格式为left,top,right,bottom |
| markdown.text | string | 返回的Markdown文本,如果prettifyMarkdown为true,则会美化Markdown文本,如果showFormulaNumber为true,则会在Markdown文本中包含公式编号 |
请求示例
HTTP API
curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/easyllms/image-ocr' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"model": "PaddleOCR-VL-0.9B",
"type":"image_url",
"image_url": {
"url": "data:image/jpeg;base64,/9j/..."
},
"prettify_markdown": true,
"show_formula_number": false
}'响应示例
{
"status":0,
"message":"请求成功",
"result": [
{
"label": "text",
"texts": "测试",
"position": "0,0,720,1920"
}
],
"markdown": {"text":"测试"}
}Image Edit
请求说明
- 基本信息
功能描述:图像编辑服务。支持多图编辑,可通过文本描述对图像进行编辑操作。
请求地址:https://www.sophnet.com/api/open-apis/projects/easyllms/image-edit
请求方式:POST
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer" + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| model | string | 是 | 使用的模型,当前仅支持Qwen-Image-Edit-2509 |
| input | object | 是 | 输入内容 |
| input.messages | array | 是 | 消息列表 |
| input.messages[].role | string | 是 | 角色,固定为"user" |
| input.messages[].content | array | 是 | 内容列表,可包含多个图片和文本 |
| input.messages[].content[].image | string | 否 | 图片URL(当类型为图片时) |
| input.messages[].content[].text | string | 否 | 文本描述(当类型为文本时) |
| parameters | object | 否 | 可选参数 |
| parameters.seed | integer | 否 | 随机数种子,取值范围[0,2147483647],用于控制生成结果的可重复性 |
| parameters.negative_prompt | string | 否 | 负向提示词,描述不希望在生成结果中出现的内容 |
| parameters.watermark | boolean | 否 | 是否添加水印,默认为false |
注意:
Qwen-Image-Edit-2509模型仅支持输出1张图片,系统会自动强制设置n=1- 支持多图输入,可以在content中包含多个image对象
- 必须包含至少一个text对象来描述编辑需求
响应说明
- 响应头参数
| 名称 | 值 | 描述 |
|---|---|---|
| Content-Type | application/json |
- 响应体参数
| 名称 | 类型 | 描述 |
|---|---|---|
| output | object | 输出结果 |
| output.choices | array | 选项列表 |
| output.choices[].finish_reason | string | 完成原因,正常完成为"stop" |
| output.choices[].message | object | 消息对象 |
| output.choices[].message.role | string | 角色,固定为"assistant" |
| output.choices[].message.content | array | 内容列表 |
| output.choices[].message.content[].image | string | 生成的图片URL |
| usage | object | 用量信息 |
| usage.width | integer | 图片宽度(像素) |
| usage.height | integer | 图片高度(像素) |
| usage.image_count | integer | 生成的图片数量 |
| request_id | string | 请求ID |
请求示例
HTTP API
curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/easyllms/image-edit' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
"model": "Qwen-Image-Edit-2509",
"input": {
"messages": [
{
"role": "user",
"content": [
{
"image": "https://example.com/image1.png"
},
{
"image": "https://example.com/image2.png"
},
{
"text": "图1中的女生穿着图2中的黑色裙子"
}
]
}
]
},
"parameters": {
"seed": 42,
"negative_prompt": " ",
"watermark": false
}
}'响应示例
{
"output": {
"choices": [
{
"finish_reason": "stop",
"message": {
"role": "assistant",
"content": [
{
"image": "https://www.sophnet.com/api/oss-images/3/result.png"
}
]
}
}
]
},
"usage": {
"width": 1248,
"image_count": 1,
"height": 832
},
"request_id": "bf37ca26-0abe-98e4-8065-xxxxxx"
}Chat completions + Text to voice
请求说明
- 基本信息
请求地址:https://www.sophnet.com/api/open-apis/v1/chat/completions-with-voice-output
请求方式:POST
- Header参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Content-Type | String | 是 | 固定值application/json |
| Authorization | String | 是 | "Bearer" + Apikey |
- Body参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| chat_completion_req | dict | 是 | 包含Chat completions的参数 |
| speech_synthesis_req | dict | 是 | 包含Text to voice的部分参数 |
chat_completion_req参数:参考Chat completions章节,仅支持流式
speech_synthesis_req参数:仅支持流式
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| synthesis_param | dict | 否 | 转语音参数 |
| synthesis_param.model | string | 否 | 指定模型,默认值为"cosyvoice-v1" |
| synthesis_param.voice | string | 否 | 指定音色,默认值为"longxiaochun",支持longwan/longcheng/longhua/longxiaochun/longxiaoxia/longxiaocheng/longxiaobai/longlaotie/longshu/longshuo/longjing/longyue/loongstella/loongbella |
| synthesis_param.format | string | 否 | 指定音频编码格式及采样率,格式为"文件格式_采样率_通道_比特率",例如MP3_16000HZ_MONO_128KBPS代表音频格式为mp3,采样率为16kHz。若未指定format,系统将根据voice参数自动选择该音色的推荐格式。 |
| synthesis_param.volume | number | 否 | 指定音量,默认值为50,取值范围:[0-100] |
| synthesis_param.speechRate | number | 否 | 指定语速,默认值为1,输入范围:[0.5,2] |
| synthesis_param.pitchRate | number | 否 | 指定语调,默认值为1,取值范围:[0.5,2] |
| easyllm_id | string | 是 | Easyllm ID |
响应说明
基本信息:会返回两类消息,分别是Chat completions响应消息和Text to voice响应消息
Chat completions响应说明:参考Chat completions章节
Text to voice响应说明
| 名称 | 类型 | 值 |
|---|---|---|
| audioFrame | dict | 语音数据结果 |
| audioFrame.array | String | Base64编码的音频数据 |
| status | String | 目前服务状态 |
请求示例
示例如下,请将参数示例值替换为实际值。
- curl请求示例
curl --location --request POST 'https://www.sophnet.com/api/open-apis/v1/chat/completions-with-voice-output' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer $API_KEY' \
--data-raw '{
"chat_completion_req": {
"messages": [
{
"role": "user",
"content": "你好"
}
],
"model":"Qwen2.5-32B-Instruct",
"stream": true
},
"speech_synthesis_req": {
"easyllm_id": "${easyllm_id}"
}
}'响应示例
{"choices": [{"delta": {"content": "", "role": "assistant"},"index": 0}],"created": 1749037853,"id": "chatcmpl-xxx","model": "Qwen2.5-32B-Instruct","object": "chat.completion.chunk"}
{"choices":[{"delta":{"content":"你好"},"index":0}],"created":1749037853,"id":"chatcmpl-xxx","model":"Qwen2.5-32B-Instruct","object":"chat.completion.chunk"}
{"choices":[{"delta":{"content":"!"},"index":0}],"created":1749037853,"id":"chatcmpl-xxx","model":"Qwen2.5-32B-Instruct","object":"chat.completion.chunk"}
{"choices":[{"delta":{"content":"有什么"},"index":0}],"created":1749037853,"id":"chatcmpl-xxx","model":"Qwen2.5-32B-Instruct","object":"chat.completion.chunk"}
{"status":"accepting","usage":null,"audioFrame":"SUQzBAAA..."}
{"choices":[{"delta":{"content":"可以帮助你的吗?"},"index":0}],"created":1749037853,"id":"chatcmpl-xxx","model":"Qwen2.5-32B-Instruct","object":"chat.completion.chunk"}
{"status":"accepting","usage":null,"audioFrame":null}
{"status":"accepting","usage":null,"audioFrame":"//PCxO1..."}
{"choices":[{"delta":{"content":""},"finish_reason":"stop","index":0}],"created":1749037853,"id":"chatcmpl-xxx","model":"Qwen2.5-32B-Instruct","object":"chat.completion.chunk"}
{"status":"accepting","usage":null,"audioFrame":"//PAxPJh..."}
{"status":"finish","usage":{"characters":26},"audioFrame":null}
...语音对话
上行事件
连接请求事件说明
- 基本信息
请求地址:wss://www.sophnet.com/api/open-apis/projects/{ProjectId}/chat/speech-chat
请求方式:Websocket
- Path参数:
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| ProjectId | String | 是 | 项目id |
- Request参数
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| token | String | 是 | 包含“Bearer ”前缀,后跟Apikey |
| model | String | 是 | Chat completions服务的模型名 |
| asr_easyllm_id | String | 是 | Speech to text服务的easyllm id |
| tts_easyllm_id | String | 是 | Text to voice服务的easyllm id |
对话配置更新事件说明
事件类型:chat.update
事件说明:该事件发生在获得连接请求响应后,可选地更新对话配置,在执行流式上传音频片段前,可更新多次,之后将不能更新。若不更新则使用默认参数。仅支持流式
参数说明:字段
create_transcription_task_req、chat_completion_with_voice_output_req.chat_completion_req和chat_completion_with_voice_output_req.speech_synthesis_req必须设置,其内容为空则所有字段使用默认参数,若部分字段为空则未设置的字段将使用默认值。默认参数:
{
"create_transcription_task_req": {
"heartbeat": false,
"speech_recognition_param": {
"sample_rate": 16000,
"format": "wav"
}
},
"chat_completion_with_voice_output_req": {
"chat_completion_req": {
"messages": [],
"model": "${model参数}",
"stream": true
},
"speech_synthesis_req": {
"stream": true,
"synthesis_param": {
"model": "cosyvoice-v1",
"voice": "longxiaochun",
"format": "MP3_22050HZ_MONO_256KBPS"
}
}
},
"asr_mode": "online"
}- 事件消息结构:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event_type | String | 是 | 事件类型,固定为chat.update |
| message | String | 是 | 配置参数JSON字符串,格式{"create_transcription_task_req": {可参考流式Speech to text中Request参数说明}, "chat_completion_with_voice_output_req": {可参考Chat completions + Text to voice中Body参数说明}, "asr_mode": asr加载模式} |
| message.asr_mode | String | 否 | 目前支持三种:"online"/"refresh"/"dynamic",默认为"online"模式。"refresh"模式指每次执行llm+tts时清空asr音频缓存,并继续监听,对于输入截断的音频建议开启,"online"模式指总是开启ASR,对于连续音频流建议开启,"dynamic"模式指动态开启ASR,在LLM+TTS推理开始时会关闭,在下一次传递bytes音频数据的时候会自动开启。 |
流式上传音频片段
事件说明:该事件发生后对话配置不允许再被更新,并将根据
heartbeat设置的参数判断超时,超时将关闭连接。事件消息结构:二进制音频数据块,可按照100ms、200ms传输,根据实际情况调整。
音频提交事件说明
事件类型:input_audio_buffer.complete
事件说明:该事件发生后将停止ASR,并将ASR识别结果作为LLM输入,转为LLM+TTS推理。
事件消息结构:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event_type | String | 是 | 事件类型,固定为input_audio_buffer.complete |
音频缓存清理事件说明
事件类型:input_audio_buffer.clear
事件说明:该事件发生后将清空ASR服务的音频缓存bytes数据(可能会发送一条ASR识别结果),并清空已识别结果。若在未发送过音频bytes数据情况下执行该事件,将报错。
事件消息结构:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event_type | String | 是 | 事件类型,固定为input_audio_buffer.clear |
上下文清理事件说明
事件类型:conversation.clear
事件说明:该事件发生后将清理之前的LLM上下文记录,但对话配置更新事件设置的上下文不会被清理。
事件消息结构:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event_type | String | 是 | 事件类型,固定为conversation.clear |
打断事件说明
事件类型:conversation.chat.cancel
事件说明:该事件发生后将中断LLM+TTS推理,并转为ASR。
事件消息结构:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event_type | String | 是 | 事件类型,固定为conversation.chat.cancel |
心跳事件说明
事件类型:ping
事件说明:需要定时发送该消息,如果超过60s,将关闭连接。
事件消息结构:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| event_type | String | 是 | 事件类型,固定为ping |
下行事件
连接请求事件响应
事件类型:chat.created
事件说明:需要等连接响应返回后才能执行其他事件。
响应体参数
| 参数 | 类型 | 说明 |
|---|---|---|
| event_type | String | 事件类型,固定为chat.created |
| status | int | 事件状态,0表示成功,非0表示失败 |
| message | String | 失败原因说明 |
对话配置更新事件响应
事件类型:chat.updated
响应体参数
| 参数 | 类型 | 说明 |
|---|---|---|
| event_type | String | 事件类型,固定为chat.updated |
| status | int | 事件状态,0表示成功,非0表示失败 |
| message | String | 失败原因说明 |
增量音频识别结果响应
事件说明:流式返回音频识别结果。
响应体参数:参考流式Speech to text中返回响应
音频提交事件响应
事件类型:input_audio_buffer.completed
响应体参数
| 参数 | 类型 | 说明 |
|---|---|---|
| event_type | String | 事件类型,固定为input_audio_buffer.completed |
| status | int | 事件状态,0表示成功,非0表示失败 |
| message | String | 失败原因说明 |
音频缓存清空事件响应
事件类型:input_audio_buffer.cleared
响应体参数
| 参数 | 类型 | 说明 |
|---|---|---|
| event_type | String | 事件类型,固定为input_audio_buffer.cleared |
| status | int | 事件状态,0表示成功,非0表示失败 |
| message | String | 失败原因说明 |
上下文清理事件响应
事件类型:conversation.cleared
响应体参数
| 参数 | 类型 | 说明 |
|---|---|---|
| event_type | String | 事件类型,固定为conversation.cleared |
| status | int | 事件状态,0表示成功,非0表示失败 |
| message | String | 失败原因说明 |
打断事件响应
事件类型:conversation.chat.canceled
响应体参数
| 参数 | 类型 | 说明 |
|---|---|---|
| event_type | String | 事件类型,固定为conversation.chat.canceled |
| status | int | 事件状态,0表示成功,非0表示失败 |
| message | String | 失败原因说明 |
增量LLM+TTS推理结果响应
事件说明:流式返回LLM和TTS推理结果。
响应体参数:参考Chat completions + Text to voice中返回响应
当次对话完成响应
事件类型:conversation.chat.completed
事件说明:在LLM+TTS正常推理结束、发生错误或被打断,则该消息会被返回,将开启ASR。
响应体参数
| 参数 | 类型 | 说明 |
|---|---|---|
| event_type | String | 事件类型,固定为conversation.chat.completed |
| status | int | 固定为0 |
| message | String | 固定为空 |
心跳事件响应
事件类型:pong
响应体参数
| 参数 | 类型 | 说明 |
|---|---|---|
| event_type | String | 事件类型,固定为pong |
| status | int | 事件状态,0表示成功,非0表示失败 |
| message | String | 失败原因说明 |
错误响应
事件类型:error
事件说明:其他错误,例如请求参数或运行时错误。
响应体参数
| 参数 | 类型 | 说明 |
|---|---|---|
| event_type | String | 事件类型,固定为error |
| status | int | 非0 |
| message | String | 错误原因说明 |
请求/响应示例
连接请求示例
- 连接请求
const url = `wss://www.sophnet.com/api/open-apis/projects/{ProjectId}/chat/speech-chat`
+ `?model=${model}`
+ `&token=Bearer ${apikey}`
+ `&asr_easyllm_id=${asr_easyllm_id}`
+ `&tts_easyllm_id=${tts_easyllm_id}`;
ws = new WebSocket(url);
ws.onopen = () => {
log('WebSocket 已连接: ' + url);
};
ws.onmessage = (evt) => {
log('<- RESULT: ' + evt.data);
};
ws.onerror = (err) => {
log('WebSocket 错误: ' + err);
};
ws.onclose = (evt) => {
log(`WebSocket 已关闭: [${evt.code}] ${evt.reason}`);
};- 连接响应
{"status":0,"message":"","event_type":"chat.created"}对话配置更新示例
- 对话配置更新请求
ws.send('{"event_type":"chat.update","message":"{\\"create_transcription_task_req\\":{\\"service_uuid\\":\\"\\"},\\"chat_completion_with_voice_output_req\\":{\\"chat_completion_req\\":{\\"messages\\":[{\\"role\\":\\"system\\",\\"content\\":\\"你是人工智能助手。\\"}],\\"model\\":\\"\\",\\"stream\\":true},\\"speech_synthesis_req\\":{\\"service_id\\":\\"\\"}}}"}');- 对话配置更新响应
{"status":0,"message":"","event_type":"chat.updated"}流式上传音频片段示例
Websocket API
ws.send(byteData);ASR结果、LLM结果、TTS结果响应示例
可分别参考流式Speech to text和Chat completions + Text to voice中的返回示例。
