Last active
January 6, 2023 22:10
-
-
Save FeMaffezzolli/ad1c8c9647a1b30d19043bcf3d800f7f to your computer and use it in GitHub Desktop.
openai-node
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 express = require("express"); | |
const OpenAI = require("openai-api"); | |
const app = express(); | |
const port = 3000; | |
// load API_KEY from env | |
const OPENAI_API_KEY = "API_KEY"; | |
const openai = new OpenAI(OPENAI_API_KEY); | |
const sendMessage = async (message) => { | |
const gptResponse = await openai.complete({ | |
engine: "text-davinci-003", | |
prompt: message, | |
temperature: 0, | |
top_p: 1, | |
n: 1, | |
stream: true, | |
logprobs: null, | |
//stop: "\n", | |
}); | |
return gptResponse.data; | |
}; | |
app.get("/", (req, res) => { | |
const { q } = req.query; | |
sendMessage(q).then((value) => { | |
res.send(value); | |
}); | |
}); | |
app.listen(port, () => { | |
console.log(`listening on port ${port}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment