编程技术分享平台

网站首页 > 技术教程 正文

Deepseek+ollama+WPS如何实现本地玩

xnh888 2025-06-28 17:34:18 技术教程 2 ℃ 0 评论

喂奶级教程

后续会搞搞企业知识库教程和模型微调(Ollama+chat box本地AI/AnythingLLM知识库)

不足的地方还请各位指点,大家相互学习,我也是新手

直接入题:下载Ollama、下载模型、运行模型、如何接入WPS/office

电脑配置:12代I5 16G+512G能跑模型,但是很慢

首先下载:Ollama

网址:https://ollama.com/下载windows版本,下载速度慢耐心等待

高速下载:
https://ollama.ruanmao.net/不一定能用

Ollama 是一个基于 Go 语言开发的开源框架,可以在本地运行大模型。它支持多种操作系统,包括 Windows、Linux 和 macOS。该教程Windows步骤

一、下载与安装

安装 Ollama

Windows

下载并双击安装此程序:OllamaSetup.exe。安装步骤就不多解释,鼠标点就可以

安装完成后,在命令提示符中输入 ollama,验证安装是否成功。运行模型启动服务

在终端中输入以下命令启动 Ollama 服务:ollama serve


安装完成之后,打开一个cmd命令窗口,输入“ollama”命令,如果显示ollama相关的信息就证明安装已经成功了!

二、下载模型

可以通过命令行 ollama pull qwen2.5ollama pull llama3.1 下载模型千问和羊驼。

用命令ollama run deepseek-r1下载的模型:

网速快半小时下载完成

三、运行模型

打开新终端窗口,使用以下命令运行模型:

ollama run deepseek-r1

如果是第一次运行,Ollama 会自动下载模型。

常用命令

启动服务:ollama serve

创建模型:ollama create <model> -f <Modelfile>

显示模型信息:ollama show <model>

运行模型:ollama run <model>

拉取模型:ollama pull <model>

删除模型:ollama rm <model>

用ollama serve即可启动ollama,打开浏览器并在地址栏输入http://127.0.0.1:11434/ (自带的地址)如果在界面显示如下的信息,表示ollama已经正常启动,可以进行编程实验啦;)

Ollama is running

在命令行输入如下的命令,即能得到相应的回答:

如:介绍一下你自己

ollama run deepseek-r1:我是..........运行成功第一步搞定

四、Word接入DeepSeek

今天我就来手把手教你,如何将DeepSeek-V3/deepseek-r1接入Word,解锁工作新技能,让你的办公效率飞起来。

什么是DeepSeek-V3?

我们先简单科普一下,DeepSeek-V3/deepseek-r1DeepSeek公司推出的一款强大的AI模型,是国产AI界的一匹黑马。相较于之前的V2.5版本,V3/R1不仅在性能和速度上有大幅度提升,而且成本控制得也相当好。它现在已经能够在多个领域展现出强劲的能力,比如翻译、写作、数据分析等,甚至可以和GPT-4这种国际大牌比肩。无论你是需要快速处理文本,还是要生成高质量的写作内容,DeepSeek都能轻松搞定。

如果你还没有Office,别着急WPS也可以

好了,接下来就让我们一步步来配置DeepSeek,让它完美接入你的Word。

五、完整vba代码(复制代码粘贴即可)

word配置过程(WPS类同)

(1)新建一个Word文档,点击 文件 -> 选项 -> 自定义功能区,勾选“开发者工具”。

(2)点击 信任中心 -> 信任中心设置,选择“启用所有宏”与“信任对VBA......”。

(3)接下来点击确定,我们发现选项卡中出现了“开发者工具”,点击开发者工具,点击Visual Basic,在新窗口中的插入,选择插入模块,把接入deepseek的VBA代码(参见我发布的文章)复制到编辑区中,替换官方申请的API key。完成后,可直接关闭窗口。

代码直接用:标红部分替换直接本地IP和本地模型,不然运行VBA报错

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


'本地部署的大模型API地址

API = "http://192.168.1.14:11434/api/chat"


' 修改请求体为与本地大模型相匹配的格式

SendTxt = "{""model"": ""deepseek-r1:7b"", ""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


' 弹出窗口显示 API 响应(调试用)

'

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*""([\s\S]*?)""" ' 更稳健的提取逻辑

End With

If regex.Test(response) Then

response = regex.Execute(response)(0).SubMatches(0)

'

response = Replace(response, "\u003c", "<")

response = Replace(response, "\u003e", ">")

' 步骤3:删除标签及其内容

With regex

.Global = True

.MultiLine = True

.IgnoreCase = True

.Pattern = "[\s\S]*?"

End With

response = regex.Replace(response, "")

'

response = Replace(response, "\n", vbCrLf)

' 步骤5:移除Markdown格式

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

(3)点击 文件 -> 选项 -> 自定义功能区,右键开发工具,点击添加新组命名为DeepSeek。选择DeepSeek(自定义),选择左侧的命令为“宏”,找到我们添加的DeepSeekV3,选中后点击添加并重命名为“生成”。

(4)完成后就在开发工具那里看到了DeepSeek的生成操作,现在就可以和DeepSeek聊天了。在文档内聊天哦

(5)保存后需要为宏文件哦!不然下次进入的时候又得重新写VBA

如果你想要所有文档都能够用到这个功能,那么请保存启用宏的word模板,保存路径:C:\Users\用户名顺便那个文件夹都可以

PS:文档内聊天、翻译、各种玩法请先运行Ollama哦,不然就是报错

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表