模型
控制台
文档
试验场
模型
控制台
文档
试验场
  • 概览

    • 简介
    • 快速开始
    • 更新日志
    • 费用与价格
  • API使用

    • API使用
  • 最佳实践

    • 智能体
    • function call
    • MCP使用案例
  • 项目管理

    • 创建或加入组织
    • 创建项目
    • 选择服务
    • 设置API Key
  • 试验场

    • 如何进入试验场
    • Chat
  • 热门工具接入

    • ARGO
    • Dify
    • Bob翻译
    • ChatGPT Box
    • 沉浸式导读
    • 沉浸式翻译
    • 馆长
    • 划词翻译
    • 流畅阅读
    • Cursor
    • Chatbox
    • ChatGPT-Next-Web
    • Cherry Studio
    • Easydict
    • Enconvo
    • Pal - AI Chat Client
    • RSS翻译器
    • 思源笔记
    • ToMemo
    • Cline
    • AI-commit

API使用

Chat completions

请求说明

  • 基本信息

请求地址:https://www.sophnet.com/api/open-apis/v1/chat/completions

请求方式:POST

  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey
  • Body参数
名称类型必填描述
messagesarray(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"}}]}]}}
modelstring是模型
toolsarray否工具列表,只支持function,支持的模型有DeepSeek-R1,DeepSeek-v3
streambool否是否以流式接口的形式返回数据,默认false
max_tokensinteger否模型回复最大长度(单位 token)
temperaturenumber否较高的数值会使输出更加随机,而较低的数值会使其更加集中。默认值1.0,取值范围[0,2.0]。支持的模型有DeepSeek-Prover-V2, DeepSeek-V3-Fast, DeepSeek-V3, Qwen全系列
top_pnumber否影响输出文本的多样性,取值越大,生成文本的多样性越强。默认值1.0。支持的模型有DeepSeek-Prover-V2, DeepSeek-V3-Fast, DeepSeek-v3, Qwen全系列
stoparray(string)否停止生成更多Tokens的最多4个字符串。支持的模型有DeepSeek-Prover-V2, DeepSeek-V3-Fast, DeepSeek-v3, Qwen全系列
presence_penaltynumber否通过对已生成的token增加惩罚,减少重复生成的现象。默认值0,取值范围:[-2.0, 2.0]。支持的模型有DeepSeek-Prover-V2, DeepSeek-V3-Fast, DeepSeek-v3, Qwen全系列
frequency_penaltynumber否根据新词在当前文本中的频率进行惩罚,降低模型逐字重复同一行的可能性。 默认值0,取值范围:[-2.0, 2.0]。支持的模型有DeepSeek-Prover-V2, DeepSeek-V3-Fast, DeepSeek-v3
logprobsboolean否默认值false。是否返回输出 tokens 的对数概率。支持的模型有DeepSeek-Prover-V2, DeepSeek-V3-Fast, DeepSeek-v3
top_logprobsinteger否默认值0,取值范围为 [0, 20]。指定每个输出 token 位置最有可能返回的 token 数量,每个 token 都有关联的对数概率。仅当 logprobs为true 时可以设置 top_logprobs 参数。支持的模型有DeepSeek-Prover-V2, DeepSeek-V3-Fast, DeepSeek-v3
response_formatobject否指定模型必须输出的格式的对象。
默认值: { "type": "text" }
设置为 { "type": "json_object" } 可启用 JSON 模式,这保证模型生成的消息是有效的 JSON。
重要:使用 JSON 模式时,您还必须通过系统或用户消息提示模型自行生成JSON。支持的模型有DeepSeek-R1-0528,DeepSeek-v3

响应说明

  • 响应头参数
名称值描述
Content-Type流式:text/event-stream非流式:application/json
  • 响应体参数

a.非流式

名称类型描述
objectstring回包类型 chat.completion.chunk:多轮对话返回
createdint时间戳
modelstring模型
示例值:Qwen/Qwen2.5-72B-Instruct
choicesarray
choices[0].indexint索引
choices[0].finish_reasonstring结束原因 正常结束:stop,token超长截断结束:length
choices[0].messageobject模型回答
choices[0].message.tool_callsarray工具列表
choices[0].message.tool_calls[0].functionobject函数调用信息
choices[0].refsarray引用列表,调用自定义模型且模型输出包含文档引用时存在。在非流式调用中,会在最终结果内输出此次回答包含的所有引用来源信息。
choices[0].refs[0].indexint引用来源出现顺序
choices[0].refs[0].titlestring引用数据标题
choices[0].refs[0].contentstring引用数据内容
choices[0].refs[0].typestring引用数据类型,file/qa/web, 分别代表文件知识, Q&A Table和web搜索
choices[0].refs[0].urlstring引用数据url,其中,file和qa数据url访问需配置apikey,web数据url访问无需配置apikey

b.流式

名称类型描述
objectstring回包类型 chat.completion.chunk:多轮对话返回
createdint时间戳
modelstring模型
示例值:Qwen/Qwen2.5-72B-Instruct
choicesarray
choices[0].indexint索引
choices[0].finish_reasonstring结束原因 正常结束:stop,token超长截断结束:length
choices[0].deltaobject模型回答
choices[0].refsarray引用列表,调用自定义模型且模型输出包含文档引用时存在。在流式响应过程中,会实时于存在引用的位置输出引用来源信息,并在finish_reason不为空时输出此次回答包含的所有引用来源信息。
choices[0].refs[0].indexint引用来源出现顺序
choices[0].refs[0].titlestring引用数据标题
choices[0].refs[0].contentstring引用数据内容
choices[0].refs[0].typestring引用数据类型,file/qa/web, 分别代表文件知识, Q&A Table和web搜索
choices[0].refs[0].urlstring引用数据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参数:
名称类型必填描述
ProjectIdString是项目id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey
  • Body参数
名称类型必填描述
audio_urlstring是语音url路径
支持音频格式:wav、mp3、m4a、flv、mp4、wma、3gp、amr、aac、ogg-opus、flac
音频限制:音频 URL 时长不能大于5小时,文件大小不超过1GB
识别有效时间:识别结果在服务端保存24小时
easyllm_idstring是Easyllm ID

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型描述
task_idstring任务id
createdint时间戳

请求示例

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"
}'

响应示例

{
    "taskId": "10047816884",
    "created": 1724652804
}

查询Task状态、结果

请求说明

  • 基本信息

请求地址:https://www.sophnet.com/api/open-apis/projects/{project_id}/easyllms/speechtotext/transcriptions/{taskId}

请求方式:GET

  • Path参数:
名称类型必填描述
project_idString是项目id
task_idString是语音转文本task_id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey
  • Body参数

无

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型描述
task_idstring任务id
statusstring任务状态,waiting:任务等待,doing:任务执行中,success:任务成功,failed:任务失败。
示例值:waiting
resultstring转录结果
errorMsgstring错误码

请求示例

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参数:
名称类型必填描述
ProjectIdString是项目id
  • Request参数
名称类型必填描述
easyllm_idString是easyllm id
apikeyString是Apikey
formatString是输入音频格式,支持pcm、wav、mp3、aac
sample_rateint是音频采样率,任意音频采样率,但16k效果更好
heartbeatbool是是否开启心跳,若为false即使发送静音音频也会在60s后超时关闭连接,若为true,发送静音音频将保持连接

音频数据发送请求说明

  • 音频数据发送说明:音频bytes数据,可按照3200的数量发送。

关闭连接请求说明

  • 关闭连接请求说明:发送一个字符串"BYE"来主动关闭连接。

连接响应说明

  • 响应体参数
名称类型描述
statusstring连接成功返回'ok',失败则直接关闭连接

音频识别结果响应说明

  • 响应体参数
名称类型描述
textstring句子级识别结果,当is_sentence_end为false时,包含流式识别的输出结果,而为true则表示最终句子识别结果,下一个消息将是新的句子
begin_timeint句子开始的时刻,单位为毫秒
end_timeint句子结束的时刻,单位为毫秒
wordsstring字级别的预测结果
is_sentence_endbool表示句子是否结束

连接请求示例

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}

Embeddings

请求说明

  • 基本信息

请求地址:https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/embeddings

请求方式:POST

  • Path参数:
名称类型必填描述
ProjectIdString是项目id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey
  • Body参数
名称类型必填描述
input_textsarray(string)是数组中每一个元素是一个文本,最大支持10个文本,每个文本最大8192个Tokens
dimensionsinteger是输出Embeddings的维度,支持1,024/768/512/256/128/64
easyllm_idstring是Easyllm ID

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型描述
idstring任务id
usagedict模型推理时Token使用情况
dataarray模型推理结果

请求示例

HTTP API

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
}'

响应示例

{
    "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"
        }
    ]
}

Document Parse

请求说明

  • 基本信息

功能描述:高效转换主流格式文档至精准、易用的Markdown文本内容。上传文件(form-data),输出文档内容(Markdown)

请求地址:https://www.sophnet.com/api/open-apis/projects/{ProjectId}/easyllms/doc-parse

请求方式:POST

  • Path参数:
名称类型必填描述
ProjectIdString是项目id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey
  • form-data参数
名称类型必填描述
filefile是文档,支持pdf,docx,doc,xlsx,xls,txt,ppt,pptx格式,大小<50MB
easyllm_idstring是Easyllm ID

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
datastring文档解析结果(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: application/json" \
--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

请求说明

  • 基本信息

功能描述:文字转语音服务。发送文件,输出语音(默认为mp3格式)。

请求地址:https://www.sophnet.com/api/open-apis/projects/{ProjectId}/easyllms/voice/synthesize-audio-stream

请求方式:POST

  • Path参数:
名称类型必填描述
ProjectIdString是项目id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey
  • Body参数
名称类型必填描述
textarray(string)是需要转语音的字符串列表
streambool否是否使用流式接口,默认值为true
synthesis_paramobject是转语音参数
synthesis_param.modelstring是指定模型,默认值为"cosyvoice-v1"
synthesis_param.voicestring否指定音色,默认值为"longxiaochun"
synthesis_param.formatstring否指定音频编码格式及采样率,格式为"文件格式_采样率_通道_比特率",例如MP3_16000HZ_MONO_128KBPS代表音频格式为mp3,采样率为16kHz。若未指定format,系统将根据voice参数自动选择该音色的推荐格式。
synthesis_param.volumenumber否指定音量,默认值为50,取值范围:[0-100]
synthesis_param.speechRatenumber否指定语速,默认值为1,输入范围:[0.5,2]
synthesis_param.pitchRatenumber否指定语调,默认值为1,取值范围:[0.5,2]
easyllm_idstring是Easyllm ID

响应说明

  • 响应头参数
名称值描述
Content-Typetext/event-stream
  • 响应体参数
名称类型值
datastringbase64编码的语音数据

请求示例

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"

payload = json.dumps({
   "easyllm_id": easyllmId,
   "text": [
       "测试",
   ],
   "synthesis_param": {
       "model": "cosyvoice-v1",
       "voice": "longxiaochun",
       "format": "WAV_16000HZ_MONO_16BIT",
       "volume": 80,
       "speechRate": 1.2,
       "pitchRate": 1
   }
})

headers = {
   'Content-Type': 'application/json',
   'Authorization': 'Bearer ' + API_KEY,
}

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))

响应示例

{'status': 'accepting', 'usage': None, 'audioFrame': '{BASE64 encoded data}'}

Image OCR

请求说明

  • 基本信息

功能描述:图片OCR服务。发送图片,输出图片中的文本信息。

请求地址:https://www.sophnet.com/api/open-apis/projects/{ProjectId}/easyllms/image-ocr

请求方式:POST

  • Path参数:
名称类型必填描述
ProjectIdString是项目id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey
  • Body参数
名称类型必填描述
typestring是图片类型,固定为"image_url"
image_urlobject是图片参数
image_url.urlstring是图片,可以是base64图片,固定格式为"data:image/jpeg;base64,{base64_data}";也可以是图片url链接
use_doc_oriint是是否使用文档方向分类,1表示使用,0表示不使用
use_tableint是是否使用表格识别,1表示使用,0表示不使用;此项为1时use_html_out必须为1
use_html_outint是是否使用html输出,1表示使用,0表示不使用;使用表格识别时,此项必须为1
easyllm_idstring是Easyllm ID

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
statusint0表示成功,其他值表示失败
messagestring调用成功返回请求成功,否则返回错误信息
resultarray(object)返回的结果,有一个个的段落组成,如果是use_html_out我1,则list的长度为1,有每个段落包含以下字段
result[0].labelstring段落的类型,可以是text,table,html等
result[0].textsstring段落的文本
result[0].positionarray(int)段落的位置,格式为left,top,right,bottom

请求示例

HTTP API

curl --location --request POST 'https://www.sophnet.com/api/open-apis/projects/{projectId}/easyllms/image-ocr' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
    "easyllm_id": "YOUR_SERVICE_ID",
    "type":"image_url",
    "image_url": {
            "url": "data:image/jpeg;base64,/9j/..."
    },
    "use_doc_ori": 1,
    "use_table":1,
    "use_html_out":1
}'

响应示例

{
    "status":0,
    "message":"请求成功",
    "result": [
        {
            "label": "text",
            "texts": "测试",
            "position": "0,0,720,1920"
        }
    ]
}

Chat completions + Text to voice

请求说明

  • 基本信息

请求地址:https://www.sophnet.com/api/open-apis/v1/chat/completions-with-voice-output

请求方式:POST

  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey
  • Body参数
名称类型必填描述
chat_completion_reqdict是包含Chat completions的参数
speech_synthesis_reqdict是包含Text to voice的部分参数
  • chat_completion_req参数:参考Chat completions章节,仅支持流式

  • speech_synthesis_req参数:仅支持流式

名称类型必填描述
synthesis_paramdict否转语音参数
synthesis_param.modelstring否指定模型,默认值为"cosyvoice-v1"
synthesis_param.voicestring否指定音色,默认值为"longxiaochun",支持longwan/longcheng/longhua/longxiaochun/longxiaoxia/longxiaocheng/longxiaobai/longlaotie/longshu/longshuo/longjing/longyue/loongstella/loongbella
synthesis_param.formatstring否指定音频编码格式及采样率,格式为"文件格式_采样率_通道_比特率",例如MP3_16000HZ_MONO_128KBPS代表音频格式为mp3,采样率为16kHz。若未指定format,系统将根据voice参数自动选择该音色的推荐格式。
synthesisParam.volumenumber否指定音量,默认值为50,取值范围:[0-100]
synthesisParam.speechRatenumber否指定语速,默认值为1,输入范围:[0.5,2]
synthesisParam.pitchRatenumber否指定语调,默认值为1,取值范围:[0.5,2]
easyllm_idstring是Easyllm ID

响应说明

  • 基本信息:会返回两类消息,分别是Chat completions响应消息和Text to voice响应消息

  • Chat completions响应说明:参考Chat completions章节

  • Text to voice响应说明

名称类型值
audioFramestringbase64编码的语音数据

请求示例

示例如下,请将参数示例值替换为实际值。

  • 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}

...

自定义模型-文件知识

上传文件

请求说明

  • 基本信息

功能描述:为服务新增文件知识,此接口为自动注入,无需再次注入我的模型

请求地址:https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/files

请求方式:POST

  • Path参数:
名称类型必填描述
serviceIdString是服务id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey
  • form-data参数
名称类型必填描述
filefile是文档,支持pdf,docx,xlsx,txt,pptx格式,大小<30MB

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
statusstring请求状态码,0为成功
messagestring请求执行状态
resultobject执行结果
result.idstring文档id
result.titlestring文档标题
result.snippetstring文档内容片段
result.statusstring文档状态,ENABLED为已启用,NOT_ENABLED为未启用

请求示例

HTTP API

