官网参考:https://api-docs.deepseek.com/zh-cn/guides/multi_round_chat
使用原因
- 需要gpu算力少。
- 精准度比较高。
- 中国的,不需要考虑vpn,国外手机注册的信息。
- 政府支持。
- 开源
5.1 671B 100块a100
5.2 7B 4090
可以私有化部署(为什么进行私有化部署)
在自己的机房的服务器中,进行deepseek部署。(政府,银行,国企电网)
- 安全性(数据可以不出自己的服务器)。
1.1 直接使用自己的知识库。
1.2 可以利用自己的数据进行微调训练。 - 拥有最高权限。
2.1 没有次数限制
2.2 没有网速限制
2.3 第一掌控权
如果官方的deepseek api用不了怎么办
- 中转(淘宝 闲鱼 拼多多)
- 私有化部署
api key申请
- 登录后台
登录地址:https://platform.deepseek.com/api_keys - 创建api key
api调用
针对代码不太擅长的,可以考虑安装marscode (https://www.marscode.com/extension?goInstall=true)
首次调用
调用模版如下
# 第一次调用需要用安装openai包
conda activate base
pip install openai
# 具体服务器路径地址 /root/test_yang/deepseek
# python 调用
from openai import OpenAI
client = OpenAI(api_key="<DeepSeek API Key>", base_url="https://api.deepseek.com")
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant"},
{"role": "user", "content": "Hello"},
],
stream=False
)
print(response.choices[0].message.content)
发生报错:
openai.APIStatusError: Error code: 402 - {'error': {'message': 'Insufficient Balance', 'type': 'unknown_error', 'param': None, 'code': 'invalid_request_error'}}
不必惊慌,只是因为你没有冲钱导致,充点费用就可以了。
api调用方式
推理模式
不考虑上下文,只针对提的问题进行回答
场景:代码生成
多次推理方式:
- 一个问题调用一次api
- 多问题同时问同时回
多轮对话
考虑上下文,此问题考虑上文
场景:角色扮演
多次推理方式:
- 一个问题调用一次api
- 多问题同时问同时回
其他官方文档会有更清晰的介绍
重点!应用
利用deepseek进行数据打标(提示词分类)
利用deepseek进行数据转结构化(json output)
利用deepseek进行数据“训练”
通过在提示词中多给一些准确案例,实现结果精准推理。比如在以下system_prompt中,多给一些EXAMPLE,出结果。
import json
from openai import OpenAI
client = OpenAI(
api_key="<your api key>",
base_url="https://api.deepseek.com",
)
system_prompt = """
The user will provide some exam text. Please parse the "question" and "answer" and output them in JSON format.
EXAMPLE INPUT:
Which is the highest mountain in the world? Mount Everest.
EXAMPLE JSON OUTPUT:
{
"question": "Which is the highest mountain in the world?",
"answer": "Mount Everest"
}
"""
user_prompt = "Which is the longest river in the world? The Nile River."
messages = [{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}]
response = client.chat.completions.create(
model="deepseek-chat",
messages=messages,
response_format={
'type': 'json_object'
}
)
print(json.loads(response.choices[0].message.content))