回复 2# jyswjjgdwtdtj
这个一个openai用在excel里面的vba,只修改它的地址和key,用不了。所以要根据上面那个实例修改~- Function ChatGPT(prompt As String) As String
-
- Dim url As String, apiKey As String
- Dim response As Object, re As String
- Dim midString As String
-
- apiKey = "your_api_key"
- url = "https://api.openai.com/v1/engines/text-davinci-003/completions"
-
- Set response = CreateObject("MSXML2.XMLHTTP")
- response.Open "POST", url, False
- response.setRequestHeader "Content-Type", "application/json"
- response.setRequestHeader "Authorization", "Bearer " + apiKey
- response.Send "{""prompt"":""" & prompt & """,""max_tokens"":1024, ""temperature"":0.1}"
-
- re = response.responseText
- midString = Mid(re, InStr(re, """text"":""") + 8)
- ChatGPT = Split(midString, """")(0)
- ChatGPT = Replace(ChatGPT, "\n", "")
-
- End Function
复制代码
|