<!DOCTYPE html>
<html>
<head>
  <meta charset='utf-8'>
  <meta name='viewport' content='width=device-width, initial-scale=1'>
  <title>ChatGPT 3.5 Turbo 在线聊天</title>
  <script src='https://cdn.jsdelivr.net/npm/@openai/api@0.5.0/dist/openai-api.min.js'></script>
</head>
<body>
  <h1>与 ChatGPT 3.5 Turbo 聊天</h1>
  <div id='chat-window'>
    <div id='output'></div>
    <input type='text' id='input' placeholder='在此输入您的消息'><br>
    <button id='send-btn' onclick='sendMessage()'>发送</button>
  </div>
  <script>
    const openai = new OpenAI(apiKey = 'YOUR_API_KEY_HERE');

    async function sendMessage() {
      const input = document.getElementById('input').value;
      if (input !== '') {
        document.getElementById('input').value = '';
        document.getElementById('output').innerHTML += '<p>您: ' + input + '</p>';
        const response = await openai.complete({
          engine: 'text-davinci-002',
          prompt: '与 ChatGPT 3.5 Turbo 对话:

用户: ' + input + '
ChatGPT 3.5 Turbo:',
          maxTokens: 150,
          n: 1,
          stop: ['\n'],
          temperature: 0.7
        });
        const message = response.data.choices[0].text.trim();
        document.getElementById('output').innerHTML += '<p>ChatGPT 3.5 Turbo: ' + message + '</p>';
      }
    }
  </script>
</body>
</html>
ChatGPT 3.5 Turbo 在线聊天 - 使用 OpenAI API

原文地址: https://www.cveoy.top/t/topic/lBpI 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录