-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
982 lines (849 loc) · 28.8 KB
/
index.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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat-GPT Playground</title>
<script>
const apiKeys = [
];
</script>
<style>
@import url('https://fonts.googleapis.com/css2family=Fuzzy+Bubbles&display=swap');
* {
box-sizing: border-box;
--color-Ghost-White: #f7f7f8;
--color-Lavender: #ececf1;
--color-Quartz: #d9d9e3;
--color-Lavender-grey: #c5c5d2;
--color-Free-Speech-Aquamarine: #10a37f;
--color-Deep-Sea: #1a7f64;
--color-Black-Russian: #202123;
}
html {
height: 100%;
margin: 0;
padding: 0;
outline: 0;
border: 0;
}
body {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
outline: none;
border: none;
}
div.header {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
align-items: center;
margin: 0;
padding: 16px;
border-style: solid none;
border-width: 2px;
border-color: var(--color-Lavender);
flex: 0 0 0px;
}
div.header>p {
display: block;
margin: 0 16px;
padding: 0;
outline: none;
font-size: 16px;
font-weight: bold;
color: var(--color-Black-Russian);
flex: 1 1 1px;
}
div.header>svg {
flex: 0 0 24px;
}
div.main {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
height: 100%;
width: 100%;
margin: 0;
padding: 16px;
overflow: hidden;
flex: 1 1 0px;
}
.chat-instruction-panel{
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
height: 100%;
margin: 0;
padding: 0;
border: solid 1px var(--color-Lavender-grey);
border-radius: 8px;
overflow: hidden;
flex: 1 1 520px;
}
.chat-panel {
display: flex;
flex-direction: column;
flex-wrap: nowrap;
justify-content: flex-start;
align-content: stretch;
height: 100%;
margin: 0;
padding: 0 16px;
flex: 1 1 1200px;
}
.parameter-panel {
height: 100%;
margin: 0;
padding: 0;
border: none;
flex: 0 0 200px;
overflow: hidden;
transition: 0.3s;
}
label.chat-instruction-title {
display: block;
font-variant: small-caps;
padding: 16px;
font-size: 16px;
font-family: 'Fuzzy Bubbles', cursive;
font-weight: bold;
}
textarea.chat-instruction-input, textarea.chat-instruction-input:focus {
width: 100%;
height: 100%;
resize: none;
border: none;
outline: none;
margin: 0;
padding: 0 16px;
font-size: 16px;
font-family: 'Fuzzy Bubbles', cursive;
letter-spacing: 1px;
overflow:auto;
}
div.chat-message-panel {
margin-bottom: 12px;
flex: 1 1 0px;
overflow: auto;
}
div.message-grid {
display: flex;
flex-direction: row;
align-items: center;
border-style: none none solid none;
border-width: 1px;
border-color: var(--color-Lavender-grey);
}
div[class$=message-grid] {
padding: 16px;
}
div[class$=message-grid]:hover {
background: var(--color-Ghost-White);
}
div.add-message-grid {
display: flex;
flex-direction: row;
align-items: center;
}
div.add-message-grid>span {
margin-left: 20px;
font-size: 14px;
font-weight: 700;
line-height: 20px;
vertical-align: middle;
}
div.message-role-wrapper {
display: flex;
margin: 0;
padding: 0;
width: 100px;
height: 48px;
align-items: center;
align-content: center;
align-self: flex-start;
flex: 0 0 95px;
}
div.message-input-wrapper {
display: flex;
margin: 0 16px;
padding: 12px 12px;
border: none;
outline: none;
min-height: 48px;
align-self: flex-start;
flex: 1 1 0px;
}
div.message-deletion-wrapper {
display: flex;
align-content: center;
align-items: center;
align-self: flex-start;
margin-top: 14px;
opacity: 0.4;
flex: 0 0 0px;
}
div.message-deletion-wrapper:hover {
opacity: 1;
}
span.message-role {
padding: 6px 12px;
font-variant: small-caps;
font-weight: 700;
}
span.message-role:hover {
background: var(--color-Quartz);
}
textarea.message-input, textarea.message-input:focus{
width: 100%;
height: 24px;
align-self: center;
background: transparent;
resize: none;
border: none;
outline-offset: 10px;
outline: solid 2px transparent;
margin: 0;
padding: 0;
font-size: 17px;
line-height: 24px;
font-family: 'Fuzzy Bubbles', cursive;
box-sizing: border-box;
overflow: hidden;
}
textarea.message-input:focus {
background: white;
border-radius: 0.5px;
outline:solid 2px var(--color-Free-Speech-Aquamarine);
box-shadow: 0 0 0 10px white;
}
div.chat-submit-panel {
position: relative;
text-align: left;
flex: 0 0 0px;
}
button {
display: inline-flex;
justify-content: center;
padding: 6px 12px;
margin: 0;
border: none;
border-radius: 3px;
color: white;
font-family: 'Fuzzy Bubbles', cursive;
font-size: 14px;
font-weight: 400;
line-height: 20px;
cursor: pointer;
}
button:hover {
color: white;
}
button.submit-chat-button {
background: var(--color-Free-Speech-Aquamarine);
color: white;
}
button.submit-chat-button:hover {
background: var(--color-Deep-Sea);
color: white;
}
div.sub-parameter-panel {
display: block;
transition: 0.3s;
}
div.parameter-panel-grid {
margin-bottom: 24px;
}
div.parameter-info-wrapper {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: center;
min-height: 27px;
width: 100%;
}
label.parameter-name {
white-space: nowrap;
flex: 1 1 0px;
font-size: 14px;
}
input.parameter-value {
flex: 0 0 0px;
width: 46px;
padding: 4px 5px 3px;
text-align: right;
border: solid 2px transparent;
outline: none;
border-radius: 5px;
}
input.parameter-value:hover, div.parameter-panel-grid:hover input.parameter-value {
border: solid 2px var(--color-Lavender);
outline: none;
border-radius: 5px;
}
input.parameter-value:focus, div.parameter-panel-grid:hover input.parameter-value:focus{
border: solid 2px var(--color-Free-Speech-Aquamarine);
outline: none;
border-radius: 5px;
}
input[type=range] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: linear-gradient(to right, var(--color-Lavender-grey) 0%, var(--color-Lavender-grey) 50%, var(--color-Lavender) 50%, var(--color-Lavender) 100%);
width: 100%;
height: 4px;
margin: 0;
padding: 0;
outline: none;
cursor: pointer;
border-radius: 3px;
border: none;
transition: background 450ms ease-in;
}
input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
border: 2px solid var(--color-Lavender-grey);
height: 15px;
width: 15px;
border-radius: 50%;
background: white;
cursor: pointer;
}
select {
width: 100%;
padding: 8px;
margin-top: 8px;
border: 1px solid var(--color-Lavender-grey);
border-radius: 4px;
background-color: transparent;
}
select:active, select:focus {
outline: none;
box-shadow: none;
}
div.parameter-type-switch-wrapper {
display: flex;
justify-content: center;
margin: 8px 0 24px 0;
}
label.parameter-type-switch{
display: inline-block;
position: relative;
margin: 0px;
}
label.parameter-type-switch > label.parameter-type-switch-inner{
display: block;
position: relative;
margin: 0px;
width: 140px;
height: 30px;
background: #E0E0E0;
border-radius: 26px;
overflow: hidden;
font-size: 13px;
color: #424242;
font-weight: 500;
transition: all 0.2s ease;
/*box-shadow: 0px 0px 8px 0px rgba(17, 17, 17, 0.34) inset;*/
}
label.parameter-type-switch > label.parameter-type-switch-inner:before{
content: attr(data-on);
position: absolute;
font-size: 12px;
font-weight: 500;
top: 7px;
right: 10px;
}
label.parameter-type-switch > label.parameter-type-switch-inner:after{
content: attr(data-off);
position: absolute;
padding: 5px 0px;
width: 70px;
height: 16px;
background: #fff;
border-radius: 26px;
box-shadow: 0px 0px 6px -2px #111;
left: 2px;
top: 2px;
text-align: center;
transition: all 0.3s ease;
}
label.parameter-type-switch input[type="checkbox"] {
position: absolute;
cursor: pointer;
margin: 0px;
width: 50px;
height: 25px;
font-size: 13px;
color: #424242;
font-weight: 500;
opacity: 0;
top: 0;
z-index: 1;
}
label.parameter-type-switch input[type="checkbox"]:checked + label.parameter-type-switch-inner{
/*background: #151515;*/
/*color: #fff;*/
/*background: var(--color-Deep-Sea);*/
}
label.parameter-type-switch input[type="checkbox"]:checked + label.parameter-type-switch-inner:after{
content: attr(data-on);
left: 68px;
/*background: #3c3c3c;*/
/*background: var(--color-Free-Speech-Aquamarine);*/
}
label.parameter-type-switch input[type="checkbox"]:checked + label.parameter-type-switch-inner:before{
content: attr(data-off);
right: auto;
left: 20px;
}
.noselect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
</style>
</head>
<body>
<div class="header">
<svg data-name="OpenAI Logo" width="24px" height="24px" viewBox="140 140 520 520">
<defs>
<linearGradient id="linear" x1="100%" y1="22%" x2="0%" y2="78%">
<stop offset="0%" stop-color="rgb(131,211,231)"></stop>
<stop offset="2%" stop-color="rgb(127,203,229)"></stop>
<stop offset="25%" stop-color="rgb(86,115,217)"></stop>
<stop offset="49%" stop-color="rgb(105,80,190)"></stop>
<stop offset="98%" stop-color="rgb(197,59,119)"></stop>
<stop offset="100%" stop-color="rgb(197,59,119)"></stop>
</linearGradient>
</defs>
<path id="logo" d="m617.24 354a126.36 126.36 0 0 0 -10.86-103.79 127.8 127.8 0 0 0 -137.65-61.32 126.36 126.36 0 0 0 -95.31-42.49 127.81 127.81 0 0 0 -121.92 88.49 126.4 126.4 0 0 0 -84.5 61.3 127.82 127.82 0 0 0 15.72 149.86 126.36 126.36 0 0 0 10.86 103.79 127.81 127.81 0 0 0 137.65 61.32 126.36 126.36 0 0 0 95.31 42.49 127.81 127.81 0 0 0 121.96-88.54 126.4 126.4 0 0 0 84.5-61.3 127.82 127.82 0 0 0 -15.76-149.81zm-190.66 266.49a94.79 94.79 0 0 1 -60.85-22c.77-.42 2.12-1.16 3-1.7l101-58.34a16.42 16.42 0 0 0 8.3-14.37v-142.39l42.69 24.65a1.52 1.52 0 0 1 .83 1.17v117.92a95.18 95.18 0 0 1 -94.97 95.06zm-204.24-87.23a94.74 94.74 0 0 1 -11.34-63.7c.75.45 2.06 1.25 3 1.79l101 58.34a16.44 16.44 0 0 0 16.59 0l123.31-71.2v49.3a1.53 1.53 0 0 1 -.61 1.31l-102.1 58.95a95.16 95.16 0 0 1 -129.85-34.79zm-26.57-220.49a94.71 94.71 0 0 1 49.48-41.68c0 .87-.05 2.41-.05 3.48v116.68a16.41 16.41 0 0 0 8.29 14.36l123.31 71.19-42.69 24.65a1.53 1.53 0 0 1 -1.44.13l-102.11-59a95.16 95.16 0 0 1 -34.79-129.81zm350.74 81.62-123.31-71.2 42.69-24.64a1.53 1.53 0 0 1 1.44-.13l102.11 58.95a95.08 95.08 0 0 1 -14.69 171.55c0-.88 0-2.42 0-3.49v-116.68a16.4 16.4 0 0 0 -8.24-14.36zm42.49-63.95c-.75-.46-2.06-1.25-3-1.79l-101-58.34a16.46 16.46 0 0 0 -16.59 0l-123.31 71.2v-49.3a1.53 1.53 0 0 1 .61-1.31l102.1-58.9a95.07 95.07 0 0 1 141.19 98.44zm-267.11 87.87-42.7-24.65a1.52 1.52 0 0 1 -.83-1.17v-117.92a95.07 95.07 0 0 1 155.9-73c-.77.42-2.11 1.16-3 1.7l-101 58.34a16.41 16.41 0 0 0 -8.3 14.36zm23.19-50 54.92-31.72 54.92 31.7v63.42l-54.92 31.7-54.92-31.7z" fill="#202123"></path>
</svg>
<p class="noselect">Budget-GPT 💀</p>
<svg data-name="Options" fill="#000000" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16px" height="16px" viewBox="0 0 124 124" xml:space="preserve">
<g>
<path d="M112,6H12C5.4,6,0,11.4,0,18s5.4,12,12,12h100c6.6,0,12-5.4,12-12S118.6,6,112,6z"/>
<path d="M112,50H12C5.4,50,0,55.4,0,62c0,6.6,5.4,12,12,12h100c6.6,0,12-5.4,12-12C124,55.4,118.6,50,112,50z"/>
<path d="M112,94H12c-6.6,0-12,5.4-12,12s5.4,12,12,12h100c6.6,0,12-5.4,12-12S118.6,94,112,94z"/>
</g>
</svg>
</div>
<div class="main">
<div class="chat-instruction-panel">
<label class="chat-instruction-title noselect" for="chat-instruction-input">System</label>
<textarea class="chat-instruction-input" id="chat-instruction-input" name="chat-instruction-input" placeholder="You are a helpful assistant."></textarea>
</div>
<div class="chat-panel">
<div class="chat-message-panel">
<div class="chat-input-panel">
<div class="message-grid">
<div class="message-role-wrapper">
<span class="message-role noselect">user</span>
</div>
<div class="message-input-wrapper">
<textarea class="message-input" rows="1" tabindex="1" placeholder="Enter a message here." style="height: 48px;"></textarea>
</div>
<div class="message-deletion-wrapper">
<svg data-name="Delete Message Icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="none" width="20" height="20">
<path d="M10 16.6667C13.6819 16.6667 16.6667 13.6819 16.6667 10C16.6667 6.31811 13.6819 3.33334 10 3.33334C6.31814 3.33334 3.33337 6.31811 3.33337 10C3.33337 13.6819 6.31814 16.6667 10 16.6667Z" stroke="#6E6E80" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M7.33337 10H12.6667" stroke="#6E6E80" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
</div>
</div>
</div>
<div class="add-message-grid" id="add-message-grid">
<svg data-name="Add Message Icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="none" class="icon" width="20px" height="20px">
<path d="M10 16.6667C13.6819 16.6667 16.6667 13.6819 16.6667 9.99999C16.6667 6.3181 13.6819 3.33333 10 3.33333C6.31814 3.33333 3.33337 6.3181 3.33337 9.99999C3.33337 13.6819 6.31814 16.6667 10 16.6667Z" stroke="#353740" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M10 7.33333V12.6667" stroke="#353740" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
<path d="M7.33337 10H12.6667" stroke="#353740" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path>
</svg>
<span class="noselect">Add message</span>
</div>
</div>
<div class="chat-submit-panel" style="position: relative;">
<button class="submit-chat-button noselect" id="submit-chat-button">Submit</button>
</div>
</div>
<div class="parameter-panel noselect">
<div class="parameter-type-switch-wrapper">
<label class="parameter-type-switch">
<input type="checkbox" name="parameter-type" id="parameter-type" value="0">
<label for="parameter-type" data-off="Basic" data-on="Finetune" class="parameter-type-switch-inner"></label>
</label>
</div>
<div class="sub-parameter-panel" id="dropdown-parameter-panel">
<div class="parameter-panel-grid">
<div class="parameter-info-wrapper">
<label class="parameter-name" for="apikey">API KEY</label>
</div>
<div class="parameter-menu-wrapper">
<select name="apikey" id="apikey">
</select>
</div>
</div>
<div class="parameter-panel-grid">
<div class="parameter-info-wrapper">
<label class="parameter-name" for="model">Model</label>
</div>
<div class="parameter-menu-wrapper">
<select name="model" id="model">
<option value="gpt-3.5-turbo" selected>gpt-3.5-turbo</option>
<option value="gpt-3.5-turbo-0301">gpt-3.5-turbo-0301</option>
<option value="gpt-4">gpt-4</option>
<option value="gpt-4-0314">gpt-4-0314</option>
</select>
</div>
</div>
<div class="parameter-panel-grid">
<div class="parameter-info-wrapper">
<label class="parameter-name" for="mode">Mode</label>
</div>
<div class="parameter-menu-wrapper">
<select name="mode" id="mode">
<option value="true" selected>Stream</option>
<option value="false">Non-stream</option>
</select>
</div>
</div>
</div>
<div class="sub-parameter-panel" id="slider-parameter-panel">
<div class="parameter-panel-grid">
<div class="parameter-info-wrapper">
<label class="parameter-name" for="max_tokens">Maximum Length</label>
<input class="parameter-value" type="text" value="256" >
</div>
<div class="parameter-slider-wrapper">
<input class="parameter-slider" type="range" id="max_tokens" min="1" max="2048" step="1" value="1024">
</div>
</div>
<div class="parameter-panel-grid">
<div class="parameter-info-wrapper">
<label class="parameter-name" for="temperature">Temperature</label>
<input class="parameter-value" type="text" value="0.7" >
</div>
<div class="parameter-slider-wrapper">
<input class="parameter-slider" type="range" id="temperature" min="0" max="1" step="0.01" value="0.7">
</div>
</div>
<div class="parameter-panel-grid">
<div class="parameter-info-wrapper">
<label class="parameter-name" for="top_p">Top P</label>
<input class="parameter-value" type="text" value="1" >
</div>
<div class="parameter-slider-wrapper">
<input class="parameter-slider" type="range" id="top_p" min="0" max="1" step="0.01" value="1">
</div>
</div>
<div class="parameter-panel-grid">
<div class="parameter-info-wrapper">
<label class="parameter-name" for="frequency_penalty">Frequency Penalty</label>
<input class="parameter-value" type="text" value="0" >
</div>
<div class="parameter-slider-wrapper">
<input class="parameter-slider" type="range" id="frequency_penalty" min="0" max="2" step="0.01" value="0">
</div>
</div>
<div class="parameter-panel-grid">
<div class="parameter-info-wrapper">
<label class="parameter-name" for="presence_penalty">Presence Penalty</label>
<input class="parameter-value" type="text" value="0" >
</div>
<div class="parameter-slider-wrapper">
<input class="parameter-slider" type="range" id="presence_penalty" min="0" max="2" step="0.01" value="0">
</div>
</div>
</div>
</div>
</div>
<script>
// load the apikeys to drop-down menu
let dropDownMenu = document.getElementById("apikey");
for (let i = 0; i < apiKeys.length; i++) {
if (i == 0) {
dropDownMenu.innerHTML += `<option value="${apiKeys[i].key}" selected>${apiKeys[i].label}</option>`;
}
else {
dropDownMenu.innerHTML += `<option value="${apiKeys[i].key}">${apiKeys[i].label}</option>`;
}
}
// containers of message grid
let chatMessagePanel = document.getElementsByClassName("chat-message-panel")[0];
let chatInputPanel = document.getElementsByClassName("chat-input-panel")[0];
// generate template message grid
let messageGrid = document.getElementsByClassName("message-grid")[0];
let templateMessageGrid = messageGrid.cloneNode(true);
messageGrid.remove();
// add message grid
function addMessage(role, message) {
// get a copy from template
let messageGridCopy = templateMessageGrid.cloneNode(true);
// get inner elements of message grid
let messageRole = messageGridCopy.querySelector("span.message-role");
let messageInput = messageGridCopy.querySelector("textarea.message-input");
let messageDeletion = messageGridCopy.querySelector("div.message-deletion-wrapper");
// set initial values
messageRole.textContent = role;
messageInput.textContent = message;
// change the role when click on it
messageRole.onclick = function() {
this.textContent = (this.textContent == "user")? "assistant":"user";
};
// expand the textarea when content wrap
messageInput.oninput = function() {
this.style.height = "0";
this.style.height = this.scrollHeight + "px";
};
// remove the message grid when delete button is pressed
messageDeletion.onclick = function() {
this.parentElement.remove();
};
// append the new node to tree
chatInputPanel.appendChild(messageGridCopy);
// set the initial size of text area
messageInput.oninput();
// set the panel scroll to bottom and show latest message
chatMessagePanel.scrollTop = chatMessagePanel.scrollHeight;
// return the meesage input textarea for further configuration
return messageInput;
}
// update height of all textarea in the message grid
function updateAllMessageGrid() {
let currentHeight = chatMessagePanel.scrollTop;
let messageGrids = document.getElementsByClassName("message-grid");
for (let i = 0; i < messageGrids.length; i++) {
let messageInput = messageGrids[i].querySelector("textarea.message-input");
messageInput.style.height = "0";
messageInput.style.height = messageInput.scrollHeight + "px";
}
// update the scroll position of the panel
chatMessagePanel.scrollTop = currentHeight;
}
// display a loading animation when waiting response
function updateLoadingStatus(textareaObj, timeInterval=100, base=0) {
let frames = ["◜","◠","◝","◞","◡", "◟"];
let time = Math.floor(new Date().getTime() / timeInterval);
if (base == 0) {
base = time;
}
let frameNum = (time - base) % frames.length;
textareaObj.textContent = frames[frameNum] + " Loading" + ".".repeat(frameNum);
return base;
}
// generate initial message grid
addMessage("user", "");
// add-message-grid button
let addMessageGrid = document.getElementById("add-message-grid");
addMessageGrid.addEventListener("click", function(){
addMessage("user", "");
});
// submit button
let submitChatButton = document.getElementById("submit-chat-button");
submitChatButton.addEventListener("click", function() {
sendMessageToGPT();
});
// sliders
let temperature = document.getElementById("temperature");
let max_tokens = document.getElementById("max_tokens");
let top_p = document.getElementById("top_p");
let frequency_penalty = document.getElementById("frequency_penalty");
let presence_penalty = document.getElementById("presence_penalty");
// initialize parameter sliders
let parameterPanel = document.querySelector("div.parameter-panel");
let parameterPanelGrids = document.getElementsByClassName("parameter-panel-grid");
// set up the parameter sliders
for (let i = 0; i < parameterPanelGrids.length; i++) {
// get the elements
let parameterValue = parameterPanelGrids[i].querySelector("input.parameter-value");
let parameterSlider = parameterPanelGrids[i].querySelector("input.parameter-slider");
// only set up grids with slider
if (parameterValue == null || parameterSlider == null){
continue;
}
// associate parameterSlider with parameterValue
parameterSlider.oninput = function() {
parameterValue.value = this.value;
let value = (this.value-this.min)/(this.max-this.min)*100;
this.style.background = 'linear-gradient(to right, var(--color-Lavender-grey) 0%, var(--color-Lavender-grey) ' + value + '%, var(--color-Lavender) ' + value + '%, var(--color-Lavender) 100%)';
}
// associate parameterValue with parameterSlider
parameterValue.onchange = function() {
parameterSlider.value = this.value;
parameterSlider.oninput();
}
// initialize the slider
parameterSlider.oninput();
}
// allow hide option bar by click the optionsButton
let optionsButton = document.querySelector('svg[data-name="Options"]');
optionsButton.addEventListener("click", function() {
if (parameterPanel.style.flex == "0 0 0px"){
parameterPanel.style.flex = "0 0 200px";
parameterPanel.style.opacity = "100%";
}
else {
parameterPanel.style.flex = "0 0 0px";
parameterPanel.style.opacity = "0";
}
setTimeout(function() {
updateAllMessageGrid();
}, 300);
});
// initialize the sub parameter panel
let dropdownParameterPanel = document.getElementById("dropdown-parameter-panel");
let sliderParameterPanel = document.getElementById("slider-parameter-panel");
dropdownParameterPanel.style.display = "block";
sliderParameterPanel.style.display = "none";
// change the sub parameter panel displayed when switch clicked
let parameterType = document.getElementById("parameter-type");
parameterType.addEventListener("change", (event) => {
// display dropdown parameters
if (! parameterType.checked) {
sliderParameterPanel.style.opacity = "0%";
setTimeout(function() {
sliderParameterPanel.style.display = "none";
dropdownParameterPanel.style.display = "block";
dropdownParameterPanel.style.opacity = "100%";
}, 300);
}
// display slider parameters
else {
dropdownParameterPanel.style.opacity = "0%";
setTimeout(function() {
dropdownParameterPanel.style.display = "none";
sliderParameterPanel.style.display = "block";
sliderParameterPanel.style.opacity = "100%";
}, 300);
}
});
// request from open-ai
async function sendMessageToGPT() {
// disable the submit button
submitChatButton.disabled = true;
submitChatButton.style.opacity = 0.4;
// buffer of message to be sent
let messages = [];
// get the system message
messages.push({
role:"system",
content: document.getElementById("chat-instruction-input").value
});
// get the chat message
messageGrids = document.getElementsByClassName("message-grid");
for (let i = 0; i < messageGrids.length; i++) {
messages.push({
role: messageGrids[i].querySelector("span.message-role").textContent,
content: messageGrids[i].querySelector("textarea.message-input").value
});
}
// url of open-ai api
const url = 'https://openai-api-proxy.uk/v1/chat/completions';
// request to open-ai
let request = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${document.getElementById("apikey").value}`,
},
body: JSON.stringify({
model: document.getElementById("model").value,
temperature: parseFloat(temperature.value),
presence_penalty: parseFloat(presence_penalty.value),
frequency_penalty: parseFloat(frequency_penalty.value),
max_tokens: parseInt(max_tokens.value),
top_p: parseFloat(top_p.value),
stream: (document.getElementById("mode").value == "true")? true: false,
messages: messages
})
};
// create an message grid for receiving response
let messageInput = addMessage("assistant", "loading...");
// update teh loading text periodically
let timeInterval = 100;
let base = updateLoadingStatus(messageInput, timeInterval, 0);
let t = setInterval(()=>{updateLoadingStatus(messageInput, timeInterval, base)}, timeInterval);
// wait for response
const response = await fetch(url, request);
// stop updating the loading text
clearInterval(t);
// handle the response accroding to status code
if (response.status == 200) {
// buffer for response text
let buffer = "";
// non-stream mode
if (JSON.parse(request.body).stream == false) {
// get the json object of response
let data = await response.json();
// get the text message from json object
if (data.hasOwnProperty('choices')) {
buffer = data.choices.at(-1).message.content;
messageInput.textContent = buffer;
}
}
// stream mode
else {
const encode = new TextDecoder("utf-8");
const reader = response.body.getReader();
// read the response content by iteration
while (true) {
const result = await reader.read();
if (result.done) {
break;
}
// decode content
const text = "" + encode.decode(result.value);
// search for required output
const regex = /data: {"id":".*?","object":".*?","created":.*?,"model":".*?","choices":\[\{"delta":\{"content":"(.*?)"\},"index":.*?,"finish_reason":.*?\}\]}/g;
const matches = text.matchAll(regex);
for (const match of matches) {
// get the text message
buffer += match[1];
// update the input grid
messageInput.textContent = JSON.parse(`"${buffer}"`);
messageInput.oninput();
chatMessagePanel.scrollTop = chatMessagePanel.scrollHeight;
}
}
}
}
else {
// display the error message returned by openAI
let output = ""
try {
let data = await response.json();
output = `Error ${response.status} ${data.error.type}:\n\n${data.error.message}`
}
catch(err) {
output = `Error ${response.status}`
}
messageInput.textContent = output;
}
// update the message input box
messageInput.oninput();
// update the scroll position of the panel
chatMessagePanel.scrollTop = chatMessagePanel.scrollHeight;
// enable the submit button again
submitChatButton.disabled = false;
submitChatButton.style.opacity = 1;
}
</script>
</body>
</html>