-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
42 lines (36 loc) · 1.2 KB
/
index.js
File metadata and controls
42 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fetch = require("isomorphic-fetch");
const API_KEY = "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"
async function getProjectIdea(userInput) {
const endpoint = "https://api.openai.com/v1/engines/text-davinci-002/completions"
const body = {
prompt: userInput,
max_tokens: 250,
stop: "Project completed",
temperature: 0.75
}
try {
const response = await fetch(endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify(body)
});
const json = await response.json();
if (json.choices && json.choices.length > 0) {
return json.choices[0].text;
} else {
console.error('No project ideas found');
return '';
}
} catch (err) {
console.error(err);
}
}
async function main() {
const userInput = "I am a beginner coder and I want to create a project using java, what are some project ideas that I can work on?";
const projectIdea = await getProjectIdea(userInput);
console.log(projectIdea);
}
main();