curl --location --request POST 'https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/files' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--form 'file=@"YOUR_DOCUMENT"' \
--form 'easyllm_id="YOUR_SERVICE_ID"'

响应示例

{
    "status": 0,
    "message": "请求成功",
    "result": {
        "id": "4pw0y0Foa0lNubkPUriLkA",
        "title": "你的文档标题",
        "snippet": "文档内容片段",
        "status": "ENABLED",
        "createdAt": "2025-03-17T06:21:09.175+00:00"
    },
    "timestamp": 1742192469480
}

查询服务已绑定文件列表

请求说明

  • 基本信息

功能描述:查询服务已绑定文件列表

请求地址:https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/files

请求方式:GET

  • Path参数:
名称类型必填描述
serviceIdString是服务id
  • Query参数:
名称类型必填描述
pageNumNumber否分页页数
pageSizeNumber否分页页大小
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
statusstring请求状态码,0为成功
messagestring请求执行状态
resultobject执行结果
result.pageNumnumber当前页码
result.pageSizenumber当前页面尺寸
result.sizenumber当前页面item数量
result.pagesnumber当总页数
result.totalnumber总item数量
result.listList<object>文档列表
result.list[0].idstring文档id
result.list[0].titlestring文档标题
result.list[0].snippetstring文档内容片段
result.list[0].statusstring文档状态,ENABLED为已启用,NOT_ENABLED为未启用

请求示例

HTTP API

curl --location --request GET 'https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/files?pageNum=1&&pageSize=10' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \

响应示例

{
    "status": 0,
    "message": "请求成功",
    "result": {
        "pageNum": 1,
        "pageSize": 10,
        "size": 1,
        "pages": 1,
        "total": 1,
        "list": [
            {
                "id": "4pw0y0Foa0lNubkPUriLkA",
                "title": "你的文档标题",
                "snippet": "文档内容片段",
                "status": "ENABLED",
                "createdAt": "2025-03-17T06:21:09.175+00:00"
            }
        ]
    },
    "timestamp": 1740536970407
}

获取文件详情

请求说明

  • 基本信息

功能描述:查询文件详情

请求地址:https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/files/{fileId}

请求方式:GET

  • Path参数:
名称类型必填描述
serviceIdString是服务id
fileIdString是文件id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
statusstring请求状态码,0为成功
messagestring请求执行状态
resultobject执行结果
result.idstring文档id
result.titlestring文档标题
result.contentstring文档内容
result.downloadUrlstring文档源文件下载地址

请求示例

HTTP API

curl --location --request GET 'https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/files/{fileId}' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \

响应示例

{
    "status": 0,
    "message": "请求成功",
    "result": {
        "id": "4pw0y0Foa0lNubkPUriLkA",
        "title": "你的文档标题",
        "content": "文档内容",
        "downloadUrl": "下载地址",
        "createdAt": "2025-03-17T06:21:09.175+00:00"
    },
    "timestamp": 1742192469480
}

删除文件

请求说明

  • 基本信息

功能描述:删除服务中的指定文件

请求地址:https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/files/{fileId}

请求方式:DELETE

  • Path参数:
名称类型必填描述
serviceIdString是服务id
fileIdString是文件id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
statusstring请求状态码,0为成功
messagestring请求执行状态
resultobject执行结果

请求示例

HTTP API

curl --location --request DELETE 'https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/files/{fileId}' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \

响应示例

{
    "status": 0,
    "message": "请求成功",
    "timestamp": 1742192469480
}

自定义模型-Q&A Table

新增QA记录

请求说明

  • 基本信息

功能描述:为服务新增QA记录

请求地址:https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/qa-records

请求方式:POST

  • Path参数:
名称类型必填描述
serviceIdString是服务id
  • Body参数:
名称类型必填描述
questionString是QA问题,最长为200个字符
answerString是QA答案,最长为1000个字符
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
statusstring请求状态码,0为成功
messagestring请求执行状态
resultobject执行结果
result.idstringQA记录id
result.questionstringQA记录问题
result.answerstringQA记录答案

