forked from buildspace/gpt3-writer-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,36 @@ | ||
// Imports the Configuration and OpenAIApi classes from the openai library | ||
import { Configuration, OpenAIApi } from 'openai'; | ||
|
||
// Creates a Configuration instance with the OpenAI API key from the environment variable | ||
const configuration = new Configuration({ | ||
apiKey: process.env.OPENAI_API_KEY, | ||
}); | ||
|
||
// Creates an OpenAIApi instance using the Configuration instance | ||
const openai = new OpenAIApi(configuration); | ||
|
||
// Define the prefix for the API prompt | ||
const basePromptPrefix = ""; | ||
|
||
// Define the generateAction function | ||
const generateAction = async (req, res) => { | ||
// Run first prompt | ||
// Log the API request | ||
console.log(`API: ${basePromptPrefix}${req.body.userInput}`) | ||
|
||
// Call the OpenAI API to generate a response to the prompt | ||
const baseCompletion = await openai.createCompletion({ | ||
model: 'text-davinci-003', | ||
prompt: `${basePromptPrefix}${req.body.userInput}`, | ||
temperature: 0.7, | ||
max_tokens: 250, | ||
}); | ||
|
||
// Get the response from the API call | ||
const basePromptOutput = baseCompletion.data.choices.pop(); | ||
|
||
// Return the response to the client | ||
res.status(200).json({ output: basePromptOutput }); | ||
}; | ||
|
||
export default generateAction; | ||
// Export the generateAction function | ||
export default generateAction; |
3e1b4d7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
574ward – ./
574ward-alfrencho.vercel.app
gpt3-writer-starter-brown.vercel.app
www.574ward.com
574ward-git-main-alfrencho.vercel.app