boykopovar/aiodeepseek

GitHub: boykopovar/aiodeepseek

为 DeepSeek 私有 API 提供高性能异步调用的 Python 客户端,内置 PoW 求解和多轮对话支持。

Stars: 0 | Forks: 0

# aiodeepseek ![Python](https://img.shields.io/badge/python-3.9+-blue.svg) ![Platform](https://img.shields.io/badge/platform-linux%20%7C%20windows-lightgrey) ![Async](https://img.shields.io/badge/asyncio-fully%20async-blueviolet) ![DeepSeek](https://img.shields.io/badge/API-DeepSeek-blue) 一个高性能的私有 DeepSeek API 异步 Python 客户端。支持流式输出、图片上传、多轮对话以及新账号注册。 ➡️ 俄文文档:[docs/ru/README.md](docs/ru/README.md) ## 安装 ``` pip install aiodeepseek ``` C++ 扩展的构建需要支持 AVX2 的编译器以及 `pybind11`。更多详情请参阅 [docs/en/pow.md](docs/en/pow.md)。您也可以下载预编译的 [release](https://github.com/boykopovar/aiodeepseek/releases)。 ## 快速开始 ### 邮箱/密码认证 ``` import asyncio from aiodeepseek import DeepSeekClient async def main(): async with DeepSeekClient(email="myname@example.com", password="password123") as client: result = await client.ask("Hello!") print(result.text) asyncio.run(main()) ``` ### Token 认证 ``` import asyncio from aiodeepseek import DeepSeekClient async def main(): async with DeepSeekClient(token="YOUR_TOKEN") as client: result = await client.ask("Hello!") print(result.text) asyncio.run(main()) ``` ### 流式输出响应 ``` import asyncio from aiodeepseek import DeepSeekClient async def main(): async with DeepSeekClient(token="YOUR_TOKEN") as client: async for chunk in client.ask_stream("Tell me about Python"): print(chunk, end="", flush=True) asyncio.run(main()) ``` ### 多轮对话 ``` import asyncio from aiodeepseek import DeepSeekClient async def main(): async with DeepSeekClient(token="YOUR_TOKEN") as client: chat = client.new_conversation() print((await chat.ask("What is your name?")).text) print((await chat.ask("What can you do?")).text) asyncio.run(main()) ``` ### 图片上传 ``` import asyncio from pathlib import Path from aiodeepseek import DeepSeekClient async def main(): async with DeepSeekClient(token="YOUR_TOKEN") as client: img = await client.upload_image(Path("photo.jpg")) result = await client.ask("What is in the photo?", image=img) print(result.text) asyncio.run(main()) ``` 或者通过将 `Path | bytes` 直接传递给 `ask`: ``` import asyncio from pathlib import Path from aiodeepseek import DeepSeekClient async def main(): async with DeepSeekClient(token="YOUR_TOKEN") as client: result = await client.ask( prompt="What is in the photo?", image=Path("photo.jpg") ) print(result.text) asyncio.run(main()) ``` ### 注册新账号 ``` import asyncio from aiodeepseek import DeepSeekClient async def main(): await DeepSeekClient.send_reg_code("myname@example.com") code = input("Code from the email: ") token = await DeepSeekClient.confirm_reg_code("myname@example.com", "password123", code) print("Token:", token) asyncio.run(main()) ``` ## 模型类型 ``` from aiodeepseek import DeepSeekClient from aiodeepseek.types.enums import ModelType async with DeepSeekClient(token="...", model=ModelType.VISION) as client: ... ``` | 值 | 描述 | |---------------------|-----------------------------------| | `ModelType.DEFAULT` | 标准语言模型 | | `ModelType.EXPERT` | 深度推理模型 | | `ModelType.VISION` | 支持机器视觉的模型 | ## 错误处理 ``` import asyncio from aiodeepseek import DeepSeekClient from aiodeepseek.types.exceptions import AuthorizationError, DeepSeekError async def main(): try: async with DeepSeekClient(token="invalid") as client: await client.ask("Hello") except AuthorizationError: print("Token is invalid") except DeepSeekError as e: print(f"API error: {e}") asyncio.run(main()) ``` ## 工作量证明 在每次请求之前,客户端会自动解算 DeepSeek 服务器发放的 PoW 挑战。典型的难度为 **144,000 次迭代**。该计算使用 AVX2 在 C++ 中实现,因此在实际使用中几乎难以察觉。更多详情请参阅 [docs/en/pow.md](docs/en/pow.md)。 ## 文档 - [DeepSeekClient - 客户端方法](docs/en/client.md) - [Conversation - 多轮对话](docs/en/conversation.md) - [Types 和数据模型](docs/en/types.md) - [Exceptions 异常](docs/en/exceptions.md) - [工作量证明](docs/en/pow.md) ## 环境要求 - Python 3.9+ - `aiohttp >= 3.9` - 支持 AVX2 的 C++17 编译器(用于构建扩展)或手动下载的 wheel 包。
标签:AI对话, API客户端, asyncio, ATT&CK 框架, AVX2, Chatbot, C++扩展, DeepSeek, NLP, PoW验证, pybind11, Python, Spyse API, 人工智能, 图像上传, 多轮对话, 大模型, 开源库, 异步编程, 搜索引擎爬虫, 无后门, 流式响应, 熵值分析, 用户模式Hook绕过, 计算机取证, 逆向工具