forked from CosmicAnty/cosmicanty.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyScript.js
87 lines (70 loc) · 2.32 KB
/
myScript.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
let i = 1;
function add() {
i++;
document.getElementById("par").innerHTML = i;
}
function minus() {
i--;
document.getElementById("par").innerHTML = i;
}
function reset() {
i=0;
document.getElementById("par").innerHTML = 0;
}
document.getElementById("par").innerHTML = i;
const addButton = document.getElementById("add")
const resetButton = document.getElementById("reset")
const minusButton = document.getElementById("minus")
addButton.addEventListener('click', (event)=> {
add()
})
resetButton.addEventListener('click', (event)=> {
reset()
})
minusButton.addEventListener('click', (event)=> {
minus()
})
const prompt = document.getElementById("prompt");
prompt.addEventListener('keypress', (event)=> {
if (event.keyCode === 13) {
event.preventDefault();
document.getElementById("output").innerHTML = "loading...";
api(prompt.value)
.then(response => {
document.getElementById("output").innerHTML = response;
});
// document.getElementById("output").innerHTML = "This function is still in production...<br> come back later";
}
})
const api = async function(prompt) {
const { Configuration, OpenAIApi } = require("openai");
key = "sk-HSowNjhUsbERaLBznV1dT3Bl" + "bkFJ27FDLWkJ1AkSVEe7yYg1"
const configuration = new Configuration({
apiKey: key,
});
const openai = new OpenAIApi(configuration);
const response = await openai.createCompletion({
model: "text-davinci-002",
prompt: prompt,
temperature: 0.7,
max_tokens: 3000,
top_p: 1,
frequency_penalty: 0.7,
presence_penalty: 0.7,
});
console.log("The following log is the parsed response from the API")
parsed = response.data.choices[0].text
console.log(parsed)
return parsed
// document.getElementById("output").innerHTML = response
}
const toggleButton = document.getElementsByClassName('toggle-button')[0]
const navbarLinks = document.getElementsByClassName('navbar-links')[0]
const projectButton = document.getElementsByClassName('project-button')[0]
const projectLinks = document.getElementsByClassName('projects')[0]
toggleButton.addEventListener('click', () => {
navbarLinks.classList.toggle('active')
})
projectButton.addEventListener('click', () => {
projectLinks.classList.toggle('active')
})