-
Notifications
You must be signed in to change notification settings - Fork 3
/
openai-test.html
27 lines (26 loc) · 878 Bytes
/
openai-test.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>OpenAI Class Test</title>
</head>
<body>
<h1>OpenAI Class Test</h1>
<textarea id="input1" style="width:100%"></textarea>
<button id="btn1" style="width:25%">Record</button>
<div id="output1"></div>
<script src="openai.js"></script>
<script>
(async () => {
const token = localStorage.getItem('OPENAI_API_KEY') || (prompt("Please input OpenAI API key (stored in browser cache)", "") || '').trim();
const $ = id => document.getElementById(id);
const ai = new OpenAI(token);
await ai.listen($('btn1'), async (spokenText) => {
let input1 = $('input1');
input1.value = spokenText;
ai.chat(input1.value, $('output1'))
});
})();
</script>
</body>
</html>