Word文档加入ChatGPT功能命令

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), "")appKey = "我的AppKey"apiKey = "我的apiKey"URL = " Set response = CreateObject("MSXML2.XMLHTTP")response.Open "POST", URL, Falseresponse.setRequestHeader "Content-Type", "application/json"response.setRequestHeader "Authorization", appKeyresponse.Send "{""apiKey"":""" & apiKey & """,""model"":""gpt-3.5-turbo-0301"", ""messages"":[{""role"":""user"",""content"":""" & selectedText & """}], ""temperature"":0.3}"re = response.responseTextmidString = Mid(re, InStr(re, """content"":""") + 11)ans = Split(midString, """")(0)ans = Replace(ans, "\n", "" & vbCrLf & "")Selection.Text = selectedText & vbNewLine & ansElseExit SubEnd IfEnd Sub

 

9e53d8cdf23c94f977a397efa7120e6f

原创文章,作者:校长,如若转载,请注明出处:https://www.yundongfang.com/Yun227284.html

(0)
打赏 微信扫一扫不于多少! 微信扫一扫不于多少! 支付宝扫一扫礼轻情意重 支付宝扫一扫礼轻情意重
上一篇 2023年5月3日 下午7:07
下一篇 2023年5月12日