A small example package
Project description
DeepSeekfree
DeepSeek 网页端逆向 免费的 Api 与 DeepSeek 进行交互, 可选 V3 模型和 R1 模型,支持流式响应,网络搜索,可展示思维链。
✨ 特色功能
- 🔄 流式响应:支持可选流式输出
- 🤔 思考过程:可查看模型的思考过程
- 🔍 Web 搜索:可选集成以获取最新信息
- 💬 会话管理:具有对话历史记录的持久聊天会话, 列出会话列表以及删除会话
- 📜 获取历史消息: 可获取指定会话历史消息
安装
使用以下命令安装 DeepSeekfree:
pip install DeepSeekfree
第一步获取token 和 cookie
使用之前,前往DeepSeek官网获取token 和 cookie.
获取token:
F12 或者 右键->检查打开控制台
获取cookie
F12 或者 右键->检查打开控制台
🚀 快速开始
初始化客户端
from DeepSeekfree import DeepSeek
# 使用预获取的凭证初始化
client = DeepSeek(
cookies="your_cookies",
Authorization="your_authorization_token"
)
创建新的聊天会话
from DeepSeekfree import DeepSeek
client = DeepSeek(
cookies="your_cookies",
Authorization="your_authorization_token"
)
chat_session_id = deepseek.create_chat_session() # 返回chat_session_id, 可用于连续对话
单轮对话示例
response = deepseek.chat(
prompt="Hello,DeepSeek!"
)# 第一次会自动创建新的聊天会话
print(response)
🧠 进阶用法
流式响应处理
for chunk in client.chat(prompt="写一篇关于AI的短文", stream=True):
print(chunk, end="\n")
启用高级功能
response = client.chat(
prompt="最新的人工智能进展有哪些?",
thinking_enabled=True, # 启用R1思考模型
search_enabled=True, # 开启网络搜索
stream=True # 开启流式传输
)
多轮对话示例
通过传入父消息Id以及当前会话Id实现连续对话
from DeepSeekfree import DeepSeek
client = DeepSeek(
cookies="your_cookies",
Authorization="your_authorization_token"
)
question = "who are u"
data = client.chat(prompt=question)
print(data)
message_id = data["message_id"]
chat_session_id = data["chat_session_id"]
question2 = "你会什么"
data2 = client.chat(
prompt=question2,
chat_session_id=chat_session_id,
parent_id=message_id
)
print(data2)
开启R1模型(思考模型)以及联网搜索
response = deepseek.chat(
prompt="Hello,DeepSeek!",
thinking_enabled=True,
search_enabled=True
)# 第一次自动创建新的聊天会话
print(response)
获取历史消息
获取指定 chat_session_id 会话历史消息
history = deepseek.get_history_messages(chat_session_id=chat_session_id)
print(history)
列出聊天会话
通过传入参数count,列出自定义会话数
sessions = deepseek.list_session(count=100)
print(sessions)
删除聊天会话
删除指定 chat_session_id 会话
delete_response = deepseek.delete_session(
chat_session_id=chat_session_id
)
print(delete_response)
🛠️ 接口参数
DeepSeek 参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| cookies | str | 是 | 网站认证cookies |
| Authorization | str | 是 | Bearer令牌 |
chat() 方法参数
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| prompt | str | 必填 | 用户输入的提示信息 |
| chat_session_id | str | None | 会话ID(为空则创建新会话) |
| parent_id | str | None | 父消息ID(用于上下文追踪) |
| thinking_enabled | bool | False | 启用R1思考模型 |
| search_enabled | bool | False | 启用网络搜索功能 |
贡献
欢迎贡献代码!请提交 pull request 或报告问题。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deepseekfree-0.6.4.tar.gz.
File metadata
- Download URL: deepseekfree-0.6.4.tar.gz
- Upload date:
- Size: 22.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0afacc7888a9c4c18dcb87c9faa53fbaf6b253330c85e8b7a0ee0f9b0f807949
|
|
| MD5 |
cbf1182c414f2f238dc354b77c5df385
|
|
| BLAKE2b-256 |
8c988c4e3cf5f09e6fe83dff028591872bcb24c0e6ccfd5bc202457fc3299820
|
File details
Details for the file DeepSeekfree-0.6.4-py3-none-any.whl.
File metadata
- Download URL: DeepSeekfree-0.6.4-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3abc2a43a214bf79b69c01c783687cd3e90d48672547e0fd3324c4d851adcb7b
|
|
| MD5 |
555ec28371acea89974cc95191951ed7
|
|
| BLAKE2b-256 |
9efffbef6bc7076c02242ff6ea9a8a14b6d234309e53a24222373782239a44c4
|