-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
44 lines (34 loc) · 1.3 KB
/
Copy pathscript.js
File metadata and controls
44 lines (34 loc) · 1.3 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
43
44
import {config} from "dotenv"
config()
import { Configuration,OpenAIApi } from "openai"
const openai = new OpenAIApi(new Configuration({
apiKey: process.env.API_KEY
}))
openai.createChatCompletion({
model:"gpt-3.5-turbo",
messages: [{role:"user",content:"hello"}]
})
.then(res => {
console.log(res.data.choices[0].message.content)});
document.getElementById('submitButton').addEventListener('click', async () => {
const inputText = document.getElementById('inputText').value;
if (inputText) {
try {
const response = await axios.get('https://api.example.com/data', {
params: {
input: inputText
}
});
if (response.data) {
document.getElementById('output').innerHTML = `Output: ${response.data}`;
} else {
document.getElementById('output').innerHTML = 'No output received from the API.';
}
} catch (error) {
console.error('Error:', error);
document.getElementById('output').innerHTML = 'An error occurred while fetching data from the API.';
}
} else {
document.getElementById('output').innerHTML = 'Please enter some text before submitting.';
}
});