-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.html
434 lines (429 loc) · 15.6 KB
/
popup.html
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<!-- Komple settings -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Komple settings</title>
<!-- Bootstrap 5 -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<!-- Vue -->
<script src="vue.js" defer></script>
<!-- Inline CSS -->
<style>
#app {
width: 800px;
zoom: 0.73;
}
.form-group {
margin-bottom: 0.8em;
}
label {
/* margin-bottom: 0.5em; */
font-weight: 500;
}
kbd {
font-size: 0.8em;
background-color: #ccc;
}
.text-light-gray {
color: #ccc;
}
</style>
</head>
<body>
<!-- Main div -->
<div
id="app"
class="m-3"
>
<template
v-if="settingsLoaded"
>
<ul class="nav nav-tabs mb-4">
<li class="nav-item"
v-for="tab in [
{ id: 'api', name: 'API' },
{ id: 'hotkeys', name: 'Hotkeys' },
{ id: 'advanced', name: 'Advanced' },
{ id: 'json', name: 'Import/export' },
]"
:key="tab.id"
>
<a
:class="{
'nav-link': true,
active: tab.id === activeTab,
}"
@click="$set(settings, 'activeTab', tab.id)"
href="#"
>
{{ tab.name }}
</a>
</li>
<!-- Buy me a beer link -->
<li class="nav-item">
<a
class="nav-link"
href="https://vzakharov.github.io/buy-me-a-beer/"
target="_blank"
>
Buy me a 🍺
</a>
</li>
</ul>
<!-- Flex container for API settings -->
<div class="container-fluid"
v-show="activeTab === 'api'"
>
<div class="row">
<div class="col-3">
<label
for="api-list"
>
Your APIs
</label>
<div
id="api-list"
class="list-group"
@keydown.down.prevent.exact="api = settings.apis[currentApiIndex() + 1] || settings.apis[0]"
@keydown.up.prevent.exact="api = settings.apis[currentApiIndex() - 1] || settings.apis[settings.apis.length - 1]"
@keydown.ctrl.down.prevent="nudge(+1)"
@keydown.ctrl.up.prevent="nudge(-1)"
tabindex="0"
>
<a class="list-group-item"
href="#"
v-for="api, index in settings.apis"
:key="api.name"
:class="{
'list-group-item list-group-item-action': true,
active: api.name === settings.currentApiName,
}"
@click="vm.api = api"
tabindex="-1"
>
{{ api.name }}
</a>
<!-- Add new -->
<a class="list-group-item list-group-item-action"
href="#"
@click="addApi()"
>
<em>Add new</em>
</a>
</div>
<!-- Muted text: ctrl+up/down to move items -->
<div class="text-light-gray mt-2 small">
<kbd>Ctrl</kbd> + <kbd>▲▼</kbd> to reorder
</div>
</div>
<div class="col-9">
<div class="row">
<div class="col-12">
<!-- API name -->
<div class="form-group">
<label for="api-name">
API name
</label>
<input
type="text"
class="form-control"
id="api-name"
:value="api.name"
@input="changeApiName($event.target.value)"
placeholder="My API"
/>
<small class="form-text text-muted">
Any name you want.
</small>
</div>
<template v-if="api.empty">
<!-- Select a template -->
<div class="form-group">
<select
class="form-select"
id="api-template"
@change="
let template = JSON.parse($event.target.value)
Object.entries(template.settings).forEach(entry =>
$set(api, ...entry)
)
api.empty = false
changeApiName(pickName(`${template.name}`))
console.log(api)
"
>
<option value="" selected>
-- Select a template --
</option>
<option
v-for="template in apiTemplates"
:value="JSON.stringify(template)"
>
{{ template.name }}
</option>
</select>
<!-- Delete -->
<button
class="btn btn-sm mt-2 btn-outline-secondary"
@click="deleteApi({ doNotPrompt: true })"
>
Delete
</button>
</div>
</template>
<template v-if="!api.empty">
<button
v-for="button in [
{ action: deleteApi, caption: 'Delete'},
{ action: cloneApi, caption: 'Clone' },
{ action: () => $set(settings, 'hideAllButBody', !settings.hideAllButBody),
caption: settings.hideAllButBody ? 'Show all settings' : 'Hide all but body',
hide: !allRequiredApiSettingsSet,
},
]"
:class="{
'btn me-1 mb-2 btn-sm btn-outline-secondary': true,
}"
@click="button.action"
v-show="!button.hide"
>
{{ button.caption }}
</button>
<div v-show="!hideAllButBody">
<!-- API endpoint -->
<div class="form-group">
<label for="api-endpoint">
API endpoint
</label>
<input
:type="settings.censor ? 'password' : 'text'"
class="form-control"
id="api-endpoint"
v-model.lazy="api.endpoint"
placeholder="https://..."
/>
</div>
<!-- API authorization header -->
<div class="form-group">
<label for="api-auth">
API authorization header
</label>
<input
:type="settings.censor ? 'password' : 'text'"
class="form-control"
id="api-auth"
v-model.lazy="api.auth"
placeholder="Bearer [your API key]"
/>
</div>
<!-- Whether to hide the above fields -->
<div class="form-group">
<div class="form-check">
<input
type="checkbox"
class="form-check-input switch"
id="api-censor"
v-model="settings.censor"
/>
<label for="api-censor">
Hide API fields
</label>
</div>
</div>
</div>
</template>
</div>
</div>
<div class="row"
v-if="!api.empty"
>
<div class="col-5"
v-show="!hideAllButBody"
>
<!-- API prompt, suffix, array, result keys -->
<div class="form-group"
v-for="key in ['prompt', 'suffix', 'array', 'result']"
>
<label :for="`api-${key}`">
{{ key }} key
</label>
<input
type="text"
class="form-control"
:id="`api-${key}`"
v-model.lazy="api[key+'Key']"
:placeholder="'e.g. ' + {
prompt: 'prompt',
suffix: 'suffix',
array: 'choices',
result: 'text'
}[key]"
/>
<small class="form-text text-muted"
v-if="['suffix', 'array'].includes(key)"
>
Leave empty if {{ key === 'suffix' ? 'the model doesn\'t support text insertion' : 'the API doesn\'t return an array' }}
</small>
</div>
</div>
<div class="col">
<!-- Generation parameters -->
<div>
<!-- Monospace textarea -->
<div class="form-group">
<label for="api-body">
API request body
</label>
<textarea
id="api-body"
class="form-control"
style="font-family: monospace; height: 360px;"
v-model.lazy="stringifiedApiParams"
placeholder="{ max_tokens: 50, temperature: 0.6, stop: '\n' }"
></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Hotkeys section -->
<div
v-show="activeTab === 'hotkeys'"
>
<!-- Table: action (with description), modifier, key -->
<table class="table table-sm">
<thead>
<tr
class="thead-dark"
>
<th scope="col">Action</th>
<th scope="col">Hotkey</th>
</tr>
</thead>
<tbody>
<tr
v-for="hotkey, action in settings.hotkeys"
:key="action"
>
<td v-text="{
autocomplete: 'Autocomplete',
apiPicker: 'Pick API',
}[action]"/>
<td>
<!-- An input that listens to keydown events -->
<input
type="text"
class="form-control"
:value="`${hotkey.modifier}+${hotkey.key === ' ' ? 'Space' : hotkey.key}`"
readonly
@keydown="
// If it's a tab or a shift, don't do anything
if (['Tab', 'Shift'].includes($event.key))
return
// If the key is a modifier, set the modifier and clear the key
if ( ['Control', 'Shift', 'Alt', 'Meta'].includes($event.key) ) {
hotkey.modifier = $event.key
hotkey.key = ''
} else {
hotkey.key = $event.key
}
// Prevent the default action
$event.preventDefault()
"
@keyup.prevent="
// If no key is set, clear the modifier too
if ( !hotkey.key ) {
hotkey.modifier = ''
}
"
@keypress.prevent
/>
</td>
</tr>
</tbody>
</table>
<!-- Switch to activate on a hanging character -->
<div class="form-check form-switch">
<input
type="checkbox"
class="form-check-input"
id="activate-on-hanging-char"
v-model="settings.activateOnHangingChar"
/>
<label for="activate-on-hanging-char">
Activate on a hanging character
</label>
<p class="form-text text-muted small">
If checked, the autocomplete will be activated on a hanging character like space, comma, etc. WARNING: This can cause your tokens to deplete quickly.
</p>
</div>
</div>
<!-- Advanced section -->
<div
v-show="activeTab === 'advanced'"
>
<!-- Switch to remove new lines from output -->
<div class="form-check form-switch">
<input
type="checkbox"
class="form-check-input"
id="remove-newlines"
v-model="settings.removeNewlines"
/>
<label for="remove-newlines">
Remove newlines from output
</label>
<p class="form-text text-muted small">
If checked, newlines will be removed from the output. This can be useful for websites that handle newlines differently (e.g. Twitter)
</p>
</div>
</div>
<!-- JSON section -->
<div
v-show="activeTab === 'json'"
>
<!-- Warning that changing the JSON might break the app -->
<p class="form-text text-danger">
<strong>WARNING:</strong> This is an advanced feature. Changing the JSON might break the settings, in which case they will be reset to their default values.
</p>
<!-- A textarea with all the settings as JSON -->
<textarea
class="form-control"
style="font-family: monospace"
rows="25"
id="json"
:value="JSON.stringify(settings, null, 2)"
@change="
try {
settings = JSON.parse($event.target.value)
} catch (e) {
console.error(e)
$bvToast.toast('Invalid JSON', {
title: 'Error',
variant: 'danger',
})
}
"
></textarea>
<!-- Download & reset buttons -->
<button
class="btn btn-outline-secondary me-2 mt-2"
v-for="action, caption in {
Download: downloadSettings,
Reset: resetSettings,
}"
:key="caption"
@click="action"
v-text="caption"
:variant="action === 'Download' ? 'outline-secondary' : 'outline-danger'"
/>
</div>
</template>
</div>
<script src="settings.js" defer></script>
<script src="popup.js" defer></script>
</body>
</html>