Skip to content

PC2005-cloud/WebAI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WebAi-Gateway

将 DeepSeek 网页版封装成标准 HTTP API,无需浏览器、无需翻墙,直接用 curl / OpenAI SDK 调用。

核心特性

  • 🚀 纯 HTTP 直连 — 不走浏览器界面,直接调 DeepSeek 内部 API
  • 纯计算 PoW — 无需 Playwright 浏览器(WASM + Python 双引擎,~2s 求解)
  • 🔒 TLS 指纹模拟 — 使用 curl_cffi 模拟 Chrome 120,降低风控
  • 🧠 思维链提取 — 深度思考模式下自动分离 thinkingcontent
  • 🎯 插件架构 — 支持多后端(DeepSeek / 豆包 / 自定义),路由自动注册
  • 📊 用量统计 — 按模型、按日累计 token 消耗

快速开始

# 1. 安装依赖
uv sync

# 2. 登录(手机号 + 密码)
uv run python -m gateway.server --mode login
# 按提示输入手机号和密码,session 自动保存

# 3. 启动服务
uv run python -m gateway.server --port 8888

# 4. 测试
curl http://localhost:8888/health

API 文档

交互式文档:http://localhost:8888/docs

聊天

请求:

POST /v1/deepseek/chat

{
  "content": "你好,讲个笑话",
  "model": "default",
  "thinking_enabled": true,
  "search_enabled": false,
  "stream": false,
  "auto_clean": true
}
参数 类型 默认 说明
content string 用户输入(必填)
model string default default(快速)/ expert(专家)/ vision(识图)
thinking_enabled bool true 开启深度思考(返回链式推理过程)
search_enabled bool false 开启智能搜索(仅 default 模式可用)
stream bool false SSE 流式输出
auto_clean bool true 完成后自动清理 session

非流式响应:

{
  "code": 1,
  "message": "success",
  "data": {
    "id": "a1b2c3d4-...",
    "content": "你好!今天有什么可以帮你的?",
    "thinking": "用户打招呼,需要友好回应..."
  }
}

流式响应stream: true):

data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{"content":"你好","thinking":false},"finish_reason":null}]}
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]

模型列表

GET /v1/deepseek/models

登录 / 登出

# 密码登录
POST /v1/deepseek/login
{"mobile": "138xxxx", "password": "xxx"}

# 登出(清除本地 session)
POST /v1/deepseek/logout

其他

GET  /health              # 健康检查
GET  /v1/backends         # 列出已注册后端
POST /v1/deepseek/session/delete  # 删除 session

调用示例

curl

# 非流式
curl -X POST http://localhost:8888/v1/deepseek/chat \
  -H "Content-Type: application/json" \
  -d '{"content":"1+1等于几?","model":"default","thinking_enabled":true}'

# 流式
curl -X POST http://localhost:8888/v1/deepseek/chat \
  -H "Content-Type: application/json" \
  -d '{"content":"讲个笑话","model":"default","stream":true}'

Python

import requests

resp = requests.post("http://localhost:8888/v1/deepseek/chat", json={
    "content": "你好",
    "model": "default",
    "thinking_enabled": True,
})
print(resp.json()["data"]["content"])

参数注意事项

组合 是否支持
default + 搜索
expert / vision + 搜索 ❌ 请求会被拒绝
深度思考 + default / expert / vision
thinking_enabled=false ✅ 仅返回 content

项目结构

gateway/
├── server.py              # FastAPI 应用入口 + CLI
├── backends/              # 后端适配器(插件)
│   ├── base.py            # BaseBackend 抽象接口
│   ├── deepseek.py        # DeepSeek 后端(路由 + 请求处理)
│   └── doubao.py          # 豆包(待实现)
└── deepseek/              # DeepSeek 内部实现
    ├── client.py          # curl_cffi HTTP 客户端
    ├── pow/               # PoW 纯计算引擎
    ├── sse.py             # 统一 SSE 解析器
    ├── convert.py         # 消息格式转换(OpenAI → DSML)
    ├── dsml.py            # DSML XML 解析器
    ├── sieve.py           # 流式工具调用筛分
    ├── context.py         # 上下文 token 裁剪
    └── session.py         # 登录 / token 管理
store/                     # 持久化存储
    ├── usage.py           # 用量统计
    └── sessions.py        # session 跟踪
core/
    ├── exceptions.py      # 异常体系
    └── response.py        # Result 统一响应格式

项目状态

  • DeepSeek 基础对话(非流式 / 流式)
  • 深度思考(思维链提取)
  • 智能搜索
  • 三种模型(default / expert / vision
  • 手机号密码登录
  • PoW 纯计算(无浏览器)
  • 用量统计
  • 豆包后端适配器
  • OpenAI 兼容接口(/v1/chat/completions
  • Anthropic 兼容接口(/v1/messages

与 deepseek-free-api 的关系

核心思路参考 deepseek-free-api

  • PoW 使用 HTTP challenge + WASM 纯计算(非浏览器)
  • HTTP 层使用 curl_cffi 模拟 TLS 指纹
  • SSE 解析兼容新旧两种格式
  • 消息使用 DSML 标记格式转换

About

将网页版AI封装成可以调用的api接口

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages