-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
30 lines (28 loc) · 681 Bytes
/
test.js
File metadata and controls
30 lines (28 loc) · 681 Bytes
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
const url = 'https://open-ai21.p.rapidapi.com/chatgpt';
const options = {
method: 'POST',
headers: {
'x-rapidapi-key': '80ad31d0ffmshfc2a215b4bc65b1p1a263cjsned150dde27a9',
'x-rapidapi-host': 'open-ai21.p.rapidapi.com',
'Content-Type': 'application/json'
},
body: JSON.stringify({ // Changed to stringify the body
messages: [
{
role: 'user',
content: 'hello chat gpt tell me a joke'
}
],
web_access: false
})
};
try {
fetchData();
} catch (error) {
console.error(error);
}
async function fetchData() {
const response = await fetch(url, options);
const result = await response.json();
console.log(result);
}