API 概览
基础信息
API 基础地址: 加载中...
协议: HTTP/HTTPS
数据格式: JSON
字符编码: UTF-8
通用响应格式
成功响应
{
"success": true,
"data": {
// 具体数据内容
},
"timestamp": "2024-01-01T00:00:00.000Z"
}
错误响应
{
"success": false,
"error": "错误描述",
"code": "ERROR_CODE",
"timestamp": "2024-01-01T00:00:00.000Z"
}
API 接口列表
正在加载接口列表...
使用示例
JavaScript 示例
// 普通聊天
async function sendMessage(userInput, presetId, history = []) {
const response = await fetch('/api/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
userInput,
presetId,
history
})
});
const data = await response.json();
return data.data.content;
}
// 使用示例
sendMessage('你好', 'general_chat', [])
.then(response => console.log(response));
Python 示例
import requests
import json
# 普通聊天
def send_message(user_input, preset_id, history=None):
if history is None:
history = []
data = {
'userInput': user_input,
'presetId': preset_id,
'history': history
}
response = requests.post(
'/api/chat',
json=data,
headers={'Content-Type': 'application/json'}
)
return response.json()['data']['content']
# 使用示例
result = send_message('你好', 'general_chat', [])
print(result)
cURL 示例
# 获取预设列表
curl -X GET /api/presets
# 普通聊天
curl -X POST /api/chat \
-H "Content-Type: application/json" \
-d '{
"userInput": "你好",
"presetId": "general_chat",
"history": []
}'
# 流式聊天
curl -X POST /api/chat/stream \
-H "Content-Type: application/json" \
-d '{
"userInput": "写一个Python函数",
"presetId": "code_assistant",
"history": []
}'
系统状态
正在检查系统状态...