1.你先要拥有GPT3.5 key
如何获取见上篇
2.配置office选项卡
3.编写vba
Sub ChatGPT()Dim selectedText As StringDim apiKey As StringDim response As Object, re As StringDim midString As StringDim ans As StringIf Selection.Type = wdSelectionNormal ThenselectedText = Selection.TextselectedText = Replace(selectedText, ChrW$(13), "")apiKey = "your key"URL = "https://api.openai.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"":""gpt-3.5-turbo"", ""messages"":[{""role"":""user"",""content"":""" & selectedText & """}], ""temperature"":0.7}"re = response.responseTextmidString = Mid(re, InStr(re, """content"":""") + 11)ans = Split(midString, """")(0)ans = Replace(ans, "\n", "")Selection.Text = selectedText & vbNewLine & ansElseExit SubEnd IfEnd Sub
4.新建vba模块 插入代码
5.先在左边自定义选项卡,然后把邮编的宏放入左边即可
6. 效果
最终运行与网速有关,我这边还是要等一会儿。
结语:
实现上面的功能我主要看了b站up小卫是David的视频。代码也是他写的。原视频目前已删除,侵删。