Created
December 19, 2020 20:28
-
-
Save qasimy123/61807713a79f1e2822ac253daa842d42 to your computer and use it in GitHub Desktop.
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 OpenAI = require('openai-api'); | |
const openai = new OpenAI(process.env.OPEN_AI_API_KEY); | |
const formatToInput = (body) => { | |
const context = ` | |
This is a LinkedIn Bio Generator | |
Name: John | |
Student: Yes | |
Degree: Bachelor’s of Commerce | |
Year: third | |
Major: Marketing | |
Interest: Marketing, Entrepreneurship, mountain biking, travel | |
LinkedIn Bio: John is a third year Marketing Major. He has spent the last six years working in the fast-paced world of startups. John has a passion for entrepreneurship and marketing. He specializes in developing and marketing web and mobile applications. When he's not pushing pixels around, John enjoys mountain biking and travel. | |
### | |
Name: Amaira | |
Student: Yes | |
Degree: Bachelor’s of Engineering | |
Year: 2nd | |
Major: Psychology | |
Interest: Developmental Psychology, Abnormal Psychology, Cat | |
LinkedIn Bio: Amaira is a second year student studying psychology and specializing in Developmental and Abnormal Psychology. In her spare time she enjoys practicing yoga, trying out new recipes, and spending time with her cat. | |
### | |
Name: Marcus | |
Student: Yes | |
Degree: Bachelor’s of Arts | |
Year: 4 | |
Major: Double Major in Psychology and Management | |
Interest: Start-up, Swimming, Reddit | |
LinkedIn Bio: Marcus is a 4th year student studying Psychology. He is a double major in management and psychology and he specializes in behavioral economics and social psychology. Marcus has a passion for start-ups and spends much of his time working and volunteering at start-ups. In his spare time, Marcus enjoys swimming and reading reddit. | |
### | |
` | |
const { degree, name, major, interests, year } = JSON.parse(body) | |
console.log(degree, name, major, interests, year) | |
const newPrompt = `Name: ${name.slice(0, 70)} | |
Student: Yes | |
Degree: ${degree.slice(0, 70)} | |
Year: ${year.slice(0, 70)} | |
Major: ${major.slice(0, 70)} | |
Interest: ${interests.slice(0, 140)} | |
LinkedIn Bio:` | |
return context.concat(newPrompt) | |
} | |
const gptResponse = async (input) => { | |
const newInput = formatToInput(input) | |
const res = await openai.complete({ | |
engine: 'davinci', | |
prompt: newInput, | |
maxTokens: 150, | |
temperature: 0.78, | |
topP: 1, | |
presence_penalty: 0, | |
frequency_penalty: 0, | |
best_of: 1, | |
n: 1, | |
stream: false, | |
stop: ["###"] | |
}); | |
return res.data.choices[0].text; | |
} | |
export default gptResponse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment