Skip to content

Instantly share code, notes, and snippets.

@cmdwm
Last active April 10, 2023 01:50
Show Gist options
  • Save cmdwm/2745c102e413311c81a41d2627d6db47 to your computer and use it in GitHub Desktop.
Save cmdwm/2745c102e413311c81a41d2627d6db47 to your computer and use it in GitHub Desktop.
The code we use to fetch and return ChatGPT responses with a custom prompt. This code has been simplified to be user friendly from what is currently used at WowAgent. We do not and will not provide official support for this code, and it may become outdated. Use at your own risk, no warranty is given or implied.
var options = {
'method': 'POST',
'url': 'https://api.openai.com/v1/chat/completions',
'headers': {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': process.env.openAiKey
},
body: JSON.stringify({
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "system",
"content": prompt
},
{
"role": "user",
"content": req.query.prompt
}
]
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
return `<span style="font-size: 20px; font-family: Arial;">${JSON.parse(response.body).choices[0].message.content}</span>`
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment