Created
March 29, 2024 23:45
-
-
Save u1and0/efabf2981c8b8fe34515295fcc74c404 to your computer and use it in GitHub Desktop.
Simple GPT client Using deno
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 apiKey = Deno.env.get("CHATGPT_API_KEY"); | |
const url = "https://api.openai.com/v1/chat/completions"; | |
const content = await fetch(url, { | |
method: "POST", | |
headers: { | |
"Content-Type": "application/json", | |
"Authorization": `Bearer ${apiKey}`, | |
}, | |
body: JSON.stringify({ | |
model: "gpt-3.5-turbo", | |
max_tokens: 1000, | |
temperature: 1.0, | |
messages: [ | |
{ "role": "user", "content": "hi" }, | |
], | |
}), | |
}) | |
.then((response) => response.json()) | |
.then((data) => { | |
if (data.error) { | |
console.error(data); | |
} | |
else { | |
return data.choices[0].message.content; | |
} | |
}) | |
.catch((error) => { | |
console.error(`Fetch request failed: ${error}`); | |
}); | |
console.log(content); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment