-
Notifications
You must be signed in to change notification settings - Fork 5
/
step1.html
47 lines (43 loc) · 1.35 KB
/
step1.html
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
<!DOCTYPE html>
<html>
<head>
<title>OpenAI Web Project</title>
</head>
<body>
<h1>Using OpenAI </h1>
<p>OpenAI API Key:</p>
<input type="text" id="apiKey">
<br><br>
<p>Keyword:</p>
<input type="text" id="keyword">
<br><br>
<button onclick="generateTitle()">Create Title</button>
<br><br>
<p id="result"></p>
<script>
async function generateTitle() {
let API_KEY = document.getElementById("apiKey").value;
const keyword = document.getElementById("keyword").value;
const prompt = `Generate an article title related to "${keyword}`;
const model = "text-davinci-003";
const response = await fetch(`https://api.openai.com/v1/completions`,
{
body: JSON.stringify({"model": model, "prompt": prompt, "max_tokens": 70}),
method: "POST",
headers: {
"content-type": "application/json",
Authorization: `Bearer ${API_KEY}`,
},
}
).then((response) => {
if (response.ok) {
response.json().then((json) => {
const title = json.choices[0].text.trim();
document.getElementById("result").innerHTML = title;
});
}
});
}
</script>
</body>
</html>