0

I asked chat gpt to write a chat bot code modeled on gpt3, and he actually wrote it.

The site was created, but messages could not be sent.

I also got a gpt3 api key and used it, but it doesn't seem to work well. What's the problem?

Below is the code written by gpt

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>ChatGPT Demo</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <div class="chat-window">
    <div class="chat-header">
      <h1>ChatGPT</h1>
    </div>
    <div class="chat-body">
      <ul class="message-list">
        <li class="message bot">
          <p>Hello! How can I help you today?</p>
        </li>
      </ul>
    </div>
    <div class="chat-footer">
      <input id="input" type="text" placeholder="Type your message here...">
      <button onclick="send()">Send</button>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/@openai/api"></script>
  <script>
    // OpenAI API Key 설정
    const openai = window.openai;
    const api_key = 'YOUR_API_KEY';
    const model_engine = 'davinci';

    // API 호출하여 응답 받기
    const askGPT3 = async (input) => {
      console.log(input); // This is getting logged but below API is not being called.
      const response = await openai.Completion.create({
        engine: model_engine,
        prompt: input,
        max_tokens: 1024,
        n: 1,
        stop: null,
        temperature: 0.5,
        apiKey: api_key
      });
      return response.choices[0].text.trim();
    };

    // 대화 시작
    const startConversation = async () => {
      const botMessage = document.querySelector('.message.bot p');
      const answer = await askGPT3('Hello!');
      botMessage.innerHTML = answer;
    };
    startConversation();

    // 대화 전송
    const send = async () => {
      const input = document.getElementById('input').value;
      const messageList = document.querySelector('.message-list');
      const userMessage = `<li class="message user"><p>${input}</p></li>`;
      messageList.insertAdjacentHTML('beforeend', userMessage);
      const botMessage = `<li class="message bot"><p>${await askGPT3(input)}</p></li>`;
      messageList.insertAdjacentHTML('beforeend', botMessage);
      document.getElementById('input').value = '';
    };

    // 대화 엔터키 전송
    const input = document.getElementById('input');
    input.addEventListener('keyup', (event) => {
      if (event.keyCode === 13) {
        event.preventDefault();
        document.querySelector('button').click();
      }
    });
  </script>
</body>
</html>

I clicked send to send a message but it doesn't work - the message is not sent to the API.

Nikhil
  • 6,493
  • 10
  • 31
  • 68
이춘자
  • 9
  • 1
  • I created a site through code, but the message is not being sent. I don't even know what the problem is... – 이춘자 Feb 23 '23 at 05:39
  • I updated the question with this info, let us see if someone can help you. – Nikhil Feb 23 '23 at 05:47
  • `openai.Completion.create` - This code should be a calling the API for it to work. I don't know OpenAPI JS SDK, someone else might know more. – Nikhil Feb 23 '23 at 05:54
  • Looks like the there are breaking changes in latest API version: https://www.npmjs.com/package/openai Make these changes: `const model_engine = "text-davinci-002';` And replace `engine: model_engine,` with `model: model_engine,`. – Nikhil Feb 23 '23 at 06:05
  • ChatGPT model doesn't include information about itself. You should verify yourself the responses provided by ChatGPT. If there is a part from the response which you need help with, search thoroughly, share what you found and with it didn't meet your needs as is suggested in [ask]. – Rubén Feb 24 '23 at 02:08
  • 1
    This is exactly why AI won't replace developers. You still need skilled developers who know how to work with, debug and maintain code. The API endpoint that ChatGPT recommended no longer exists it has been replaced. Remember ChatGPT is trained up to 2021. You need to read the API docs and work it out from there: https://platform.openai.com/overview – Kane Hooper Feb 26 '23 at 04:02

1 Answers1

0

It's saying the exact same thing i type. Try saying the exact code then " is not working" or ask again and then say it's not working if it provides the same code.