File size: 5,963 Bytes
7794643
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>BitNet 1-Bit LLM Query Interface</title>
  <style>
    body {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      margin: 0;
      padding: 0;
      background-color: #f4f4f9;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }

    .container {
      display: flex;
      max-width: 1200px;
      width: 100%;
      background-color: #fff;
      border-radius: 8px;
      box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
      overflow: hidden;
    }

    .left-section {
      flex: 1;
      padding: 20px;
      background-color: white;
      color: black;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      box-sizing: border-box;
    }

    .left-section h2 {
      margin-bottom: 20px;
      font-size: 1.5rem;
    }

    .input-group {
      margin-bottom: 15px;
    }

    .input-group label {
      display: block;
      font-size: 0.9rem;
      margin-bottom: 8px;
    }

    .input-group input,
    .input-group textarea {
      width: 100%;
      padding: 10px;
      border-radius: 4px;
      font-size: 0.95rem;
      box-sizing: border-box;
    }

    input[type="number"],
    textarea {
      width: 100%;
      border: 1px solid #ccc;
      border-radius: 4px;
      box-sizing: border-box;
    }

    input[type="number"]:focus,
    textarea:focus {
      border-color: #238a95;
      outline: none;
      box-shadow: 0 0 5px rgba(35, 138, 149, 0.5);
    }

    input[type="number"]::placeholder,
    textarea::placeholder {
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    }

    .input-group textarea {
      resize: none;
    }

    .button-group {
      margin-top: 20px;
      margin: auto;
    }

    .button-group button {
      padding: 10px 20px;
      background-color: #238a95;
      border: none;
      color: white;
      cursor: pointer;
      border-radius: 4px;
      font-size: 1rem;
      transition: background-color 0.3s, transform 0.2s;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    }

    .button-group button:hover {
      background-color: #1e7a84;
      transform: scale(1.05);
    }

    .right-section {
      flex: 2;
      padding: 20px;
      background-color: #ffffff;
      border-left: 2px solid #dbdbdb;
      box-sizing: border-box;
    }

    .right-section h2 {
      margin-bottom: 20px;
    }

    #response {
      height: 430px;
      border: 1px solid #dbdbdb;
      border-radius: 4px;
      padding: 10px;
      overflow-y: auto;
      font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
      background-color: #f5f4f459;
      font-size: 0.95rem;
    }

    /* Responsive design */
    @media screen and (max-width: 768px) {
      .container {
        flex-direction: column;
      }

      .right-section {
        border-left: none;
        border-top: 2px solid #dbdbdb;
      }
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="left-section">
      <h2>Command Options</h2>
      <div class="input-group">
        <label for="tokens">Number of tokens to predict</label>
        <input type="number" id="tokens" min="0" placeholder="Enter number of tokens">
      </div>
      <div class="input-group">
        <label for="threads">Number of threads to use</label>
        <input type="number" id="threads" min="0" placeholder="Enter number of threads">
      </div>
      <div class="input-group">
        <label for="context-size">Size of the prompt context</label>
        <input type="number" id="context-size" min="0" placeholder="Enter context size">
      </div>
      <div class="input-group">
        <label for="temperature">Temperature, a hyperparameter that controls the randomness of the generated text</label>
        <input type="number" min="0" id="temperature" placeholder="Enter temperature value">
      </div>
      <div class="input-group">
        <label for="prompt">Prompt</label>
        <textarea id="prompt" rows="4" min="0" placeholder="Enter your prompt"></textarea>
      </div>
      <div class="button-group">
        <button onclick="sendQuery()">Send Query</button>
      </div>
    </div>
    <div class="right-section">
      <h2>Response</h2>
      <div id="response"></div>
    </div>
  </div>

  <script type="module">
    import { io } from "https://cdn.socket.io/4.8.0/socket.io.esm.min.js";
    const socket = io();

    window.sendQuery = function() {
      const tokens = document.getElementById('tokens').value;
      const threads = document.getElementById('threads').value;
      const contextSize = document.getElementById('context-size').value;
      const temperature = document.getElementById('temperature').value;
      const prompt = document.getElementById('prompt').value;

      if (!prompt) {
        return alert('There is no prompt to send!');
      }

      let args = '';

      if (tokens && !isNaN(tokens) && tokens > -1) {
        args += ` -n ${tokens}`;
      }

      if (threads && !isNaN(threads) && threads > -1) {
        args += ` -t ${threads}`;
      }

      if (contextSize && !isNaN(contextSize) && contextSize > -1) {
        args += ` -c ${contextSize}`;
      }

      if (temperature && !isNaN(temperature) && temperature > -1) {
        args += ` -temp ${temperature}`;
      }

      // Clear previous response
      document.getElementById('response').innerText = '';

      // Emit query with all parameters
      socket.emit('query', { query: prompt, args });
    }

    socket.on('response', function (word) {
      const responseDiv = document.getElementById('response');
      responseDiv.innerText += word.word + ' ';
      // Scroll to the bottom of the response div
      responseDiv.scrollTop = responseDiv.scrollHeight;
    });
  </script>
</body>

</html>