tosanoob commited on
Commit
3c6f1bf
1 Parent(s): e0404ce

Update chat/templates/index.html

Browse files
Files changed (1) hide show
  1. chat/templates/index.html +307 -307
chat/templates/index.html CHANGED
@@ -1,308 +1,308 @@
1
- <!doctype html>
2
- <html>
3
-
4
- <head>
5
- <title>Python Project</title>
6
- <meta charset="UTF-8">
7
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
- <script src="https://cdn.tailwindcss.com"></script>
9
- <!-- <script>
10
- // const roomdata = JSON.parse('{{ roomdata|safe }}');
11
- var roomdata = JSON.parse('{{ roomdata|safe }}');
12
- console.log(roomdata)
13
- function call() {
14
- return roomdata;
15
- }
16
- </script> -->
17
- <style>
18
- body {
19
- margin: 0;
20
- padding: 0;
21
- background-color: #2A2A2A;
22
- color: white;
23
- }
24
-
25
- .container {
26
- display: flex;
27
- height: 100vh;
28
- }
29
-
30
- .left-column {
31
- width: 25%;
32
- background-color: #3A3A3A;
33
- padding: 20px;
34
- overflow-y: auto;
35
- }
36
-
37
- .right-column {
38
- width: 75%;
39
- background-color: #2E2E2E;
40
- padding: 20px;
41
- overflow-y: auto;
42
- }
43
- .logout-button {
44
- margin-left: 30px; /* Adjust this value for more space */
45
- }
46
- </style>
47
- </head>
48
- <script>
49
- function textAreaAdjust(element) {
50
- element.style.height = "1px";
51
- element.style.height = (25 + element.scrollHeight) + "px";
52
- }
53
- </script>
54
-
55
- <body>
56
- <div id="app" class="container">
57
- <div class="left-column">
58
- <h2 class="text-xl font-medium mb-4">Lịch sử đoạn chat<button @click="logout" class="bg-blue-500 text-white px-2 py-1 rounded mt-2 logout-button">
59
- <a :href="`/users/logout`">Logout</a>
60
- </button></h2>
61
- <ul class="list-none">
62
- {% for x in rooms %}
63
- <li class="p-2 bg-[#4A4A4A] mb-2 rounded flex justify-between items-center">
64
- <a :href="`/chat?id={{x.id}}`" class="cursor-pointer">{{ x.name }}</a>
65
- <a :href="`/chat/delete?id={{x.id}}`" class="bg-red-500 text-white px-2 py-1 rounded">
66
- Xoá
67
- </a>
68
- </li>
69
- {% endfor %}
70
- </ul>
71
-
72
- </div>
73
-
74
- <div class="right-column flex flex-col md:mx-auto mx-0 bg-[#2E2E2E] w-full h-screen">
75
-
76
- <div class="flex flex-col h-full">
77
- <!-- head -->
78
- <div class="flex flex-row justify-between items-center p-4 select-none">
79
- <h1 class="text-2xl font-medium text-center">
80
- TinyChat
81
- </h1>
82
- <div>
83
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"
84
- class="cursor-pointer" :class="{'text-white':!showConfig,'text-[#919191]':showConfig}"
85
- @click="showConfig=!showConfig">
86
- <path
87
- d="M11.6439 3C10.9352 3 10.2794 3.37508 9.92001 3.98596L9.49643 4.70605C8.96183 5.61487 7.98937 6.17632 6.935 6.18489L6.09966 6.19168C5.39095 6.19744 4.73822 6.57783 4.38385 7.19161L4.02775 7.80841C3.67338 8.42219 3.67031 9.17767 4.01968 9.7943L4.4315 10.5212C4.95126 11.4386 4.95126 12.5615 4.4315 13.4788L4.01968 14.2057C3.67031 14.8224 3.67338 15.5778 4.02775 16.1916L4.38385 16.8084C4.73822 17.4222 5.39095 17.8026 6.09965 17.8083L6.93501 17.8151C7.98938 17.8237 8.96184 18.3851 9.49644 19.294L9.92001 20.014C10.2794 20.6249 10.9352 21 11.6439 21H12.3561C13.0648 21 13.7206 20.6249 14.08 20.014L14.5035 19.294C15.0381 18.3851 16.0106 17.8237 17.065 17.8151L17.9004 17.8083C18.6091 17.8026 19.2618 17.4222 19.6162 16.8084L19.9723 16.1916C20.3267 15.5778 20.3298 14.8224 19.9804 14.2057L19.5686 13.4788C19.0488 12.5615 19.0488 11.4386 19.5686 10.5212L19.9804 9.7943C20.3298 9.17767 20.3267 8.42219 19.9723 7.80841L19.6162 7.19161C19.2618 6.57783 18.6091 6.19744 17.9004 6.19168L17.065 6.18489C16.0106 6.17632 15.0382 5.61487 14.5036 4.70605L14.08 3.98596C13.7206 3.37508 13.0648 3 12.3561 3H11.6439Z"
88
- stroke="white" stroke-width="2" stroke-linejoin="round" />
89
- <path
90
- d="M12 14.5C13.3807 14.5 14.5 13.3807 14.5 12C14.5 10.6193 13.3807 9.5 12 9.5C10.6193 9.5 9.5 10.6193 9.5 12C9.5 13.3807 10.6193 14.5 12 14.5Z"
91
- stroke="white" stroke-width="2" />
92
- </svg>
93
-
94
- </div>
95
- </div>
96
- <!-- config -->
97
- <div v-show="showConfig" class="flex flex-col gap-4 p-4 select-none">
98
- <!-- render configFields -->
99
- <div v-for="field in configFields" :key="field.name" class="flex flex-col gap-2">
100
- <label class="text-sm text-gray-400">
101
- {{ field.label }}
102
- </label>
103
- <input v-if="field.type=='text'" type="text"
104
- class="bg-transparent border border-[#919191] rounded-lg p-2"
105
- v-model="config[field.name]" />
106
- <input v-if="field.type=='number'" type="number"
107
- class="bg-transparent border border-[#919191] rounded-lg p-2"
108
- v-model="config[field.name]" />
109
- </div>
110
- </div>
111
- <!-- messages -->
112
- <div class="flex flex-col overflow-y-auto scroll-smooth" id="messages">
113
- <div v-for="(message,index) in messages" :key="message.id"
114
- class="flex flex-col odd:bg-[#F7F7F7]/10 group">
115
- <div class="p-4 flex flex-col justify-between gap-4">
116
- <div class="flex flex-row gap-4 capitalize">
117
- <div class="text-gray-400 text-sm">
118
- <textarea
119
- class="text-gray-400 text-sm size-full outline-0 bg-transparent border-none text-white rounded-lg resize-none"
120
- :rows="message.role" v-model="message.role"></textarea>
121
- </div>
122
- <div class="flex flex-col w-full">
123
- <textarea onkeyup="textAreaAdjust(this)" style="overflow:hidden"
124
- class="size-full outline-0 bg-transparent border-none text-white rounded-lg resize-y"
125
- :rows="message.content.split('\n').length" v-model="message.content"></textarea>
126
- <div class="mt-4" v-if="index==messages.length-1 && message.role=='assistant'">
127
- <svg stroke="currentColor" fill="none" stroke-width="1.5" viewBox="0 0 24 24"
128
- stroke-linecap="round" stroke-linejoin="round" height="1em" width="1em"
129
- xmlns="http://www.w3.org/2000/svg" v-if="index==messages.length-1"
130
- class="group-hover:block cursor-pointer h-3 w-3" @click="refresh"
131
- :class="{'animate-spin':isLoading}">
132
- >
133
- >
134
- >
135
- <polyline points="1 4 1 10 7 10"></polyline>
136
- <polyline points="23 20 23 14 17 14"></polyline>
137
- <path
138
- d="M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15">
139
- </path>
140
-
141
- </svg>
142
- </div>
143
- </div>
144
- </div>
145
- </div>
146
- </div>
147
- </div>
148
- </div>
149
- <!-- send message -->
150
- <div class="flex flex-row justify-between items-center p-4 sticky bottom-0 bg-[#2E2E2E]" v-if="!showConfig">
151
- <div class="w-full flex flex-row border border-1 border-[#919191] rounded-xl px-4 py-6 items-center">
152
- <textarea
153
- class="w-full h-full outline-0 bg-transparent border-none text-white resize-none text-md max-h-[100px]"
154
- v-on:keyup.enter="sendMessage" placeholder="Type a message" :rows="message.split('\n').length"
155
- v-model="message"></textarea>
156
- <div class="flex flex-col justify-end gap-4 text-[#2E2E2E] rounded-md p-1"
157
- :class="{'bg-white':message!='','bg-white/10':message==''}">
158
- <button @click="sendMessage">
159
- <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"
160
- xmlns="http://www.w3.org/2000/svg">
161
- <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
162
- d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8" />
163
- </svg>
164
- </button>
165
- </div>
166
- </div>
167
- </div>
168
-
169
- </div>
170
-
171
- <script type="module">
172
- import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
173
- // import { SSE } from "https://cdn.jsdelivr.net/npm/sse.js@2.1.0/lib/sse.min.js"
174
-
175
- var roomdata = {{ roomdata|safe }};
176
-
177
- createApp({
178
- data() {
179
- return {
180
- showConfig: false,
181
- configFields: [
182
- {
183
- name: "endPoint",
184
- type: "text",
185
- label: "End Point"
186
- },
187
- {
188
- name: "apiKey",
189
- type: "text",
190
- label: "API Key"
191
- },
192
- {
193
- name: "model",
194
- type: "text",
195
- label: "Model"
196
- },
197
- {
198
- name: "temperature",
199
- type: "number",
200
- label: "Temperature"
201
- },
202
- {
203
- name: "presence_penalty",
204
- type: "number",
205
- label: "Presence Penalty"
206
- },
207
- {
208
- name: "top_p",
209
- type: "number",
210
- label: "Top P"
211
- },
212
- {
213
- name: "frequency_penalty",
214
- type: "number",
215
- label: "Frequency Penalty"
216
- },
217
- ],
218
- isLoading: false,
219
- message: '',
220
- messages: roomdata.messages,
221
- // cs:roomdata,
222
- chatSocket: null,
223
- config: {
224
- endPoint: "",
225
- apiKey: "",
226
- model: "gpt-3.5-turbo",
227
- temperature: 1,
228
- presence_penalty: 0,
229
- top_p: 1,
230
- frequency_penalty: 0,
231
- stream: true
232
- },
233
- // roomdata: roomdata
234
- }
235
-
236
- },
237
- created() {
238
- // const roomdata = JSON.parse('roomdata');
239
- const params = new URLSearchParams(window.location.search);
240
- this.id = params.get('id');//chat id
241
- if (this.id == null) {
242
- return
243
- }
244
- this.connect()
245
- },
246
- methods: {
247
- refresh() {
248
- this.send(true);
249
- },
250
- deleteChat(id) {
251
- window.location.href = '/chat/delete?id=' + id;
252
- return;
253
- },
254
- sendMessage() {
255
- if (this.id == null) {
256
- window.location.href = '/chat/newchat?ques=' + this.message;
257
- return;
258
- }
259
- this.messages.push({
260
- role: "user",
261
- content: this.message
262
- });
263
- this.chatSocket.send(JSON.stringify({
264
- 'roomid':this.id,
265
- 'message': this.message,
266
- 'messages': this.messages,
267
- }));
268
- console.log(JSON.stringify({
269
- 'messages': this.messages
270
- }))
271
- this.message = "";
272
- },
273
-
274
- connect() {
275
- this.chatSocket = new WebSocket(
276
- 'ws://' + window.location.host + '/ws/chat'
277
- );
278
-
279
- this.chatSocket.onopen = () => {
280
- this.connectionStatus = 'Connected';
281
- console.log('WebSocket connected');
282
- };
283
-
284
- this.chatSocket.onmessage = (event) => {
285
- var mes = JSON.parse(event.data)
286
- this.messages.push({
287
- role: "model",
288
- content: mes.message
289
- });
290
- console.log('Message received: ', event.data);
291
- };
292
-
293
- this.chatSocket.onclose = () => {
294
- this.connectionStatus = 'Disconnected';
295
- console.log('WebSocket disconnected');
296
- };
297
-
298
- this.chatSocket.onerror = (error) => {
299
- console.error('WebSocket Error: ', error);
300
- };
301
- }
302
- },
303
- }).mount('#app')
304
- </script>
305
- </div>
306
- </body>
307
-
308
  </html>
 
