WPS接入DeepSeek AI


如何把DeepSeek部署到到WPS上,实现AI赋能。几种方法:

一、首先申请API-KEY

1、通过DeepSeek官方网站申请DeepSeek的API-KEY:

1)打开DeepSeek官网:platform.deepseek.com/a
在开放平台页面,左侧点击“API keys”,右边点击“创建API key”

2)输入名称:任意名称。

3)点击“创建”,可以看到生成的key,这个是在程序中使用的,不要泄漏。

2、deepseek太过火爆,如果官网难申请,可在硅基流动申请 API KEY(备选方案)

打开“硅基流动”官网:iil.ink/siliconflow 自行申请 API KEY。

目前使用接口,都需要充值。如果不想付费,也可以直接使用office ai助手插件,使用其内置的免费ai模型,如豆包等。

office ai 助手下载网址:https://www.office-ai.cn/

二、接入DeepSeek服务

(一)通过 WPS 官方内置功能接入

1、升级 WPS:

将 WPS 升级至 2025 新春版(12.8.0 及以上)。

2、打开WPS功能入口:

在文字 / 表格文档界面右上角点击「智能助手」图标,或使用快捷键 Ctrl+J 调出 AI 侧边栏。

3、账户绑定:

首次使用需登录 WPS 账号,然后完成 DeepSeek API 密钥绑定。密钥获取路径为:DeepSeek 官网 > 开发者中心 > 创建 API Key。

4、使用功能:

点击「审阅」>「AI 校对」,可以实现语法纠错与润色。

(二)不登录WPS或者使用老版的WPS,通过 OfficeAI 插件接入(仅支持 Windows 系统)AI大模型。

officeAi这个插件,已经内置了一些常用ai模型,不接入deepseek也可以免费使用。

1、下载并安装 OfficeAI 插件:

访问 OfficeAI 插件下载地址 office-ai.cn/ ,下载插件。
下载完成后,双击安装文件,按照提示完成安装。

安装后,打开wps, 如有安全提示,全部默认运行。

2、获取 DeepSeek 的 API Key:见步骤一

3、配置 OfficeAI 插件:

1)OfficeAI 插件安装完成后,打开 WPS,此时在 WPS 界面中会多出一个 “OfficeAI” 的选项卡。

2)点击 “OfficeAI” 选项卡,拉到最右侧,点击 “设置”。

3)在 “设置” 窗口中,选择 “大模型设置”,打开 “本地部署” 开关,选择 “ApiKey” 标签。

4)在【大模型设置】右侧的【模型平台】 下拉菜单中,选择 DeepSeekR1(Deepseek官网)或者硅基流动(支持DeepSeekR1)。
【模型名】:deepseek-chat 或 硅基流动的 deepseek-r等
【API_KEY】 输入框中填入你自己申请的 DeepSeek API Key。
点击 “保存” 按钮。

4、使用 DeepSeek 功能:

配置完成后,点击 WPS 界面中的 “OfficeAI” 选项卡,即可使用 DeepSeek 的各种功能,如 AI 校对、文案生成、润色、翻译等。

(三)通过 VBA 代码手动集成DeepSeek 或者使用 WPS 自带的 JS 宏实现接入 DeepSeek 接口。(此方法需要一定技术要求,对于小白可以忽略)

1、启用开发工具:

打开 WPS,新建一个文档。点击 “文件”→“选项”→“自定义功能区”,勾选 “工具” 选项,点击 “确定”。

2、配置信任中心:

点击 “文件”→“选项”→“信任中心”→“信任中心设置”→“宏安全性”,将安全性设置为 “低”,以便运行 VBA 宏。

3、添加模块:

1)点击 “工具”→“开发工具”,点击 “VB 编辑器”。或者【切换开发环境】,点击【WPS宏编辑器】

2)在新窗口中点击 “插入”→“模块”,将代码复制到编辑区中,并替换其中的 api_key 为你的 DeepSeek API Key。

3)示例代码一 VBA 代码:

