Files
AI-Chat/docs/API.md

209 lines
3.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# API 文档
## 基础信息
- 基础 URL`/api`
- 响应格式JSON
- 认证方式JWT Bearer TokenAuthorization 头)
### 统一响应格式
```json
{
"success": true,
"data": {},
"message": "操作成功"
}
```
## 认证 API
### POST /auth/login
用户登录,获取 JWT 令牌。
**请求体:**
```json
{
"username": "admin",
"password": "123456"
}
```
**成功响应:**
```json
{
"success": true,
"data": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGc...",
"user": {
"id": 1,
"username": "admin",
"role": "admin"
}
}
}
```
### GET /auth/me
获取当前用户信息。(需认证)
**响应:**
```json
{
"success": true,
"data": {
"id": 1,
"username": "admin",
"role": "admin"
}
}
```
## 会话 API
### GET /sessions
获取当前用户的会话列表。(需认证)
**响应:**
```json
{
"success": true,
"data": [
{
"id": 1,
"user_id": 1,
"name": "新会话",
"provider": "newapi",
"model": "gpt-3.5-turbo",
"system_prompt": "",
"personality_id": null,
"thinking_mode": 0,
"created_at": "2024-01-01 00:00:00",
"updated_at": "2024-01-01 00:00:00"
}
]
}
```
### POST /sessions
创建新会话。(需认证)
**请求体:**
```json
{
"name": "新对话",
"provider": "newapi",
"model": "gpt-3.5-turbo",
"system_prompt": "",
"thinking_mode": false
}
```
### PUT /sessions/{id}
更新会话。(需认证)
### DELETE /sessions/{id}
删除会话。(需认证)
## 消息 API
### GET /sessions/{id}/messages
获取指定会话的消息列表。(需认证)
### POST /sessions/{id}/messages
保存消息到指定会话。(需认证)
**请求体:**
```json
{
"role": "user",
"content": "Hello!",
"file_info": null,
"thinking_content": null
}
```
## AI 对话 API
### POST /chat/completions
AI 对话请求SSE 流式响应)。(需认证)
**请求体:**
```json
{
"provider": "newapi",
"model": "gpt-3.5-turbo",
"messages": [
{"role": "user", "content": "Hello!"}
],
"stream": true,
"systemPrompt": "",
"thinkingMode": false
}
```
**SSE 响应格式:**
```
data: {"content":"Hello"}
data: {"content":"!"}
data: {"thinking":"Let me think..."}
data: [DONE]
```
## 文件上传 API
### POST /upload
上传文件。需认证multipart/form-data
**支持格式:** jpg, jpeg, png, gif, webp, js, ts, py, java, cpp, c, html, css, json, xml, txt, md, go, rs, php, rb, sql, yaml, yml, sh, bat
**大小限制:** 10MB
**响应:**
```json
{
"success": true,
"data": {
"url": "/uploads/xxx.jpg",
"name": "原始文件名.jpg",
"size": 1024,
"type": "jpg"
}
}
```
## 配置 API
### GET /config
获取系统配置。(需认证)
### PUT /config
更新系统配置。(需认证 + 管理员)
## 人格 API
### GET /personalities
获取人格列表。(需认证)
### POST /personalities
创建人格。(需认证 + 管理员)
### PUT /personalities/{id}
更新人格。(需认证 + 管理员)
### DELETE /personalities/{id}
删除人格。(需认证 + 管理员)
## 安装 API
### GET /install/status
检查安装状态。(无需认证)
### POST /install/test-db
测试数据库连接。(无需认证)
### POST /install/setup
执行安装。(无需认证)