File size: 2,803 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Fast Chat Solution v2</title>
  <style>
    body { font-family: Arial, sans-serif; padding: 24px; }
    textarea { width: 420px; min-height: 38px; padding: 8px; resize: none; overflow: hidden; }
    output { display: block; margin-top: 12px; min-height: 36px; white-space: pre-wrap; }
  </style>
  <script src="config.js"></script>
</head>
<body>
  <header><h1>Fast Chat</h1><p>Press Enter to send and Shift+Enter for a new line.</p></header>
  <main>
    <label for="chat" style="display:block;margin-bottom:6px">Your Question</label>
    <textarea id="chat" data-testid="chat-input" placeholder="Ask"></textarea>
    <button data-testid="send-button">Send</button>
    <h1 data-testid="title"></h1>
    <output data-testid="response"></output>
    <p data-testid="status">idle</p>
  </main>
  <script>
    let mockMode = 'normal';
    let requestVersion = 0;
    window.__setMockMode = mode => { mockMode = mode; };
    const input = document.querySelector('[data-testid="chat-input"]');
    function grow() { input.style.height = 'auto'; input.style.height = Math.max(38, input.scrollHeight) + 'px'; }
    input.addEventListener('input', grow);
    function send() {
      const prompt = input.value.trim();
      if (!prompt) return;
      const version = ++requestVersion;
      const status = document.querySelector('[data-testid="status"]');
      const response = document.querySelector('[data-testid="response"]');
      const title = document.querySelector('[data-testid="title"]');
      status.textContent = 'generating';
      title.textContent = '';
      response.textContent = '';
      setTimeout(() => {
        if (version !== requestVersion) return;
        if (mockMode === 'timeout') {
          status.textContent = 'failed: request timeout';
          response.textContent = 'Model response: the request timed out. Please try again later.';
          return;
        }
        title.textContent = prompt.length > 24 ? prompt.slice(0, 24) + '…' : prompt;
        status.textContent = 'streaming';
        response.textContent = `For "${prompt}", first clarify the goal and constraints.`;
        setTimeout(() => {
          if (version !== requestVersion) return;
          response.textContent += ` Then list actionable steps and adapt them to the actual needs of "${prompt}".`;
          status.textContent = 'complete';
        }, 70);
      }, 60);
    }
    document.querySelector('[data-testid="send-button"]').addEventListener('click', send);
    input.addEventListener('keydown', event => {
      if (event.key === 'Enter' && event.shiftKey) {
        return;
      }
      if (event.key === 'Enter') {
        event.preventDefault();
        send();
      }
    });
  </script>
</body>
</html>