Settings



Settings are saved as cookies on your local machine. Nothing is sent to any server other than the API endpoint above.

Code

const chat = new quikchat('#chat', handleAIRequest);

async function handleAIRequest(chatInstance, userInput) {
  chatInstance.messageAddNew(userInput, 'user', 'right');

  const response = await fetch('https://api.openai.com/v1/chat/completions', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer ' + apiKey
    },
    body: JSON.stringify({
      model: 'gpt-4o-mini',
      messages: [
        { role: 'system', content: systemPrompt },
        ...chatInstance.historyGet()  // full conversation context
      ],
      stream: true
    })
  });

  const reader = response.body.getReader();
  let start = true, id;

  // Read SSE stream token-by-token
  while (true) {
    const { value, done } = await reader.read();
    if (done) break;
    // parse chunks, extract content, append to message
    if (start) {
      id = chatInstance.messageAddNew(content, 'bot', 'left');
      start = false;
    } else {
      chatInstance.messageAppendContent(id, content);
    }
  }
}