-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test_server.js
35 lines (31 loc) · 958 Bytes
/
client_test_server.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
// get api response
const apiUrl = 'http://localhost:3000/api/openai/completions'; // API endpoint on your server
const callItself = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content:
`What is 1c in fahrenheit.
Give the final response in fahrenheit. no extra text.` },
],
model: "gpt-3.5-turbo",
max_tokens: 2
})
}
// console.log(callItself)
const output = document.getElementById('output')
async function makeApiCall() {
try {
const response = await fetch(apiUrl, callItself);
const data = await response.json();
console.log(data)
output.textContent = JSON.stringify(data)
} catch (error) {
console.error('Error:', error);
}
}
makeApiCall();