【Word内置DeepSeek大模型】

在这里插入图片描述

【Word内置DeepSeek大模型】

一 、效果演示

以Word为例,PPT与EXCEL同样适用。
选中文本即可实现模型回复,例如,在Word文档中提问写作文的技巧。
在这里插入图片描述

二 、各大AI模型 API Key 获取地址

⚡ 点击对应链接,快速申请 API Key,畅享 AI 强大算力!

三 、配置Word

  1. 启用开发者工具

    • 新建Word,点击 文件 -> 选项 -> 自定义功能区

    • 勾选"开发者工具"
      在这里插入图片描述

  2. 配置信任中心

    • 点击 信任中心 -> 信任中心设置
  • 选择"启用所有宏"与"信任对VBA…"

在这里插入图片描述

  1. 添加模块

    • 点击开发者工具,点击Visual Basic

    • 在新窗口中点击插入,选择模块

    • 将代码复制到编辑区中(注意替换你自己的API key

      在这里插入图片描述

  2. 自定义功能区

    • 点击 文件 -> 选项 -> 自定义功能区

    • 右键开发工具,点击添加新组

      • 右键新建组,点击重命名
    • 将其命名为"DeepSeek",选择心仪的图标

    • 点击确定
      在这里插入图片描述

  3. 添加命令

    • 选择DeepSeek(自定义)

    • 在左侧命令中选择"宏"

    • 找到并选中"DeepSeekV3",点击添加

    • 右键添加的命令,点击重命名

    • 选择开始符号作为图标

    • 重命名为"DeepSeekV3"
      在这里插入图片描述

四、 使用方法

  1. 选中需要处理的文字

  2. 点击"DeepSeekV3"按钮

  3. 等待大模型响应

在这里插入图片描述在这里插入图片描述

五、 创建模板

  1. 将文档另存为 Word 模板 (.dotm):
    • 点击"文件" → “另存为”

    • 选择保存类型为"Word 启用宏的模板 (.dotm)"

    • 保存到 Word 的模板文件夹(通常是 C:\Users\用户名\AppData\Roaming\Microsoft\Word\STARTUP)

    • 这样每次打开 Word 时,宏就会自动可用

      在这里插入图片描述

六 、相关代码

主要介绍DeepSeekV3、deepseek-reasoner、qwen2.5-max、gpt-4o-mini这四种大模型嵌入到word的代码。

1 DeepSeekV3代码

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 = "替换为你的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 =</
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值