add a toggle button that toggles the starting message "</final_answer>". call the toggle  "Super smart mode"

<!DOCTYPE html>
<html>
<head>
  <title>G1</title>
  <style>
    body {
      font-family: sans-serif;
    }

    #chat-container {
      display: flex;
      flex-direction: column;
      width: 500px;
      margin: 0 auto;
      border: 1px solid #ccc;
      padding: 10px;
      height: 400px;
      overflow-y: auto;
    }

    .message {
      padding: 10px;
      margin-bottom: 10px;
      border-radius: 5px;
    }

    .user-message {
      background-color: #eee;
      text-align: right;
      white-space: pre-wrap; 
    }

    .bot-message {
      background-color: #f5f5f5;
      white-space: pre-wrap; 
    }

    #input-area {
      display: flex;
      margin-top: 10px;
    }

    #input-box {
      flex-grow: 1;
      padding: 5px;
      border: 1px solid #ccc;
      border-radius: 5px;
    }

    #send-button {
      padding: 5px 10px;
      background-color: #007bff;
      color: #fff;
      border: none;
      border-radius: 5px;
      cursor: pointer;
    }

    /* Styles for typing indicator */
    #typing-indicator {
      display: none; /* Initially hidden */
      margin-top: 5px;
      font-style: italic;
      color: #999;
    }
  </style>
</head>

<body>
  <div id="chat-container"></div>
  <div id="input-area">
    <textarea id="input-box" placeholder="Enter your message..." rows="3"></textarea>
    <button id="send-button">Send</button>
  </div>
  <div id="typing-indicator">Gemini is typing...</div> 

  <script>
    // List of API keys. Replace these with your actual API keys.
    const API_KEYS = [
            'AIzaSyBdc_A8VxExwO6-0LY1--r2-Ym73lMg-h4',
            'AIzaSyBydeCpaNOIPSk794CpTGnfKrxbjCgJLu4',
            'AIzaSyCQ7tBHtctxlNs61Zm2Y__7KYeDLfz5dms',
	    'AIzaSyAip_DFfKNC35MFIorEoNK4y6czP9P65-c'
    ];

    const chatContainer = document.getElementById('chat-container');
    const inputBox = document.getElementById('input-box');
    const sendButton = document.getElementById('send-button');
    const typingIndicator = document.getElementById('typing-indicator');
    let messageHistory = "</final_answer>"

    sendButton.addEventListener('click', sendMessage);
    inputBox.addEventListener('keydown', (event) => {
      if (event.key === 'Enter' && !event.shiftKey) {
        event.preventDefault();
        sendMessage();
      }
    });

    /**
     * Attempts to fetch a response using the provided API key.
     * @param {string} apiKey - The API key to use for the request.
     * @param {string} prompt - The user message to send.
     * @returns {Promise<Object>} - The response data from the API.
     */
    async function fetchWithKey(apiKey, prompt) {
      const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=${apiKey}`, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          contents: [
            {
              role: "user",
              parts: [
                { text: prompt } // Include history in the prompt
              ]
            }
          ],
          "generationConfig": {
            "temperature": 0.1,
            "topK": 64,
            "topP": 0.95,
            "maxOutputTokens": 8192,
            "responseMimeType": "text/plain"
          }
        })
      });

      if (!response.ok) {
        // Extract error message from response
        const errorData = await response.json();
        throw new Error(errorData.error?.message || 'Unknown API error');
      }

      const data = await response.json();
      return data;
    }

    /**
     * Sends the user's message and handles the bot's response using multiple API keys.
     */
    async function sendMessage() {
      const userMessageText = inputBox.value.trim();
      if (userMessageText === '') return;

      // Display user's message
      const userMessage = document.createElement('div');
      userMessage.classList.add('message', 'user-message');
      userMessage.textContent = userMessageText;
      chatContainer.appendChild(userMessage);
      chatContainer.scrollTop = chatContainer.scrollHeight;      
      
      inputBox.value = '';
      typingIndicator.style.display = 'block';

      let botMessageText = '';
      let success = false;


      for (const apiKey of API_KEYS) {  // Simplified loop
        try {
          const data = await fetchWithKey(apiKey, messageHistory + `User: ${userMessageText}\n`); // Add user message here

          const fullResponse = data?.candidates[0]?.content?.parts[0]?.text; // Optional chaining

          if (!fullResponse) {
            throw new Error("Invalid response format: Missing content."); // Better error handling
          }


          const finalAnswerStartIndex = fullResponse.lastIndexOf("<final_answer>");
          const finalAnswerEndIndex = fullResponse.lastIndexOf("</final_answer>");

          if (finalAnswerStartIndex !== -1 && finalAnswerEndIndex !== -1) {
            botMessageText = fullResponse.substring(finalAnswerStartIndex + 14, finalAnswerEndIndex).trim();
          } else {
            botMessageText = "Error: Could not extract final answer. Invalid response format.";
            console.error("Final answer tags not found in response:", fullResponse);
          }


          messageHistory += `Gemini: ${botMessageText}\n`; // Update history *after* successful response

          success = true;
          break; 
        } catch (error) {
          console.error(`Error with API key:`, error.message);
        }
      }


      const botMessage = document.createElement('div'); // Create element *outside* the loop
      botMessage.classList.add('message', 'bot-message');
      botMessage.textContent = success ? botMessageText : "I'm sorry, I'm currently unable to process your request. Please try again later."; // Display error or bot message
      chatContainer.appendChild(botMessage);
      chatContainer.scrollTop = chatContainer.scrollHeight;

      typingIndicator.style.display = 'none';
    }
  </script>
</body>
</html>