1.你先要拥有GPT3.5 key
如何获取见上篇
2.配置office选项卡
3.编写vba
Sub ChatGPT()
Dim selectedText As String
Dim apiKey As String
Dim response As Object, re As String
Dim midString As String
Dim ans As String
If Selection.Type = wdSelectionNormal Then
selectedText = Selection.Text
selectedText = Replace(selectedText, ChrW$(13), "")
apiKey = "your key"
URL = "https://api.openai.com/v1/chat/completions"
Set response = CreateObject("MSXML2.XMLHTTP")
response.Open "POST", URL, False
response.setRequestHeader "Content-Type", "application/json"
response.setRequestHeader "Authorization", "Bearer " + apiKey
response.Send "{""model"":""gpt-3.5-turbo"", ""messages"":[{""role"":""user"",""content"":""" & selectedText & """}], ""temperature"":0.7}"
re = response.responseText
midString = Mid(re, InStr(re, """content"":""") + 11)
ans = Split(midString, """")(0)
ans = Replace(ans, "\n", "")
Selection.Text = selectedText & vbNewLine & ans
Else
Exit Sub
End If
End Sub
4.新建vba模块 插入代码
5.先在左边自定义选项卡,然后把邮编的宏放入左边即可
6. 效果
最终运行与网速有关,我这边还是要等一会儿。文章来源:https://www.toymoban.com/news/detail-510979.html
结语:
实现上面的功能我主要看了b站up小卫是David的视频。代码也是他写的。原视频目前已删除,侵删。文章来源地址https://www.toymoban.com/news/detail-510979.html
到了这里,关于GPT3.5 与word的结合,提前享受office copilot的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!