通用对话
提供 OpenAI
兼容的对话生成接口。
请求方法
POST
请求地址
https://chat.ecnu.edu.cn/open/api/v1/chat/completions
请求参数
参数名 | 参数类型 | 是否必选 | 描述 |
---|---|---|---|
messages | array | 是 | 对话消息,以 {"role": "user", "content": "你好"} 的json 数组形式进行传参; role 的取值范围包括 system ,user , assistant 三类。 |
stream | boolean | 否 | 是否开启流式对话 |
model | string | 是 | 模型名称,目前可用 ecnu-max |
temperature | float | 否 | 温度,取值范围 0-1,默认是0.7 |
search_mode | string | 否 | 仅 ecnu-max 支持,取值范围是 disable/enable/enforce ,默认是 disable |
top_p | float | 否 | top-p ,取值范围 0-1,默认是 1 |
tools | array | 否 | function call 的调用 |
tools.type | string | 是 | 工具类型,目前固定为 function |
tools.function | object | 是 | function call 的参数 |
tools.function.name | string | 是 | function call 的名称 |
tools.function.description | string | 是 | function call 的描述 |
tools.function.parameters | object | 是 | function call 的参数,详见请求示例 |
返回参数
参数名 | 参数类型 | 描述 |
---|---|---|
id | string | 对话id |
object | string | 返回对象类型 |
created | int | 对话创建时间 |
choices | array | 对话回复 |
choices.index | int | 回复索引 |
choices.message | object | 回复消息 |
choices.message.role | string | 回复消息角色 |
choices.message.content | string | 回复消息内容 |
choices.message.tool_calls | array | function call 的调用 |
choices.message.tool_calls.id | string | function call 的id |
choices.message.tool_calls.type | string | function call 的类型 |
choices.message.tool_calls.function | object | function call 的参数 |
choices.message.tool_calls.function.name | string | function call 的名称 |
choices.message.tool_calls.function.arguments | string | function call 的参数 |
choices.finish_reason | string | 对话结束原因 |
choices.doc_reference | array | 参考的引用资料,仅当 ecnu-max 模型支持,在 search_mode=enable 是,模型会智能启动联网搜索能力 |
usage | object | 对话使用情况 |
usage.prompt_tokens | int | 提示词 token 量(估计值) |
usage.completion_tokens | int | 回复的 token 量(估计值) |
usage.total_tokens | int | 总 token 量(估计值) |
请求示例
对话生成
- reqeust
http
POST https://chat.ecnu.edu.cn/open/api/v1/chat/completions
Content-Type: application/json
Authorization: Bearer yourapikey
{
"messages": [{
"role": "system",
"content": "你是华东师范大学大模型ChatECNU"
}, {
"role": "user",
"content": "你好呀"
}],
"stream": false,
"model": "ecnu-plus"
}
- response
json
{
"id": "chatcmpl-4fa713672569459d93bf3790b7a53179",
"object": "chat.completion",
"created": 1720671014,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!有什么我可以帮助你的吗?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 9,
"completion_tokens": 8,
"total_tokens": 17
}
}
对话生成(流式)
- reqeust
http
POST https://chat.ecnu.edu.cn/open/api/v1/chat/completions
Content-Type: application/json
Authorization: Bearer yourapikey
{
"messages": [{
"role": "system",
"content": "你是华东师范大学大模型ChatECNU"
}, {
"role": "user",
"content": "你好呀"
}],
"stream": true
"model": "ecnu-plus"
}
- response
r
data: {"id":"chatcmpl-137a302ac8c642d2bb6046fc0ae77b41","object":"chat.completion.chunk","created":1720671137,"model":"SparkDesk","choices":[{"index":0,"delta":{"content":"你好"}}]}
data: {"id":"chatcmpl-66c9b32131b04ebaa26ba29bc8938308","object":"chat.completion.chunk","created":1720671138,"model":"SparkDesk","choices":[{"index":0,"delta":{"content":"!很高兴"}}]}
data: {"id":"chatcmpl-98eabd5391fb4286bf160eedd460c2e1","object":"chat.completion.chunk","created":1720671138,"model":"SparkDesk","choices":[{"index":0,"delta":{"content":"为你提供帮助"}}]}
data: {"id":"chatcmpl-7add6aadb1644f269e550fc2df19b277","object":"chat.completion.chunk","created":1720671138,"model":"SparkDesk","choices":[{"index":0,"delta":{"content":"。"}}]}
data: {"id":"chatcmpl-86399dd5e06e4c3ab590b5684f5bdf9e","object":"chat.completion.chunk","created":1720671140,"model":"SparkDesk","choices":[{"index":0,"delta":{"content":"如果你有任何问题或者需要了解的信息,请随时告诉我。"},"finish_reason":"stop"}]}
data: [DONE]
function call
- request
http
POST https://chat.ecnu.edu.cn/open/api/v1/chat/completions
Content-Type: application/json
Authorization: Bearer yourapikey
{
"messages": [ {
"role": "user",
"content": "上海今天天气如何?"
}],
"tools":[
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "当你想查询指定城市的天气时非常有用。",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市或县区,比如北京市、杭州市、余杭区等。"
}
}
},
"required": [
"location"
]
}
}
],
"stream": false,
"model": "ecnu-plus"
}
- response
json
{
"id": "chat-ca7f7b7aed434322a11e0350fc89802d",
"object": "chat.completion",
"created": 1732677065,
"model": "qwen25",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "chatcmpl-tool-4b247cc8f6db4565a574a3e1b30261f7",
"type": "function",
"function": {
"name": "get_current_weather",
"arguments": "{\"location\": \"\\u4e0a\\u6d77\\u5e02\"}"
}
}
]
},
"logprobs": null,
"finish_reason": "tool_calls",
"stop_reason": null
}
],
"usage": {
"prompt_tokens": 186,
"total_tokens": 207,
"completion_tokens": 21
},
"prompt_logprobs": null
}
联网搜索(仅支持 ecnu-max)
- request
http
POST https://chat.ecnu.edu.cn/open/api/v1/chat/completions
Content-Type: application/json
Authorization: Bearer sk-bb6xxxxxxxxxxxxxxxxxxac0ad
{
"messages": [{
"role": "system",
"content": "你是一个具备联网搜索能力的大模型"
}, {
"role": "user",
"content": "华东师范大学是哪一年成立的?"
}],
"search_mode":"enable",
"stream": false,
"model": "ecnu-max"
}
- response
json
{
"id": "chatcmpl-80989451104e40a39f42f515bbe6a9fd",
"object": "chat.completion",
"created": 1732681810,
"model": "ecnu-max",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "华东师范大学成立于**1951年10月16日**。\n\n华东师范大学的成立,标志着新中国在高等教育领域迈出了重要的一步。作为一所综合性研究型大学,华东师范大学不仅承担着培养高素质教师和专业人才的使命,而且在科学研究、社会服务等方面也发挥着重要作用[^1^][^2^]。学校以大夏大学、光华大学为基础,同时调进了圣约翰大学、复旦大学、同济大学及浙江大学等高校的部分系科,在大夏大学原址上创办[^1^][^2^][^3^]。"
},
"finish_reason": "stop",
"doc_reference": [
{
"index_id": "1",
"title": "校情简介 - 华东师范大学",
"doc_name": "校情简介 - 华东师范大学",
"doc_type": "url",
"url": "https://www.ecnu.edu.cn/wzcd/xxgk/xqjj.htm"
},
{
"index_id": "2",
"title": "华东师范大学 - 百度百科",
"doc_name": "华东师范大学 - 百度百科",
"doc_type": "url",
"url": "https://baike.baidu.com/item/%E5%8D%8E%E4%B8%9C%E5%B8%88%E8%8C%83%E5%A4%A7%E5%AD%A6/232635"
},
{
"index_id": "3",
"title": "华东师范大学校史沿革",
"doc_name": "华东师范大学校史沿革",
"doc_type": "url",
"url": "https://www.ecnu.edu.cn/wzcd/xxgk/xsyg.htm"
},
{
"index_id": "4",
"title": "学校简介",
"doc_name": "学校简介",
"doc_type": "url",
"url": "https://xxgk.ecnu.edu.cn/3d/9f/c11786a212383/page.htm"
},
{
"index_id": "5",
"title": "华东师范大学简介 - 知乎",
"doc_name": "华东师范大学简介 - 知乎",
"doc_type": "url",
"url": "https://zhuanlan.zhihu.com/p/652130465"
}
]
}
],
"usage": {
"prompt_tokens": 14,
"completion_tokens": 124,
"total_tokens": 138
}
}