免费deepseek的API获取教程及将API接入word或WPS中

embedded/2025/2/22 20:54:33/

免费deepseek的API获取教程:

1 火山方舟 https://console.volcengine.com/中注册 填写邀请码:WGDGUTTL 即可获取3250万R1模型tokens
或硅基流动 https://cloud.siliconflow.cn/中注册时填写邀请码:GAejkK6X即可获取2000 万 Tokens;

2 按照图中步骤进行操作
在这里插入图片描述

wordWPS_8">将API接入word或WPS中

1 打开一个word,文件-选项-自定义功能区-勾选开发工具-左侧的信任中心-信任中心设置-宏设置-启用所有宏-确定
在这里插入图片描述
2
2 开发工具-VB-插入-模块
在这里插入图片描述
在这里插入图片描述

3 在调出的窗口中输入如下代码

word">Function CallDeepSeekAPI(api_key word">As word">String, inputText word">As word">String) word">As word">Stringword">Dim API word">As word">Stringword">Dim SendTxt word">As word">Stringword">Dim Http word">As word">Objectword">Dim status_code word">As word">Integerword">Dim response word">As word">StringAPI = "https://api.siliconflow.cn/v1/chat/completions" SendTxt = "{""model"": ""deepseek-ai/DeepSeek-V3"", ""messages"": [{""role"":""system"", ""content"":""You are a Word assistant""}, {""role"":""user"", ""content"":""" & inputText & """}], ""stream"": false}"word">Set Http = CreateObject("MSXML2.XMLHTTP")word">With Http.word">Open "POST", API, word">False.setRequestHeader "Content-Type", "application/json".setRequestHeader "Authorization", "Bearer " & api_key.send SendTxtstatus_code = .Statusresponse = .responseTextword">End word">With' 弹出窗口显示 API 响应(调试用)' MsgBox "API Response: " & response, vbInformation, "Debug Info"word">If status_code = 200 word">ThenCallDeepSeekAPI = responseword">ElseCallDeepSeekAPI = "Error: " & status_code & " - " & responseword">End word">Ifword">Set Http = word">Nothing
word">End word">Functionword">Sub DeepSeekV3()word">Dim api_key word">As word">Stringword">Dim inputText word">As word">Stringword">Dim response word">As word">Stringword">Dim regex word">As word">Objectword">Dim matches word">As word">Objectword">Dim originalSelection word">As word">Objectapi_key = "替换为你的api key"word">If api_key = "" word">ThenMsgBox "Please enter the API key."word">Exit word">Subword">ElseIf Selection.word">Type <> wdSelectionNormal word">ThenMsgBox "Please select text."word">Exit word">Subword">End word">If' 保存原始选中的文本word">Set originalSelection = Selection.Range.DuplicateinputText = Replace(Replace(Replace(Replace(Replace(Selection.text, "\", "\\"), vbCrLf, ""), vbCr, ""), vbLf, ""), Chr(34), "\""")response = CallDeepSeekAPI(api_key, inputText)word">If Left(response, 5) <> "Error" word">Thenword">Set regex = CreateObject("VBScript.RegExp")word">With regex.word">Global = word">True.MultiLine = word">True.IgnoreCase = word">False.Pattern = """content"":""(.*?)"""word">End word">Withword">Set matches = regex.Execute(response)word">If matches.Count > 0 word">Thenresponse = matches(0).SubMatches(0)response = Replace(Replace(response, """", Chr(34)), """", Chr(34))' 取消选中原始文本Selection.Collapse Direction:=wdCollapseEnd' 将内容插入到选中文字的下一行Selection.TypeParagraph ' 插入新行Selection.TypeText text:=response' 将光标移回原来选中文本的末尾originalSelection.word">Selectword">ElseMsgBox "Failed to parse API response.", vbExclamationword">End word">Ifword">ElseMsgBox response, vbCriticalword">End word">If
word">End word">Sub

在使用火山方舟时API更改为: API = “https://ark.cn-beijing.volces.com/api/v3/chat/completions”
并将相应密匙进行更改即可

4 文件-选项-自定义功能区-选中开发工具-新建组(命名为deepseek)
在这里插入图片描述
5 中间框中依次选中“宏”-deepseek模型-(选中刚创建的deepseek组)添加
6 文件-另存为带宏的模板-放入C:\Users<YourUsername>\AppData\Roaming\Microsoft\Word\STARTUP中,完成

7上述代码为v3模型,r1模型代码如下:

word">Function CallDeepSeekAPI(api_key word">As word">String, inputText word">As word">String) word">As word">Stringword">Dim API word">As word">Stringword">Dim SendTxt word">As word">Stringword">Dim Http word">As word">Objectword">Dim status_code word">As word">Integerword">Dim response word">As word">StringAPI = "https://api.siliconflow.cn/v1/chat/completions"SendTxt = "{""model"": ""deepseek-ai/DeepSeek-R1"", ""messages"": [{""role"":""system"", ""content"":""You are a Word assistant""}, {""role"":""user"", ""content"":""" & inputText & """}], ""stream"": false}"word">Set Http = CreateObject("MSXML2.XMLHTTP")word">With Http.word">Open "POST", API, word">False.setRequestHeader "Content-Type", "application/json".setRequestHeader "Authorization", "Bearer " & api_key.send SendTxtstatus_code = .Statusresponse = .responseTextword">End word">With' 弹出窗口显示 API 响应(调试用)' MsgBox "API Response: " & response, vbInformation, "Debug Info"word">If status_code = 200 word">ThenCallDeepSeekAPI = responseword">ElseCallDeepSeekAPI = "Error: " & status_code & " - " & responseword">End word">Ifword">Set Http = word">Nothing
word">End word">Functionword">Sub DeepSeekR1()word">Dim api_key word">As word">Stringword">Dim inputText word">As word">Stringword">Dim response word">As word">Stringword">Dim regex word">As word">Objectword">Dim matches word">As word">Objectword">Dim originalSelection word">As word">Objectapi_key = "替换为你的api key"word">If api_key = "" word">ThenMsgBox "Please enter the API key."word">Exit word">Subword">ElseIf Selection.word">Type <> wdSelectionNormal word">ThenMsgBox "Please select text."word">Exit word">Subword">End word">If' 保存原始选中的文本word">Set originalSelection = Selection.Range.DuplicateinputText = Replace(Replace(Replace(Replace(Replace(Selection.text, "\", "\\"), vbCrLf, ""), vbCr, ""), vbLf, ""), Chr(34), "\""")response = CallDeepSeekAPI(api_key, inputText)word">If Left(response, 5) <> "Error" word">Thenword">Set regex = CreateObject("VBScript.RegExp")word">With regex.word">Global = word">True.MultiLine = word">True.IgnoreCase = word">False.Pattern = """content"":""(.*?)"""word">End word">Withword">Set matches = regex.Execute(response)word">If matches.Count > 0 word">Thenresponse = matches(0).SubMatches(0)response = Replace(Replace(response, """", Chr(34)), """", Chr(34))' 取消选中原始文本Selection.Collapse Direction:=wdCollapseEnd' 将内容插入到选中文字的下一行Selection.TypeParagraph ' 插入新行Selection.TypeText text:=response' 将光标移回原来选中文本的末尾originalSelection.word">Selectword">ElseMsgBox "Failed to parse API response.", vbExclamationword">End word">Ifword">ElseMsgBox response, vbCriticalword">End word">If
word">End word">Sub

完整版见链接:https://rvq2yh94tm.feishu.cn/docx/HXLDdLmZcoE7hGxS1RqcomEanSd


http://www.ppmy.cn/embedded/164437.html

相关文章

Vue Axios

Vue 渐进式JavaScript 框架 基于Vue2的学习笔记 - Vue 使用 - Axios 目录 Axios 请求方法 功能 安装 使用CDN 引入axios 使用axios 赋值 总结 Axios Axios&#xff0c;基于 Promise 的 HTTP 客户端&#xff0c;可以工作于浏览器中&#xff0c;也可以在 node.js 中使用…

JMeter 中实现 100 个用户在 3 秒内并发登录

在 JMeter 中实现 100 个用户在 3 秒内并发登录,需要合理配置线程组、定时器和测试逻辑。以下是具体步骤: 1. 创建测试计划 打开 JMeter。右键点击“Test Plan”,选择 Add > Threads (Users) > Thread Group。 : 设置为 100(模拟 100 个用户)。 : 设置为 3

计算机视觉算法实战——图像风格迁移(主页有源码)

✨个人主页欢迎您的访问 ✨期待您的三连 ✨ ✨个人主页欢迎您的访问 ✨期待您的三连 ✨ ✨个人主页欢迎您的访问 ✨期待您的三连✨ ​ 一、图像风格迁移领域简介✨✨ 图像风格迁移&#xff08;Image Style Transfer&#xff09;是计算机视觉领域的核心技术之一&#xff0c;旨在…

AI赋能生态学暨“ChatGPT+”多技术融合在生态系统服务中的实践技术应用与论文撰写

随着全球城市化进程的加速与人类活动的频繁&#xff0c;土地利用及生态系统服务面临巨大的压力&#xff0c;水土流失、植被退化、生物多样性丧失等环境问题日益严重。如何在土地供需矛盾中维持生态安全、优化土地利用模式&#xff0c;成为当前生态学与土地规划领域的研究重点。…

DeepSeek VS OpenAI:AI巨头应用对比

DeepSeek 和 OpenAI 都是领先的 AI 公司&#xff0c;具备各自的优势。这两天我读了一篇很棒的文章&#xff0c;作者Da-vinci对这两家AI巨头做了很直观的介绍比较。以下是来自原创的部分内容&#xff1a; DeepSeek、ChatGPT 比较表 DeepSeek、ChatGPT 比较表 | 来源于Da-vinci …

基于Java实现宠物领养救助交流平台设计和实现

基于Java实现宠物领养救助交流平台设计和实现 &#x1f345; 作者主页 网顺技术团队 &#x1f345; 欢迎点赞 &#x1f44d; 收藏 ⭐留言 &#x1f4dd; &#x1f345; 文末获取源码联系方式 &#x1f4dd; &#x1f345; 查看下方微信号获取联系方式 承接各种定制系统 &#x…

IntelliJ IDEA 控制台输出中文出现乱码

IntelliJ IDEA 控制台输出中文出现乱码通常是由于编码设置不一致导致的。以下是常见原因及解决方法 1. 项目编码设置 检查路径&#xff1a;File → Settings → Editor → File Encodings 确保 Project Encoding、Global Encoding 和 Default Encoding for Properties Files 均…

LLaMA-Factory 微调 Qwen2-VL 进行人脸情感识别

引言 随着人工智能技术的飞速发展,人脸情感识别技术逐渐成为人机交互、智能监控等领域的重要研究方向。然而,传统的人脸情感识别方法往往受限于数据集的规模和模型的泛化能力。为了提升人脸情感识别的准确性和鲁棒性,本文采用LLaMA-Factory框架对Qwen2-VL大模型进行微调,以…