1
+ <!doctype html>
2
+ <html>
3
+
4
+ <head>
5
+ <title>Python Project</title>
6
+ <meta charset="UTF-8">
7
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <!-- <script>
10
+ // const roomdata = JSON.parse('{{ roomdata|safe }}');
11
+ var roomdata = JSON.parse('{{ roomdata|safe }}');
12
+ console.log(roomdata)
13
+ function call() {
14
+ return roomdata;
15
+ }
16
+ </script> -->
17
+ <style>
18
+ body {
19
+ margin: 0;
20
+ padding: 0;
21
+ background-color: #2A2A2A;
22
+ color: white;
23
+ }
24
+
25
+ .container {
26
+ display: flex;
27
+ height: 100vh;
28
+ }
29
+
30
+ .left-column {
31
+ width: 25%;
32
+ background-color: #3A3A3A;
33
+ padding: 20px;
34
+ overflow-y: auto;
35
+ }
36
+
37
+ .right-column {
38
+ width: 75%;
39
+ background-color: #2E2E2E;
40
+ padding: 20px;
41
+ overflow-y: auto;
42
+ }
43
+ .logout-button {
44
+ margin-left: 30px; /* Adjust this value for more space */
45
+ }
46
+ </style>
47
+ </head>
48
+ <script>
49
+ function textAreaAdjust(element) {
50
+ element.style.height = "1px";
51
+ element.style.height = (25 + element.scrollHeight) + "px";
52
+ }
53
+ </script>
54
+
55
+ <body>
56
+ <div id="app" class="container">
57
+ <div class="left-column">
58
+ <h2 class="text-xl font-medium mb-4">Lịch sử đoạn chat<button @click="logout" class="bg-blue-500 text-white px-2 py-1 rounded mt-2 logout-button">
59
+ <a :href="`/users/logout`">Logout</a>
60
+ </button></h2>
61
+ <ul class="list-none">
62
+ {% for x in rooms %}
63
+ <li class="p-2 bg-[#4A4A4A] mb-2 rounded flex justify-between items-center">
64
+ <a :href="`/chat?id={{x.id}}`" class="cursor-pointer">{{ x.name }}</a>
65
+ <a :href="`/chat/delete?id={{x.id}}`" class="bg-red-500 text-white px-2 py-1 rounded">
66
+ Xoá
67
+ </a>
68
+ </li>
69
+ {% endfor %}
70
+ </ul>
71
+
72
+ </div>
73
+
74
+ <div class="right-column flex flex-col md:mx-auto mx-0 bg-[#2E2E2E] w-full h-screen">
75
+
76
+ <div class="flex flex-col h-full">
77
+ <!-- head -->
78
+ <div class="flex flex-row justify-between items-center p-4 select-none">
79
+ <h1 class="text-2xl font-medium text-center">
80
+ TinyChat
81
+ </h1>
82
+ <div>
83
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"
84
+ class="cursor-pointer" :class="{'text-white':!showConfig,'text-[#919191]':showConfig}"
85
+ @click="showConfig=!showConfig">
86
+ <path
87
+ d="M11.6439 3C10.9352 3 10.2794 3.37508 9.92001 3.98596L9.49643 4.70605C8.96183 5.61487 7.98937 6.17632 6.935 6.18489L6.09966 6.19168C5.39095 6.19744 4.73822 6.57783 4.38385 7.19161L4.02775 7.80841C3.67338 8.42219 3.67031 9.17767 4.01968 9.7943L4.4315 10.5212C4.95126 11.4386 4.95126 12.5615 4.4315 13.4788L4.01968 14.2057C3.67031 14.8224 3.67338 15.5778 4.02775 16.1916L4.38385 16.8084C4.73822 17.4222 5.39095 17.8026 6.09965 17.8083L6.93501 17.8151C7.98938 17.8237 8.96184 18.3851 9.49644 19.294L9.92001 20.014C10.2794 20.6249 10.9352 21 11.6439 21H12.3561C13.0648 21 13.7206 20.6249 14.08 20.014L14.5035 19.294C15.0381 18.3851 16.0106 17.8237 17.065 17.8151L17.9004 17.8083C18.6091 17.8026 19.2618 17.4222 19.6162 16.8084L19.9723 16.1916C20.3267 15.5778 20.3298 14.8224 19.9804 14.2057L19.5686 13.4788C19.0488 12.5615 19.0488 11.4386 19.5686 10.5212L19.9804 9.7943C20.3298 9.17767 20.3267 8.42219 19.9723 7.80841L19.6162 7.19161C19.2618 6.57783 18.6091 6.19744 17.9004 6.19168L17.065 6.18489C16.0106 6.17632 15.0382 5.61487 14.5036 4.70605L14.08 3.98596C13.7206 3.37508 13.0648 3 12.3561 3H11.6439Z"
88
+ stroke="white" stroke-width="2" stroke-linejoin="round" />
89
+ <path
90
+ d="M12 14.5C13.3807 14.5 14.5 13.3807 14.5 12C14.5 10.6193 13.3807 9.5 12 9.5C10.6193 9.5 9.5 10.6193 9.5 12C9.5 13.3807 10.6193 14.5 12 14.5Z"
91
+ stroke="white" stroke-width="2" />
92
+ </svg>
93
+
94
+ </div>
95
+ </div>
96
+ <!-- config -->
97
+ <div v-show="showConfig" class="flex flex-col gap-4 p-4 select-none">
98
+ <!-- render configFields -->
99
+ <div v-for="field in configFields" :key="field.name" class="flex flex-col gap-2">
100
+ <label class="text-sm text-gray-400">
101
+ {{ field.label }}
102
+ </label>
103
+ <input v-if="field.type=='text'" type="text"
104
+ class="bg-transparent border border-[#919191] rounded-lg p-2"
105
+ v-model="config[field.name]" />
106
+ <input v-if="field.type=='number'" type="number"
107
+ class="bg-transparent border border-[#919191] rounded-lg p-2"
108
+ v-model="config[field.name]" />
109
+ </div>
110
+ </div>
111
+ <!-- messages -->
112
+ <div class="flex flex-col overflow-y-auto scroll-smooth" id="messages">
113
+ <div v-for="(message,index) in messages" :key="message.id"
114
+ class="flex flex-col odd:bg-[#F7F7F7]/10 group">
115
+ <div class="p-4 flex flex-col justify-between gap-4">
116
+ <div class="flex flex-row gap-4 capitalize">
117
+ <div class="text-gray-400 text-sm">
118
+ <textarea
119
+ class="text-gray-400 text-sm size-full outline-0 bg-transparent border-none text-white rounded-lg resize-none"
120
+ :rows="message.role" v-model="message.role"></textarea>
121
+ </div>
122
+ <div class="flex flex-col w-full">
123
+ <textarea onkeyup="textAreaAdjust(this)" style="overflow:hidden"
124
+ class="size-full outline-0 bg-transparent border-none text-white rounded-lg resize-y"
125
+ :rows="message.content.split('\n').length" v-model="message.content"></textarea>
126
+ <div class="mt-4" v-if="index==messages.length-1 && message.role=='assistant'">
127
+ <svg stroke="currentColor" fill="none" stroke-width="1.5" viewBox="0 0 24 24"
128
+ stroke-linecap="round" stroke-linejoin="round" height="1em" width="1em"
129
+ xmlns="http://www.w3.org/2000/svg" v-if="index==messages.length-1"
130
+ class="group-hover:block cursor-pointer h-3 w-3" @click="refresh"
131
+ :class="{'animate-spin':isLoading}">
132
+ >
133
+ >
134
+ >
135
+ <polyline points="1 4 1 10 7 10"></polyline>
136
+ <polyline points="23 20 23 14 17 14"></polyline>
137
+ <path
138
+ d="M20.49 9A9 9 0 0 0 5.64 5.64L1 10m22 4l-4.64 4.36A9 9 0 0 1 3.51 15">
139
+ </path>
140
+
141
+ </svg>
142
+ </div>
143
+ </div>
144
+ </div>
145
+ </div>
146
+ </div>
147
+ </div>
148
+ </div>
149
+ <!-- send message -->
150
+ <div class="flex flex-row justify-between items-center p-4 sticky bottom-0 bg-[#2E2E2E]" v-if="!showConfig">
151
+ <div class="w-full flex flex-row border border-1 border-[#919191] rounded-xl px-4 py-6 items-center">
152
+ <textarea
153
+ class="w-full h-full outline-0 bg-transparent border-none text-white resize-none text-md max-h-[100px]"
154
+ v-on:keyup.enter="sendMessage" placeholder="Type a message" :rows="message.split('\n').length"
155
+ v-model="message"></textarea>
156
+ <div class="flex flex-col justify-end gap-4 text-[#2E2E2E] rounded-md p-1"
157
+ :class="{'bg-white':message!='','bg-white/10':message==''}">
158
+ <button @click="sendMessage">
159
+ <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"
160
+ xmlns="http://www.w3.org/2000/svg">
161
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
162
+ d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8" />
163
+ </svg>
164
+ </button>
165
+ </div>
166
+ </div>
167
+ </div>
168
+
169
+ </div>
170
+
171
+ <script type="module">
172
+ import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
173
+ // import { SSE } from "https://cdn.jsdelivr.net/npm/sse.js@2.1.0/lib/sse.min.js"
174
+
175
+ var roomdata = {{ roomdata|safe }};
176
+
177
+ createApp({
178
+ data() {
179
+ return {
180
+ showConfig: false,
181
+ configFields: [
182
+ {
183
+ name: "endPoint",
184
+ type: "text",
185
+ label: "End Point"
186
+ },
187
+ {
188
+ name: "apiKey",
189
+ type: "text",
190
+ label: "API Key"
191
+ },
192
+ {
193
+ name: "model",
194
+ type: "text",
195
+ label: "Model"
196
+ },
197
+ {
198
+ name: "temperature",
199
+ type: "number",
200
+ label: "Temperature"
201
+ },
202
+ {
203
+ name: "presence_penalty",
204
+ type: "number",
205
+ label: "Presence Penalty"
206
+ },
207
+ {
208
+ name: "top_p",
209
+ type: "number",
210
+ label: "Top P"
211
+ },
212
+ {
213
+ name: "frequency_penalty",
214
+ type: "number",
215
+ label: "Frequency Penalty"
216
+ },
217
+ ],
218
+ isLoading: false,
219
+ message: '',
220
+ messages: roomdata.messages,
221
+ // cs:roomdata,
222
+ chatSocket: null,
223
+ config: {
224
+ endPoint: "",
225
+ apiKey: "",
226
+ model: "gpt-3.5-turbo",
227
+ temperature: 1,
228
+ presence_penalty: 0,
229
+ top_p: 1,
230
+ frequency_penalty: 0,
231
+ stream: true
232
+ },
233
+ // roomdata: roomdata
234
+ }
235
+
236
+ },
237
+ created() {
238
+ // const roomdata = JSON.parse('roomdata');
239
+ const params = new URLSearchParams(window.location.search);
240
+ this.id = params.get('id');//chat id
241
+ if (this.id == null) {
242
+ return
243
+ }
244
+ this.connect()
245
+ },
246
+ methods: {
247
+ refresh() {
248
+ this.send(true);
249
+ },
250
+ deleteChat(id) {
251
+ window.location.href = '/chat/delete?id=' + id;
252
+ return;
253
+ },
254
+ sendMessage() {
255
+ if (this.id == null) {
256
+ window.location.href = '/chat/newchat?ques=' + this.message;
257
+ return;
258
+ }
259
+ this.messages.push({
260
+ role: "user",
261
+ content: this.message
262
+ });
263
+ this.chatSocket.send(JSON.stringify({
264
+ 'roomid':this.id,
265
+ 'message': this.message,
266
+ 'messages': this.messages,
267
+ }));
268
+ console.log(JSON.stringify({
269
+ 'messages': this.messages
270
+ }))
271
+ this.message = "";
272
+ },
273
+
274
+ connect() {
275
+ this.chatSocket = new WebSocket(
276
+ 'wss://' + window.location.host + '/wss/chat'
277
+ );
278
+
279
+ this.chatSocket.onopen = () => {
280
+ this.connectionStatus = 'Connected';
281
+ console.log('WebSocket connected');
282
+ };
283
+
284
+ this.chatSocket.onmessage = (event) => {
285
+ var mes = JSON.parse(event.data)
286
+ this.messages.push({
287
+ role: "model",
288
+ content: mes.message
289
+ });
290
+ console.log('Message received: ', event.data);
291
+ };
292
+
293
+ this.chatSocket.onclose = () => {
294
+ this.connectionStatus = 'Disconnected';
295
+ console.log('WebSocket disconnected');
296
+ };
297
+
298
+ this.chatSocket.onerror = (error) => {
299
+ console.error('WebSocket Error: ', error);
300
+ };
301
+ }
302
+ },
303
+ }).mount('#app')
304
+ </script>
305
+ </div>
306
+ </body>
307
+
308
  </html>