Word接入ChatGPT的VB代码
欢迎你来到站长在线的代码库,本文的代码是《Word接入ChatGPT的VB代码》我们在Word里面接入ChatGPT的时候,用到的代码段,注意里面要切换自己的apikey哦!
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 = "你的API 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
本文地址:https://www.olzz.com/word-chatgpt.html
码字不易,打个赏呗
杨泽业感谢你的支持!
站长在线站长一对一网络指导服务,一元一分钟,50元一个小时
阿里云虚拟主机1G空间,120元一年
香港、美国虚拟主机100元一年,1000元永久
腾讯云双十一0.4折起,2核8G5M三年仅700元,2核4G8M三年仅198元
阿里云虚拟主机1G空间,120元一年
香港、美国虚拟主机100元一年,1000元永久
腾讯云双十一0.4折起,2核8G5M三年仅700元,2核4G8M三年仅198元
猜你喜欢