-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatGPT.html
More file actions
48 lines (43 loc) · 1.52 KB
/
chatGPT.html
File metadata and controls
48 lines (43 loc) · 1.52 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
45
46
47
48
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Chat GPT</title>
</head>
<body>
<input>
<p></p>
</body>
<script>
const myAPIKEY = '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';
// Define the API endpoint and authorization token
const apiUrl = 'https://api.openai.com/v1/engines/davinci-codex/completions';
const apiToken = 'ysk-GsM4pQqXWUV6P8a1ftGCT3BlbkFJJPo9yBeZbPIt9ncC5204';
// Define a function to generate text using the ChatGPT API
async function generateText(prompt) {
// Define the API request body
const requestBody = {
'prompt': prompt,
'max_tokens': 50,
'n': 1,
'stop': '\n',
};
// Send the API request and wait for the response
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiToken}`,
},
body: JSON.stringify(requestBody),
});
// Parse the response JSON and return the generated text
const data = await response.json();
return data.choices[0].text.trim();
}
// Call the generateText function with a prompt and display the result
generateText('Hello, ChatGPT!').then(text => console.log(text));
</script>
</html>