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
正文完