当前位置: 首页 > 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.lryc.cn/news/534807.html

相关文章:

  • 【SpringBoot篇】基于Redis分布式锁的 误删问题 和 原子性问题
  • 【JVM详解三】垃圾回收机制
  • MySQL的字符集(Character Set)和排序规则(Collation)
  • 2025影视泛目录站群程序设计_源码二次开发新版本无缓存刷新不变实现原理
  • 常用的python库-安装与使用
  • array_walk. array_map. array_filter
  • 数据仓库和商务智能:洞察数据,驱动决策
  • Vue设计模式到底多少种?
  • HTML 属性
  • oracle如何查询历史最大进程数?
  • SpringBoot单机模式,能否支持一万用户请求并发?
  • [前端]CRX持久化
  • 模型 替身决策
  • 【系统架构设计师】体系结构文档化
  • Python Pandas(5):Pandas Excel 文件操作
  • 区块链技术:Facebook 重塑社交媒体信任的新篇章
  • 跨平台App开发,有哪些编程语言和工具,比较一下优劣势?
  • Windows逆向工程入门之汇编环境搭建
  • 网络安全溯源 思路 网络安全原理
  • 《Peephole LSTM:窥视孔连接如何开启性能提升之门》
  • viem库
  • Iceberg and AIStor 的Lakehouse Architecture 权威指南
  • TCP/IP 协议图解 | TCP 协议详解 | IP 协议详解
  • 第四节 docker基础之---dockerfile部署JDK
  • Arcgis/GeoScene API for JavaScript 三维场景底图网格设为透明
  • 基于javaweb的SpringBoot电影推荐系统
  • 【kafka系列】Topic 与 Partition
  • 大数据项目2:基于hadoop的电影推荐和分析系统设计和实现
  • [笔记] 汇编杂记(持续更新)
  • 同步阻塞IO和多路复用IO(epoll)的性能对比