可用于在 WPS 的 Word 文档中调用 DeepSeek API 对选中文本进行处理,并将结果插入到文档中。

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 = "https://api.deepseek.com/chat/completions"
    SendTxt = "{""model"": ""deepseek-chat"", ""messages"": ({""role"":""system"", ""content"":""You are a Word assistant""}, {""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响应(调试用)
    '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 = "输入你的deepseek api - key"
    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
           .IgnoreCase = False
           .Pattern = """content"":""(.*?)"""
        End With
        Set matches = regex.Execute(response)
        If matches.Count > 0 Then
            response = matches(0).SubMatches(0)
            response = Replace(Replace(response, """", Chr(34)), """", Chr(34))
            '取消选中原始文本
            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

4)示例代码二:

使用 WPS 自带的 JS 宏实现接入 DeepSeek 接口,主要功能是对选中文本进行润色或续写。

/**
 * 使用DeepSeek API对WPS文档中的选中文本进行润色或续写
 */
function DeepSeekPolish() {
    Console.log("开始调用接口DeepSeekPolish");
    // 获取选中的文本
    let selectedText = Application.Selection.Text;
    if (!selectedText || selectedText.trim() === "") {
        alert("请选择需要润色或续写的文本!");
        return;
    }
    // 替换特殊字符以适应JSON格式
    selectedText = selectedText.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/"/g, "\\\"");
    // DeepSeek API密钥(请替换为你的API密钥)
    let apiKey = "改成自己的密钥";
    let url = "https://api.deepseek.com/chat/completions";
    // 构造请求数据
    let data = {
        model: "deepseek-chat",
        messages: (
            { role: "user", content: selectedText },
            { role: "assistant", content: "请润色或续写以上内容" }
        ),
        temperature: 0.7
    };
    // 发送POST请求
    let xhr = new XMLHttpRequest();
    xhr.open("POST", url, false);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.setRequestHeader("Authorization", "Bearer " + apiKey);
    xhr.send(JSON.stringify(data));
    // 处理响应
    try {
        if (xhr.status === 200) {
            let response = JSON.parse(xhr.responseText);
            let result = response.choices(0).message.content;
            result = result.replace(/\\n/g, "\n"); // 恢复换行符
            //移动光标到选取末尾,另起一行
            Application.Selection.MoveEnd;
            Application.Selection.TypeParagraph;
            Application.Selection.TypeBackspace;
            // 将结果插入到文档中
            Application.Selection.Text = result;
            alert("润色或续写完成!");
        } else {
            alert("请求失败:" + xhr.statusText + "\n响应内容:" + xhr.responseText);
        }
    } catch (error) {
        Console.log("错误信息" + error.message)
    }
}

4、自定义功能区:

1)回到 WPS 主界面,点击 “文件”→“选项”→“自定义功能区”。

2)在右侧功能区列表中,点击 “新建组”,将其命名为 “DeepSeek”。

3)在左侧命令列表中,选择 “宏”,找到刚刚添加的宏(如 “DeepSeekV3”),点击 “添加”,然后右键重命名为 “生成”,点击 “确定”。

5、使用 DeepSeek 功能:

打开 WPS 文档,选中需要处理的文字,点击 “生成” 按钮,DeepSeek 会返回处理结果,并直接插入到文档中。

6、说明:DeepSeek 所有的模型和对应的费用

模型 & 价格细节

  1. deepseek-chat 模型已经升级为 DeepSeek-V3deepseek-reasoner 模型为新模型 DeepSeek-R1
  2. 思维链deepseek-reasoner模型在给出正式回答之前的思考过程,其原理详见推理模型。
  3. 如未指定 max_tokens,默认最大输出长度为 4K。请调整 max_tokens 以支持更长的输出。
  4. 关于上下文缓存的细节,请参考DeepSeek 硬盘缓存。
  5. deepseek-reasoner的输出 token 数包含了思维链和最终答案的所有 token,其计价相同。

扣费规则

扣减费用 = token 消耗量 × 模型单价,对应的费用将直接从充值余额或赠送余额中进行扣减。 当充值余额与赠送余额同时存在时,优先扣减赠送余额。

产品价格可能发生变动,DeepSeek 保留修改价格的权利。请您依据实际用量按需充值,定期查看此页面以获知最新价格信息。