Skip to content

Instantly share code, notes, and snippets.

@alongubkin
Created September 19, 2024 15:55
Show Gist options
  • Save alongubkin/c2619a74fe8a2a4cd65f55b87f4965c4 to your computer and use it in GitHub Desktop.
Save alongubkin/c2619a74fe8a2a4cd65f55b87f4965c4 to your computer and use it in GitHub Desktop.
/**
* @customfunction
*/
async function completion(content: string) {
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <OPENAI_API_KEY>"
},
body: JSON.stringify({
model: "gpt-4o",
temperature: 0,
messages: [
{
role: "system",
content
}
]
})
});
const result = await response.json();
return result["choices"][0]["message"]["content"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment