Skip to content

Instantly share code, notes, and snippets.

@zeuslawyer
Created November 9, 2023 07:20
Show Gist options
  • Save zeuslawyer/9ad2ce86950782ee0c3e92564c21de54 to your computer and use it in GitHub Desktop.
Save zeuslawyer/9ad2ce86950782ee0c3e92564c21de54 to your computer and use it in GitHub Desktop.
Functions-OpenAI
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