Skip to content

Instantly share code, notes, and snippets.

@v0xel1337
Created April 21, 2024 19:22
Show Gist options
  • Save v0xel1337/08c4d9d9b0876718c7aa0a9401d4be2f to your computer and use it in GitHub Desktop.
Save v0xel1337/08c4d9d9b0876718c7aa0a9401d4be2f to your computer and use it in GitHub Desktop.
var request = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + config.chatGpt.secret
},
body: JSON.stringify({
model: "gpt-3.5-turbo",
messages: [{
role: "user",
content: getDialoguePrompt(index).replace("<topic>", req[0].topic)
}],
temperature: 0.7
})
};
console.log("Generating script for topic: " + req[0].topic);
var response = await fetch("https://api.openai.com/v1/chat/completions", request);
var jsonResponse = await response.json();
try {
var preProcessed = processText(jsonResponse.choices[0].message.content);
var messages = validateCharacters(preProcessed);
} catch (e) {
console.log("Chat GPT failed to respond. Re-generating script");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment