本文围绕Deepseek模型的本地部署方法和使用展开。
1. 探讨了Deepseek指令技巧,
2. 一些热门客户端(AnythingLLM、Chatbox、Cherry Studio等)使用和搭建知识库,使用个人文档问答。
3. 热门的插件分享,例如浏览器联网插件Page Assist、VSCode中写代码的插件。
4. 在 Word和WPS中调用Deepseek API服务


deepseek本地部署方法
本地部署需要根据自己的硬件配置做好模型选型,671B的模型有1.58bit的量化版,至少需要136G左右的显存(可以GPU配合内存使用。),配置不够的可以选择使用蒸馏版+量化版的模型。
基于Ollama
安装ollama
我以前写了一篇超全面的Ollama安装和使用指南,以及常见问题。MacBook、Linux和Windows都可以参考这篇安装:
Ollama使用指南【超全版】[1]

个人平时使用Ollama有个显著的特点,不用的时候不会占用GPU显存。我的很多应用也都基于Ollama做后端服务的。
在Models界面,搜DeepSeek就能看到

点进去选择自己想用的模型即可。

命令:
# 拉取模型并运行
ollama run deepseek-r1
# 仅仅拉取:
ollama pull deepseek-r1

拉取镜像之后怎么使用?
这个要看你是开发使用还是想无代码使用。先聊聊代码开发,后面有无代码使用方法。
-
1. 开发者使用:
-
我比较常用openai的库调用,可以封装后调用:
from openai import OpenAI
client = OpenAI(
base_url='http://localhost:11434/v1/',
api_key='ollama', # 必需但可以随便填写
)
chat_completion = client.chat.completions.create(
messages=[
{
'role': 'user',
'content': '介绍杭州旅游怎么玩。',
}
],
model='deepseek-r1',
)
-
2. 无代码使用
-
下文介绍了基于 AnythingLLM、Chatbox、Cherry Studio等方法,直接在客户端中使用。
基于Vllm部署
vLLM 是高性能大模型推理框架,专为生产环境优化,适合企业级应用。
安装:
pip install vllm --index-url https://mirrors.aliyun.com/pypi/simple/
启动 vllm 服务:
# HF_ENDPOINT 镜像,在国内下载模型更快
HF_ENDPOINT=https://hf-mirror.com vllm serve deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
其他的一些参数可以参考官方文档。
https://docs.vllm.ai/en/latest/index.html
OpenAI API代码调用
同上面Ollama的方式,只是后端启用服务不同,方式大致相同。
from openai import OpenAI
openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"
client = OpenAI(
api_key=openai_api_key,
base_url=openai_api_base,
)
completion = client.completions.create(model="DeepSeek-R1-Distill-Qwen-1.5B",
prompt="你的提示词。")
print("Completion result:", completion)
Chat版:
chat_response = client.chat.completions.create(
model="DeepSeek-R1-Distill-Qwen-1.5B",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me a joke."},
]
)
print("Chat response:", chat_response)
通过vllm库中的 LLM 加载:
from vllm import LLM, SamplingParams
model_name_or_path = "指定模型名称或者路径"
llm = LLM(
model=model_name_or_path,
pipeline_parallel_size=1,
tensor_parallel_size=8,
max_num_seqs=512,
max_num_batched_tokens=8192,
max_model_len=4096,
gpu_memory_utilization=0.85,
trust_remote_code=True,
)
sampling_params = SamplingParams(
temperature=0.0,
# top_p=0.95,
max_tokens=1024,
stop=stop,
)
# 可以批量
prompts = [
"Hello, my name is",
"The president of the United States is",
]
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt}, Generated text: {generated_text}")
Deepseek 无代码使用
这部分介绍如何使用开源的客户端或者开源的网站使用Deepseek模型,以及一些高质量指令技巧。

DeepSeek官方
-
1. 网页版网址:
https://www.deepseek.com/
https://chat.deepseek.com/
-
2. APP
直接在手机应用商城下载
-
3. API方式
https://platform.deepseek.com/usage
搭建个人知识库
这里主要介绍开源客户端,例如 AnythingLLM、Cherry Studio、ChatBox等下载安装版的可以根据自己的喜好选择,如果你有用其他的客户端,欢迎留言,让大家体验体验。除此之外,还有在VS Code里的插件,以及 Page Assist 浏览器插件。
配合 AnythingLLM
进入AnythingLLM官网(https://anythingllm.com/),选择安装包下载安装即可。

在软件设置里面,LLM首选项界面,提供商选择Ollama,Ollama Model选择前面下载的DeepSeek-R1系列模型,然后点击Save changes。

点击【工作区设置】,点击聊天设置,工作区LLM提供者选择【Ollama】,工作区聊天模型选择【deepseek-r1】模型,然后点击【Update workspace agent】。

点击上传按钮,可以选择本地文档,也可以输入网址进行问答。

在Cherry Studio中使用
内置了很多的提示词,这点很方便。写论文、看论文轻松多了,哈哈哈。

支持很多客户端, Ollama相关配置见下图:

在ChatBox中使用
ChatBox也是一个不错的本地客户端应用,集成了市面上的模型服务,可以按照下面的去配置ollama的服务。但联网等服务,需要是会员。

插件
WebUI 浏览器插件
Page Assist[2] 是本地 AI 模型的 Web UI,可以使用本地运行的 AI 模型联网给你找答案。
在扩展中的管理扩展页面,搜索找到Page Assist,点击获取就会安装。

然后在浏览器插件那里点击就会跳转界面。

更多操作可以参考Page Assist 官方文档。
https://github.com/n4ze3m/page-assist
联网检索的引擎也支持很多。
VSCode里使用插件
Roo-code插件、Cline插件、Continue插件,都是不错的选择。Continue插件会和notebook冲突,我后来就没用了,目前不清楚有没有改掉bug。
程序员写代码的效率提升了好多。有的时候拿过来,改改就能用了,哈哈哈。

无代码应用
无代码流程编排
无代码流程编排类的应用,例如Coze(字节的),还有一些开源的项目,比如 Dify、langflow, RAGFlow等

https://github.com/langgenius/dify

https://github.com/langflow-ai/langflow
如果你还有其他比较推荐的无代码流程编排类的应用,欢迎留言区和大家分享。
Dify目前在往1.x的版本迁移,和0.x版本略有差异。这类无代码的sass类服务,可以根据自己的需求设置工作流。也可以结合Ollama和Vllm使用,具体操作可以看官方文档,后面也会分享更多的操作给大家。
其他网站
1、硅基流动
https://cloud.siliconflow.cn/i/AJQISNv5

如何更好让DeepSeek R1发挥实力
不要用ChatGPT的那套逻辑去使用Deepseek。
指令技巧模板
核心指令分类模板,可以根据自己的任务需求填充和调整。
输入类 :步骤分解、扮演专家、创建生成。一般具有明确的范围和数量、给出具体示例和评估标准等特征。能让 AI 为我们拆解步骤、模拟专家、生成各类内容、搭建完整框架。
-
• 洞察 :"请分析[现象/数据/问题],找出其中的关键信息和深层含义。"
-
• 归因 : "请对[结果/现象]进行归因分析,说明各个因素的影响程度和作用机制。"
-
• 判断 : "请基于[给定条件/标准],对[对象/方案]做出专业判断,并说明判断依据。"
-
• 建议 :"请针对[现状/问题]提供[数量]条具体建议,每条建议需包含[实施要点]。"
-
• 指导 :"请为[目标群体]提供关于[主题]的指导方案,需要涵盖[具体方面]。"
-
• 诊断 :"请对[问题/现象]进行深入诊断,分析[具体层面],并提供[解决方向]。"
分析类 :"检查审核、深度分析、交叉对比,获取专业洞见",这类指令往往需要清晰定义研究对象、提供具体的评估维度或标准、要求AI给出判断的依据、强调专业视角、注重深度诠释。
-
• 解释 : "请用[受众]能理解的方式,解释[概念]。要求:[深度/类比/示例]"
-
• 诠释 : "请从[视角/维度]出发,诠释[作品/观点/现象]的深层含义和价值。"
-
• 呈现 : "请以[形式/方式],生动呈现[内容/主题],确保[要求/效果]。"
-
• 对比 : "请从[维度/角度]对[对象A]和[对象B]进行对比分析,突出[关注点]。"
-
• 横向 : "请对[领域/行业]中的[多个对象],进行全面的横向比较,包含[比较要素]。"
-
• 纵向 : "请对[对象]在[时间周期]内的变化进行纵向比较,分析[关注点]。"
优化类:内容转化、改进完善、总结提炼、持续打磨迭代。一般包含:明确的目的、具体内容、预期的效果、具体的输出形式。
-
• 转化 : "请将[内容A]转化为[内容B]的形式,确保[核心要求]。"
-
• 适应 : "请将[内容]调整适应[目标平台/受众],注重[重点要素]。"
-
• 迭代 :"请对[现有内容]进行优化迭代,重点改进[具体方面]。"
-
• 提炼 :"请从[原始内容]中提炼出[核心要素],重点关注[关键维度]。"
-
• 总结 :"请对[内容系列]进行系统总结,包含[重点方面],形成[预期成果]。"
-
• 完善 :"请完善[现有内容],重点补充[缺失部分],使其达到[标准要求]。"
-
• 改进 :"请对[目标内容]进行改进,主要从[具体维度]入手,确保符合[评估标准]。"
-
• 补齐 :"请为[基础内容]补充[必要元素],重点关注[核心要点],使其形成完整的[目标体系]。"
其他技巧
边聊边看边想
如果以前学过AI提示词,或者收藏了很多AI提问指令,在这里发布不了多少作用。只要你像和人聊天一样,说说你的身份、目标、需求,它就会给你一个有启发的内容,然后有针对性提问。
其实,提问技巧都隐藏在它的思维链里,有时候你不知道怎么提问,看看它的思维链就知道了。看了它的思维链后,完全可以想想,自己想要什么样的内容,然后根据思维链提问。
公式模板,事半功倍
就是把目标、创作类型、风格等不同的元素说清楚。
让AI说人话,比如你可以直接说:说人话、用大白话说、禁用专业术语、每段不超过手机屏幕。
示例
-
1. 要求: 说人话,开头吸睛
给英语教育博主,写1篇300字以内的口播稿,专门给10-15岁孩子科学习英语方法的,要求: 说人话,开头吸睛
-
2. 专家视角指令:
"作为首席分析师,请用Gartner技术成熟度曲线分析2024年量子计算发展态势,要求:
1. 划分技术发展阶段并标注时间节点
2. 识别3个关键突破方向
3. 制作投资风险评估矩阵
4. 输出格式:Markdown表格+趋势图描述"
通过这种结构化、参数化的提示词设计体系,可使Deepseek的输出在逻辑严谨性、专业深度和实用价值上提升58%以上(基于内部测试数据)。
-
3. 创作指令
内容定义:明确内容类型、主题范围、设定创作目标
风格要求:语言风格、表达方式、情感基调
结构规划:明确章节划分、设定逻辑关系、规划内容层次
请创建一个产品说明书,主题是儿童语音机器人,
风格要求:简洁专业,结构要求:包含功能、参数、使用说明。
Word+WPS中使用Deepseek
在WPS和Word里使用
Word或者WPS我们职场牛马总归会用到吧。
先看效果:
我输入提示词:“杭州西湖”,选中文字,再点击右上角的“AI模型组件”按钮自动生成到下面的内容:

Word + DeepSeek R1
核心思路就是通过 Visual Basic 编程语言调用Deepseek 的API,我也实现了调用本地Ollama服务的方式。
跟着下面的步骤操作起来:
在 Word 文档中,点击“文件 -> 选项 -> 自定义功能区”,勾选“开发者工具”。

接着,进入“信任中心 -> 信任中心设置”,选择“启用所有宏”和“信任对 VBA……”。

保存设置后,“开发工具”就会出现在顶部菜单栏。

然后,点击“开发者工具”,再点击“Visual Basic”,进入代码编辑界面。

如果中间没有编辑块,可以点击“插入 -> 模块”。
将以下代码复制到编辑区,完成代码修改后,关闭弹窗。
自定义改动:
你需要自定义改动的地方:
' 不想用R1模型,想用V3模型,就把model的deepseek-reasoner换成deepseek-chat
替换秘钥:api_key = "替换为你自己的密钥。"
API = "https://api.deepseek.com/chat/completions"
SendTxt = "{""model"": ""deepseek-reasoner"", ""messages"": [{""role"":""system"", ""content"":""You are a Word assistant""}, {""role"":""user"", ""content"":""" & inputText & """}], ""stream"": false}"
完整的代码:
Function CallDeepSeekAPI(api_key As String, inputText As String) As String
Dim API As String
Dim SendTxt As String
Dim Http As Object
Dim status_code As Integer
Dim response As String
' ollama 服务的 API 地址
API = "http://localhost:11434/api/chat"
SendTxt = "{""model"": ""deepseek-r1:32b-qwen-distill-q8_0"", ""messages"": [{""role"":""user"", ""content"":""" & inputText & """}], ""stream"": false}"
Set Http = CreateObject("MSXML2.XMLHTTP")
With Http
.Open "POST", API, False
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Authorization", "Bearer " & api_key
.send SendTxt
status_code = .Status
response = .responseText
End With
' MsgBox "API Response: " & response, vbInformation, "Debug Info"
If status_code = 200 Then
CallDeepSeekAPI = response
Else
CallDeepSeekAPI = "Error: " & status_code & " - " & response
End If
Set Http = Nothing
End Function
Sub DeepSeekV3()
Dim api_key As String
Dim inputText As String
Dim response As String
Dim regex As Object
Dim matches As Object
Dim originalSelection As Object
api_key = "pass"
If api_key = "" Then
MsgBox "Please enter the API key."
Exit Sub
ElseIf Selection.Type <> wdSelectionNormal Then
MsgBox "Please select text."
Exit Sub
End If
Set originalSelection = Selection.Range.Duplicate
inputText = Replace(Replace(Replace(Replace(Replace(Selection.Text, "", "\"), vbCrLf, ""), vbCr, ""), vbLf, ""), Chr(34), """")
response = CallDeepSeekAPI(api_key, inputText)
If Left(response, 5) <> "Error" Then
Set regex = CreateObject("VBScript.RegExp")
With regex
.Global = True
.MultiLine = True
.Pattern = """content"":s*""([sS]*?)"""
End With
If regex.Test(response) Then
response = regex.Execute(response)(0).SubMatches(0)
response = Replace(response, "u003c", "<")
response = Replace(response, "u003e", ">")
With regex
.Global = True
.MultiLine = True
.IgnoreCase = True
.Pattern = "[sS]*?"
End With
response = regex.Replace(response, "")
response = Replace(response, "n", vbCrLf)
With regex
.Global = True
.Pattern = "(#+s*|**|__|`|*{1,2}|_{1,2}|~~|^>s)"
response = .Replace(response, "")
End With
response = regex.Replace(response, "")
Selection.Collapse Direction:=wdCollapseEnd
Selection.TypeParagraph
Selection.TypeText Text:=response
originalSelection.Select
Else
MsgBox "Failed to parse API response.", vbExclamation
End If
Else
MsgBox response, vbCritical
End If
End Sub
再次点击“文件 -> 选项 -> 自定义功能区”,右键“开发工具”,点击“添加新组”。
在下拉列表中找到“宏”,将之前创建的宏模块添加到“开发工具”中。

WPS + DeepSeek R1
打开WPS,在上层菜单栏中,点击“工具>开发工具”。

然后点击“切换到 VB 环境”,此时提示加载插件,点击等待插件安装完成。重启 WPS即可。

点击“WPS”宏编辑器,剩下的步骤就和 Word 完全一样了。如果不使用VB,在WPS中也可以使用JavaScript。
引用链接
[1]
Ollama使用指南【超全版】: https://www.icnma.com/ollama-tutorial/[2]
Page Assist: https://github.com/n4ze3m/page-assist

END

2025-01-29
2024-07-06
2023-06-09


<