Created
November 9, 2023 07:20
-
-
Save zeuslawyer/9ad2ce86950782ee0c3e92564c21de54 to your computer and use it in GitHub Desktop.
Functions-OpenAI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gptPrompt = args[0]; | |
const postData = { | |
model: "gpt-3.5-turbo", | |
messages: [{ role: "user", content: gptPrompt }], | |
temperature: 0, | |
}; | |
const openAIResponse = await Functions.makeHttpRequest({ | |
url: "https://api.openai.com/v1/chat/completions", | |
method: "POST", | |
headers: { | |
Authorization: `Bearer ${secrets.apiKey}`, | |
"Content-Type": "application/json", | |
}, | |
data: postData, | |
}); | |
if (openAIResponse.error) { | |
throw new Error(JSON.stringify(openAIResponse)); | |
} | |
const result = openAIResponse.data.choices[0].message.content; | |
console.log(result); | |
return Functions.encodeString(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment