基于DeepSeek模型的智能对话接口 | 高性能流式响应
本服务提供基于大模型的智能聊天交互功能,采用先进的流式生成技术,为开发者提供高效、灵活的对话API接口。
自动维护对话上下文,支持长会话记忆,提供连贯的交互体验
低延迟的流式生成技术,实现快速响应和即时中断功能
可选的AI思考过程展示,帮助理解模型推理逻辑
基于邮箱的会话隔离,确保不同用户数据完全独立
https://aisocket.zeromi.cn
Content-Type: application/json
所有API请求需要通过邮箱进行认证,系统会自动为每个邮箱创建独立的对话上下文。
字段名 | 位置 | 类型 | 必填 | 说明 |
---|---|---|---|---|
Request Body | String | 用户邮箱地址,用于会话隔离和权限验证 |
发送用户消息并触发AI回复生成,采用流式处理技术,支持即时中断。
字段 | 类型 | 必填 | 描述 | 示例值 |
---|---|---|---|---|
String | 用户邮箱标识 | "test@zeromi.cn" |
||
inp | String | 用户输入的聊天内容 | "如何学习Python编程?" |
{ "status": true, "code": 200, "exit": 0 }
字段 | 类型 | 说明 |
---|---|---|
status | Boolean | 请求处理状态,true表示成功触发生成 |
code | Integer | HTTP状态码 |
exit | Integer | 0=正常结束,1=被新请求中断 |
/api/record
接口获取。采用轮询方式检查生成状态,建议间隔500ms-1s。
获取指定用户的完整对话记录,包含AI思考过程和生成内容。
字段 | 类型 | 必填 | 描述 |
---|---|---|---|
String | 要查询的邮箱地址 |
{ "text": [ { "role": "user", "content": "你好,推荐一本Python书?" }, { "role": "ai", "content": "我推荐《Python编程:从入门到实践》...", "think": "用户可能是编程初学者,选择一本实践性强的入门书..." } ], "code": 200 }
字段 | 类型 | 说明 |
---|---|---|
text | Array | 对话记录数组,按时间顺序排列 |
code | Integer | 200=完整记录,201=生成中 |
字段 | 类型 | 说明 |
---|---|---|
role | String | "user" 或 "ai" |
content | String | 显示的对话内容 |
think | String | 仅AI消息有,表示思考过程(可选) |
状态码 | 错误类型 | 可能原因 | 解决方案 |
---|---|---|---|
400 | Bad Request | 请求体缺少必需字段或格式错误 | 检查是否包含email和inp字段 |
403 | Forbidden | 邮箱未授权或认证失败 | 联系管理员添加访问权限 |
500 | Internal Server Error | 后端服务异常或模型加载失败 | 检查服务日志或联系技术支持 |
import requests from time import sleep BASE_URL = "http://aisocket.zeromi.cn:5000" EMAIL = "test@example.com" def chat_with_ai(message): # 发送消息 response = requests.post( f"{BASE_URL}/api/chat", json={"email": EMAIL, "inp": message} ) if response.status_code != 200: raise Exception(f"请求失败: {response.text}") # 轮询获取回复 while True: record = requests.post( f"{BASE_URL}/api/record", json={"email": EMAIL} ).json() last_msg = record["text"][-1] if last_msg["role"] == "ai": print(f"AI回复: {last_msg['content']}") if "think" in last_msg: print(f"思考过程: {last_msg['think']}") break sleep(0.5) # 适当间隔轮询 # 使用示例 chat_with_ai("解释一下量子计算的基本原理")
const API_URL = 'http://aisocket.zeromi.cn:5000/api/chat'; const EMAIL = 'test@example.com'; async function chat(message) { try { // 发送消息 const response = await fetch(API_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: EMAIL, inp: message }) }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } // 获取完整对话记录 const record = await fetch('http://aisocket.zeromi.cn:5000/api/record', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: EMAIL }) }).then(res => res.json()); console.log('最新回复:', record.text.slice(-1)[0]); } catch (error) { console.error('请求失败:', error); } } // 使用示例 chat("你好!").then(() => console.log("对话完成"));
# 发送消息 curl -X POST http://localhost:5000/api/chat \ -H "Content-Type: application/json" \ -d '{ "email": "user@example.com", "inp": "你好,今天天气怎么样?" }' # 获取对话记录 curl -X POST http://localhost:5000/api/record \ -H "Content-Type: application/json" \ -d '{"email": "user@example.com"}'
# 发送消息 http POST localhost:5000/api/chat \ email="user@example.com" \ inp="你好,今天天气怎么样?" # 获取对话记录 http POST localhost:5000/api/record \ email="user@example.com"
http://localhost:5000/api/chat
Content-Type: application/json
{ "email": "user@example.com", "inp": "你的问题内容" }
500 - 1000ms
一次