Skip to content

About

A professional qr code design

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 

Repository files navigation

<title>AI Chatbot</title> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.min.js"></script> <style> .chatlog { height: 300px; overflow-y: scroll; }
  .clear-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
  }
</style>

AI Chatbot

Welcome to our AI Chatbot. How can I assist you today?


Send
Clear Chat Log
<script> const chatlog = document.querySelector(".chatlog"); const inputField = document.querySelector("input"); const sendButton = document.querySelector("#button-addon2"); const clearButton = document.querySelector(".clear-button");
  sendButton.addEventListener("click", function () {
    const message = inputField.value;
    sendMessage(message);
    inputField.value = "";
  });

  clearButton.addEventListener("click", function () {
    chatlog.innerHTML = '<p class="text-center">Welcome to our AI Chatbot. How can I assist you today?</p>';
  });

  function sendMessage(message) {
    const userMessage = document.createElement("p");
    userMessage.innerText = `You: ${message}`;
    chatlog.appendChild(userMessage);

    const loader = document.createElement("div");
    loader.classList.add("spinner-border", "spinner-border-sm", "text-primary", "align-self-end");
    loader.setAttribute("role", "status");
    const botMessage = document.createElement("p");
    botMessage.classList.add("text-end");
    botMessage.appendChild(loader);
    chatlog.appendChild(botMessage);

    fetch("https://www.literallyanything.io/api/integrations/chatgpt", {
      method: "POST",
      headers: {
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        "systemPrompt": "How can I assist you today?",
        "prompts": [{ "role": "user", "content": message }]
      })
    })
      .then(res => res.json())
      .then(data => {
        botMessage.innerText = `Bot: ${data.response}`;
      })
      .catch(err => {
        botMessage.innerText = `Bot: Sorry, I'm unable to process your request at the moment. Please try again later.`;
        console.log(err);
      });
  }
</script>

About

A professional qr code design

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors