当前位置: 首页 > news >正文

从Word里面用VBA调用NVIDIA的免费DeepSeekR1

看上去能用而已。

选中的文字作为输入,运行对应的宏即可;会先MSGBOX提示一下,然后相关内容追加到word文档中。
在这里插入图片描述

需要自己注册生成好用的apikey

Option ExplicitSub DeepSeek()Dim selectedText As StringDim apiKey As StringDim response As Object, re As StringDim midString As StringDim ans As StringDim URLIf Selection.Type = wdSelectionNormal ThenselectedText = Selection.TextselectedText = Replace(selectedText, ChrW$(13), "")apiKey = "nvapi--LlRnvapi-这里需要自己注册生成api key-LlR_nTfd" '"3f"URL = "https://integrate.api.nvidia.com/v1/chat/completions"Set response = CreateObject("MSXML2.XMLHTTP")response.Open "POST", URL, Falseresponse.setRequestHeader "Content-Type", "application/json"response.setRequestHeader "Authorization", "Bearer " + apiKeyresponse.Send "{""model"":""deepseek-ai/deepseek-r1"", ""messages"":[{""role"":""user"",""content"":""" & selectedText & """}], ""temperature"":0.7}"re = response.responseTextmidString = Mid(re, InStr(re, """content"":""") + 11)MsgBox reans = Split(midString, """")(0)ans = Replace(ans, "\n", "")Selection.Text = selectedText & vbNewLine & ansElseExit SubEnd IfEnd SubSub DeepSeekPolish()Dim selectedText As StringDim apiKey As StringDim response As Object, re As StringDim midString As StringDim ans As StringDim polishPrompt As StringDim URL' 检查是否有正常选中的文本If Selection.Type = wdSelectionNormal Then' 获取选中文本并去除不需要的字符selectedText = Selection.TextselectedText = Replace(selectedText, ChrW$(13), "")' 定义API密钥和请求URLapiKey = "nvapi-这里需要自己注册生成api key-LlR" ' URL = "https://integrate.api.nvidia.com/v1/chat/completions"' 设置润色提示词polishPrompt = "请润色以上文字,要求语句通顺,条理清晰,专业而合理。"' 创建HTTP请求对象并设置参数Set response = CreateObject("MSXML2.XMLHTTP")response.Open "POST", URL, False' 添加必要的头部信息response.setRequestHeader "Content-Type", "application/json"response.setRequestHeader "Authorization", "Bearer " + apiKey' 发送请求,注意在JSON字符串中添加了polishPromptresponse.Send "{""model"":""deepseek-ai/deepseek-r1"", ""messages"":[{""role"":""user"",""content"":""" & selectedText & """}, {""role"":""assistant"", ""content"":""" & polishPrompt & """}], ""temperature"":0.7}"' 处理响应数据re = response.responseTextMsgBox remidString = Mid(re, InStr(re, """content"":""") + 11)ans = Split(midString, """")(0)ans = Replace(ans, "\n", "")' 将原选中文本与润色后的文本一起插入文档中Selection.Text = selectedText & vbNewLine & ansElseExit SubEnd If
End Sub

http://www.mrgr.cn/news/90479.html

相关文章:

  • SQL面试题4:相互关注问题
  • Alertmanager 收敛规则
  • 【MySQL】# Windows下安装(压缩包、msi);Linux下安装(压缩包、命令、docker);设置连接数、binlog日志;修改时区
  • 数字孪生遭遇 “DeepSeek 之问”:谁在批量制造昂贵玩具?
  • 游戏节奏分析:游戏越来越不好玩的原因
  • IntelliJ IDEA 安装与使用完全教程:从入门到精通
  • JESD204B及解扰模块
  • Alertmanager 收敛规则
  • <工具 Claude Desktop> 配置 fetch MCP Server
  • (2025)深度分析DeepSeek-R1开源的6种蒸馏模型之间的逻辑处理和编写代码能力区别以及配置要求,并与ChatGPT进行对比(附本地部署教程)
  • 算法练习——滑动窗口
  • mysql读写分离与proxysql的结合
  • 使用k3s高可用部署rancher
  • YOLO自定义数据集实现K折交叉验证——K-Fold Cross Validation
  • 使用grafana v11 建立k线(蜡烛图)仪表板
  • CF Round 997 记录 题解 (div. 2 A - E)
  • PyQt学习记录03——批量设置水印
  • 算法很美笔记(Java)——树
  • package.json 文件配置
  • 华为云kubernetes基于keda自动伸缩deployment副本(监听redis队列长度)
  • python 获取smpl身高 fbx身高
  • 如何使用Java语言在Idea和Android中分别建立服务端和客户端实现局域网聊天
  • Android 14.0 Launcher3单层模式workspace中app列表页排序功能实现
  • @synchronized的使用
  • 使用 Express 写接口
  • 自己部署DeepSeek 助力 Vue 开发:打造丝滑的标签页(Tabs)