请求示例

HTTP API

curl --location --request POST 'https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/qa-records' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \
--data-raw '{
    "question": "你是谁?",
    "answer": "我是SophNet智能助手。"
}'

响应示例

{
    "status": 0,
    "message": "请求成功",
    "result": {
        "id": "79CNI1obN033Wi8mydOrZC",
        "question": "你是谁?",
        "answer": "我是SophNet智能助手。",
        "createdAt": "2025-03-14T06:23:42.194+00:00"
    },
    "timestamp": 1742192469480
}

修改QA记录

请求说明

  • 基本信息

功能描述:修改服务QA记录

请求地址:https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/qa-records/{qaId}

请求方式:POST

  • Path参数:
名称类型必填描述
serviceIdString是服务id
qaIdString是QA记录id
  • Body参数:
名称类型必填描述
questionString是QA问题,最长为200个字符
answerString是QA答案,最长为1000个字符
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
statusstring请求状态码,0为成功
messagestring请求执行状态
resultobject执行结果
result.idstringQA记录id
result.questionstringQA记录问题
result.answerstringQA记录答案

请求示例

HTTP API

curl --location --request POST 'https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/qa-records/{qaId}' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \ 
--data-raw '{
    "question": "你是谁?",
    "answer": "我是SophNet智能助手。"
}'

响应示例

{
    "status": 0,
    "message": "请求成功",
    "result": {
        "id": "79CNI1obN033Wi8mydOrZC",
        "question": "你是谁?",
        "answer": "我是SophNet智能助手。",
        "createdAt": "2025-03-14T06:23:42.194+00:00"
    },
    "timestamp": 1742192469480
}

查询服务已绑定QA记录列表

请求说明

  • 基本信息

功能描述:查询服务已绑定QA记录列表

请求地址:https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/qa-records

请求方式:GET

  • Path参数:
名称类型必填描述
serviceIdString是服务id
  • Query参数:
名称类型必填描述
pageNumNumber否分页页数
pageSizeNumber否分页页大小
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
statusstring请求状态码,0为成功
messagestring请求执行状态
resultobject执行结果
result.pageNumnumber当前页码
result.pageSizenumber当前页面尺寸
result.sizenumber当前页面item数量
result.pagesnumber当总页数
result.totalnumber总item数量
result.listList<object>QA记录文档列表
result.list[0].idstringQA记录文档id
result.list[0].questionstringQA记录文档问题
result.list[0].answerstringQA记录文档答案

请求示例

HTTP API

curl --location --request POST 'https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/qa-records?pageNum=1&&pageSize=10' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json" \

响应示例

{
    "status": 0,
    "message": "请求成功",
    "result": {
        "pageNum": 1,
        "pageSize": 10,
        "size": 1,
        "pages": 1,
        "total": 1,
        "list": [
            {
                "id": "79CNI1obN033Wi8mydOrZC",
                "question": "你是谁?",
                "answer": "我是SophNet智能助手。",
                "createdAt": "2025-03-14T06:23:42.194+00:00"
            }
        ]
    },
    "timestamp": 1740536970407
}

删除QA记录

请求说明

  • 基本信息

功能描述:删除服务中的指定QA记录

请求地址:https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/qa-records/{qaId}

请求方式:DELETE

  • Path参数:
名称类型必填描述
serviceIdString是服务id
qaIdString是QA记录id
  • Header参数
名称类型必填描述
Content-TypeString是固定值application/json
AuthorizationString是"Bearer" + Apikey

响应说明

  • 响应头参数
名称值描述
Content-Typeapplication/json
  • 响应体参数
名称类型值
statusstring请求状态码,0为成功
messagestring请求执行状态
resultobject执行结果

请求示例

HTTP API

curl --location --request DELETE 'https://www.sophnet.com/api/open-apis/service/{serviceId}/kn/qa-records/{qaId}' \
--header "Authorization: Bearer $API_KEY" \
--header "Content-Type: application/json"

响应示例

{
    "status": 0,
    "message": "请求成功",
    "timestamp": 1742192469480
}