Fundiman/dskpp

GitHub: Fundiman/dskpp

基于 asyncio 的 DeepSeek 非官方客户端,通过 Cloudflare 绕过和工作量证明求解实现免费访问聊天 API,支持流式对话和文件上传。

Stars: 0 | Forks: 0

# dskpp (dsk++) ![Python](https://img.shields.io/badge/python-3.10+-blue.svg) ![异步](https://img.shields.io/badge/async-supported-green.svg) ![许可证](https://img.shields.io/badge/license-Apache2.0-lightgrey.svg) ![状态](https://img.shields.io/badge/status-experimental-orange.svg) 一个轻量级的异步 Python 客户端,通过本地绕过 + cookie + 工作量证明 pipeline 与 DeepSeek 聊天基础设施进行交互。 本项目遵循相同的理念方向(并且包含部分元素): - [https://github.com/xtekky/deepseek4free](https://github.com/xtekky/deepseek4free) - [https://github.com/Doremii109/deepseek4free-fix](https://github.com/Doremii109/deepseek4free-fix) ## 概述 dsk++ 提供: * 异步 DeepSeek 聊天客户端 * 支持双格式解析的流式响应 * 基于会话的对话处理 * 自动化 cookie 获取系统 * 本地 Cloudflare 绕过服务器 * 基于 WASM 的工作量证明求解器,配备异步线程池 * 使用 asyncio.gather() 支持并发文件上传 * 自动 Cloudflare 检测和 cookie 刷新 ## 安装说明 ### 克隆仓库 ``` git clone https://github.com/fundiman/dskpp ``` ### 安装依赖 ``` pip install -r requirements.txt ``` **系统依赖(Linux / 服务器环境):** * google-chrome 或 chromium * xvfb(用于无界面回退) * python 3.10+ ## 快速开始 ``` python run_and_get_cookies.py ``` 这将执行以下操作: * 启动本地绕过服务器 * 启动 Chromium 自动化 * 解决 Cloudflare 验证挑战 * 将 cookies 存储在 `dsk/dsk/cookies.json` 中 ## 项目结构 ``` dskpp/ │ ├── api.py # async DeepSeek API client ├── server.py # FastAPI bypass + cookie server ├── CloudflareBypasser.py # Chromium-based challenge solver ├── bypass.py # automation helper logic ├── pow.py # WASM proof-of-work solver (async) ├── run_and_get_cookies.py # bootstrap cookie acquisition │ ├── dsk/ # runtime cookie storage ├── wasm/ # WASM binaries for hashing └── README.md ``` ## 使用说明 ### 初始化客户端 ``` from dskpp.api import DeepSeekAPI import asyncio api = DeepSeekAPI(auth_token="your_token") ``` ### 创建聊天会话 ``` session_id = await api.create_chat_session() ``` ### 删除聊天会话 ``` result = await api.delete_chat_session(session_id) print(result) # "Successfully deleted session: session_id" ``` ### 文件上传(并发多文件) ``` # 并发上传多个文件 file_ids = await api.upload_files([ "document.pdf", "image.png", "data.csv" ]) # file_ids 按输入顺序返回 print(file_ids) # ['file_id_1', 'file_id_2', 'file_id_3'] ``` ### 带文件引用的流式聊天 ``` async for chunk in api.chat_completion( chat_session_id=session_id, prompt="Analyze these uploaded files", ref_file_ids=file_ids, # List of file IDs from upload thinking_enabled=True, search_enabled=False # Must be False when using files ): # chunk is a dictionary with 'content' key print(chunk.get("content", ""), end="") ``` ### 带搜索的聊天 ``` async for chunk in api.chat_completion( chat_session_id=session_id, prompt="What's the latest news about AI?", thinking_enabled=True, search_enabled=True # Enables web search for current info ): print(chunk.get("content", ""), end="") ``` ### 流式响应格式 客户端解析 DeepSeek 的 SSE 格式并返回字典: ``` { 'type': 'text', # Type of chunk (text, message_ids, etc.) 'content': 'incremental text...', # The actual content 'finish_reason': None # 'stop' when complete, None otherwise } ``` ### 非流式用法(聚合) 可以手动构建完全缓冲的响应: ``` response = "" async for chunk in api.chat_completion( chat_session_id=session_id, prompt="Hello world" ): response += chunk.get("content", "") ``` ### 对话历史 ``` history = await api.get_history(session_id) print(history) ``` ### 清理 ``` await api.close() ``` ## 服务器模式 手动运行绕过服务器: ``` python server.py ``` 默认 endpoint: ``` http://localhost:8021 ``` Endpoints: * `/cookies` → 返回验证过的 cookies + user-agent * `/html` → 返回原始 HTML + cookies header 元数据 ## Docker 模式 启用 Docker 兼容性: ``` export DOCKERMODE=true ``` 这将启用以下功能: * 无头 Chromium 调整 * sandbox 标志 * 远程调试端口支持 ## 架构 系统由三个核心层组成: ### 1. API 层 (`api.py`) 用于基于会话的聊天交互的异步客户端,包含: - 使用 asyncio.gather() 进行并发文件上传 - 针对 DeepSeek SSE 格式的流式响应解析 - 带有 Cloudflare 检测和 cookie 刷新的自动重试逻辑 - 使用 curl_cffi 的异步会话管理 ### 2. 绕过层 (`server.py`) FastAPI + Chromium 自动化,用于: * Cloudflare 绕过 * cookie 提取 * 页面验证 ### 3. PoW 层 (`pow.py`) 基于 WebAssembly 的求解器,带有使用 asyncio.to_thread() 的异步包装器,以确保在 CPU 密集型计算期间 event loop 保持响应。 ## 异步设计说明 系统围绕非阻塞执行进行设计: * 网络 I/O 使用来自 curl_cffi 的异步 HTTP 会话 * 流式响应使用异步生成器,在数据块之间释放控制权 * 阻塞的 WASM 计算通过 asyncio.to_thread() 卸载到线程中 * 浏览器自动化在独立进程中运行 * cookie 获取在 event loop 控制路径之外运行 * 使用 asyncio.gather() 进行并发文件上传 * 彩色警告输出以提高可见性 ## 错误处理 客户端针对不同的失败模式提供了特定的异常: ``` from dskpp.api import ( AuthenticationError, # Invalid/expired token RateLimitError, # API rate limit exceeded NetworkError, # Network communication failure CloudflareError, # Cloudflare block detected UploadFilesUnavailable, # Search enabled during file upload APIError # Generic API error with status code ) ``` ## 示例:带文件上传的完整流程 ``` import asyncio from dskpp.api import DeepSeekAPI async def main(): api = DeepSeekAPI("your_token_here") # Create session session = await api.create_chat_session() print(f"Session created: {session}") # Upload files concurrently file_ids = await api.upload_files([ "report.pdf", "data.xlsx" ]) print(f"Uploaded files: {file_ids}") # Chat with file context async for chunk in api.chat_completion( session, "Analyze these files and summarize key points", ref_file_ids=file_ids, search_enabled=False # Required for file uploads ): print(chunk.get("content", ""), end="") # Cleanup await api.delete_chat_session(session) await api.close() asyncio.run(main()) ``` ## 注意事项 ## 许可证 本项目基于 [Apache 2.0](LICENSE) 许可证授权。
标签:AI工具, API客户端, asyncio, ATT&CK 框架, AV绕过, Chromium, CISA项目, Cloudflare绕过, Cookie获取, DeepSeek, DLL 劫持, DNS解析, FastAPI, POW破解, Python, Selenium自动化, WebAssembly, Web自动化, 云资产清单, 人工智能, 代理服务, 免费API, 反爬虫技术, 大语言模型, 并发编程, 开源项目, 异步编程, 无后门, 无头浏览器, 流式响应, 熵值分析, 用户模式Hook绕过, 网络信息收集, 网络请求, 计算机取证, 请求拦截, 逆向工具, 逆向工程