Artteiv commited on
Commit
621d93e
1 Parent(s): 92cd7bb

The last samurai, a way of life

Browse files
Files changed (1) hide show
  1. chat/templates/index.html +52 -141
chat/templates/index.html CHANGED
@@ -7,14 +7,7 @@
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
  <meta name="csrf-token" content="{{ csrf_token }}">
9
  <script src="https://cdn.tailwindcss.com"></script>
10
- <!-- <script>
11
- // const roomdata = JSON.parse('{{ roomdata|safe }}');
12
- var roomdata = JSON.parse('{{ roomdata|safe }}');
13
- console.log(roomdata)
14
- function call() {
15
- return roomdata;
16
- }
17
- </script> -->
18
  <style>
19
  body {
20
  margin: 0;
@@ -41,35 +34,38 @@
41
  padding: 20px;
42
  overflow-y: auto;
43
  }
 
44
  .logout-button {
45
- margin-left: 30px; /* Adjust this value for more space */
 
46
  }
47
  </style>
48
  </head>
49
  <script>
50
  function textAreaAdjust(element) {
51
  element.style.height = "1px";
52
- element.style.height = (25 + element.scrollHeight) + "px";
53
  }
54
  </script>
55
 
56
  <body>
57
  <div id="app" class="container">
58
  <div class="left-column">
59
- <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">
60
- <a :href="`/users/logout`">Logout</a>
61
- </button></h2>
 
62
  <ul class="list-none">
63
  {% for x in rooms %}
64
- <li class="p-2 bg-[#4A4A4A] mb-2 rounded flex justify-between items-center">
65
- <a :href="`/chat?id={{x.id}}`" class="cursor-pointer">{{ x.name }}</a>
66
- <a :href="`/chat/delete?id={{x.id}}`" class="bg-red-500 text-white px-2 py-1 rounded">
67
- Xoá
68
- </a>
69
- </li>
70
  {% endfor %}
71
  </ul>
72
-
73
  </div>
74
 
75
  <div class="right-column flex flex-col md:mx-auto mx-0 bg-[#2E2E2E] w-full h-screen">
@@ -78,70 +74,28 @@
78
  <!-- head -->
79
  <div class="flex flex-row justify-between items-center p-4 select-none">
80
  <h1 class="text-2xl font-medium text-center">
81
- <a :href="`/chat`">Arxiv Chatbot</a>
82
  </h1>
83
- <div>
84
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"
85
- class="cursor-pointer" :class="{'text-white':!showConfig,'text-[#919191]':showConfig}"
86
- @click="showConfig=!showConfig">
87
- <path
88
- 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"
89
- stroke="white" stroke-width="2" stroke-linejoin="round" />
90
- <path
91
- 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"
92
- stroke="white" stroke-width="2" />
93
- </svg>
94
-
95
- </div>
96
  </div>
97
  <!-- config -->
98
- <div v-show="showConfig" class="flex flex-col gap-4 p-4 select-none">
99
- <!-- render configFields -->
100
- <div v-for="field in configFields" :key="field.name" class="flex flex-col gap-2">
101
- <label class="text-sm text-gray-400">
102
- {{ field.label }}
103
- </label>
104
- <input v-if="field.type=='text'" type="text"
105
- class="bg-transparent border border-[#919191] rounded-lg p-2"
106
- v-model="config[field.name]" />
107
- <input v-if="field.type=='number'" type="number"
108
- class="bg-transparent border border-[#919191] rounded-lg p-2"
109
- v-model="config[field.name]" />
110
- </div>
111
- </div>
112
  <!-- messages -->
113
  <div class="flex flex-col overflow-y-auto scroll-smooth" id="messages">
114
  <div v-for="(message,index) in messages" :key="message.id"
115
  class="flex flex-col odd:bg-[#F7F7F7]/10 group">
116
  <div class="p-4 flex flex-col justify-between gap-4">
117
  <div class="flex flex-row gap-4 capitalize">
 
118
  <div class="text-gray-400 text-sm">
119
  <textarea
120
  class="text-gray-400 text-sm size-full outline-0 bg-transparent border-none text-white rounded-lg resize-none"
121
- :rows="message.role" v-model="message.role"></textarea>
 
122
  </div>
123
- <div class="flex flex-col w-full">
124
- <textarea onkeyup="textAreaAdjust(this)" style="overflow:hidden"
125
- class="size-full outline-0 bg-transparent border-none text-white rounded-lg resize-y"
126
- :rows="message.content.split('\n').length" v-model="message.content"></textarea>
127
- <div class="mt-4" v-if="index==messages.length-1 && message.role=='assistant'">
128
- <svg stroke="currentColor" fill="none" stroke-width="1.5" viewBox="0 0 24 24"
129
- stroke-linecap="round" stroke-linejoin="round" height="1em" width="1em"
130
- xmlns="http://www.w3.org/2000/svg" v-if="index==messages.length-1"
131
- class="group-hover:block cursor-pointer h-3 w-3" @click="refresh"
132
- :class="{'animate-spin':isLoading}">
133
- >
134
- >
135
- >
136
- <polyline points="1 4 1 10 7 10"></polyline>
137
- <polyline points="23 20 23 14 17 14"></polyline>
138
- <path
139
- 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">
140
- </path>
141
 
142
- </svg>
143
- </div>
144
  </div>
 
145
  </div>
146
  </div>
147
  </div>
@@ -152,8 +106,8 @@
152
  <div class="w-full flex flex-row border border-1 border-[#919191] rounded-xl px-4 py-6 items-center">
153
  <textarea
154
  class="w-full h-full outline-0 bg-transparent border-none text-white resize-none text-md max-h-[100px]"
155
- v-on:keyup.enter="sendMessageAPI" placeholder="Type a message" :rows="message.split('\n').length"
156
- v-model="message"></textarea>
157
  <div class="flex flex-col justify-end gap-4 text-[#2E2E2E] rounded-md p-1"
158
  :class="{'bg-white':message!='','bg-white/10':message==''}">
159
  <button @click="sendMessageAPI">
@@ -168,12 +122,13 @@
168
  </div>
169
 
170
  </div>
171
-
172
  <script type="module">
173
- import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js'
174
- // import { SSE } from "https://cdn.jsdelivr.net/npm/[email protected]/lib/sse.min.js"
175
-
176
- var roomdata = {{ roomdata|safe }};
 
177
 
178
  createApp({
179
  data() {
@@ -217,7 +172,7 @@
217
  },
218
  ],
219
  isLoading: false,
220
- isFirst:true,
221
  message: '',
222
  messages: roomdata.messages,
223
  // cs:roomdata,
@@ -245,7 +200,7 @@
245
  }
246
  // this.connect()
247
  this.ques = params.get('ques');
248
- if (this.ques != null && this.isFirst==true) {
249
  this.message = this.ques;
250
  this.isFirst = false;
251
  this.sendMessageAPI();
@@ -255,6 +210,11 @@
255
  refresh() {
256
  this.send(true);
257
  },
 
 
 
 
 
258
  deleteChat(id) {
259
  window.location.href = '/chat/delete?id=' + id;
260
  return;
@@ -274,76 +234,27 @@
274
  fetch('/chat/messages/', {
275
  method: 'POST',
276
  headers: {
277
- 'Content-Type': 'application/json'
278
  },
279
  body: JSON.stringify({
280
- 'roomid': this.id,
281
- 'message': this.ques,
282
- 'messages': this.messages,
283
  })
284
  })
285
- .then(response => response.json())
286
- .then(data => {
287
- this.messages.push({
288
- role: "model",
289
- content: data.message
 
 
 
 
290
  });
291
- })
292
- .catch(error => {
293
- console.error('Error sending or fetching messages:', error);
294
- });
295
  },
296
-
297
- // sendMessage() {
298
- // if (this.id == null) {
299
- // window.location.href = '/chat/newchat?ques=' + this.message;
300
- // return;
301
- // }
302
- // this.messages.push({
303
- // role: "user",
304
- // content: this.message
305
- // });
306
- // this.chatSocket.send(JSON.stringify({
307
- // 'roomid':this.id,
308
- // 'message': this.message,
309
- // 'messages': this.messages,
310
- // }));
311
- // console.log(JSON.stringify({
312
- // 'messages': this.messages
313
- // }))
314
- // this.message = "";
315
- // },
316
-
317
- // connect() {
318
- // this.chatSocket = new WebSocket(
319
- // 'wss://' + window.location.host + '/wss/chat'
320
- // );
321
-
322
- // this.chatSocket.onopen = () => {
323
- // this.connectionStatus = 'Connected';
324
- // console.log('WebSocket connected');
325
- // };
326
-
327
- // this.chatSocket.onmessage = (event) => {
328
- // var mes = JSON.parse(event.data)
329
- // this.messages.push({
330
- // role: "model",
331
- // content: mes.message
332
- // });
333
- // console.log('Message received: ', event.data);
334
- // };
335
-
336
- // this.chatSocket.onclose = () => {
337
- // this.connectionStatus = 'Disconnected';
338
- // console.log('WebSocket disconnected');
339
- // };
340
-
341
- // this.chatSocket.onerror = (error) => {
342
- // console.error('WebSocket Error: ', error);
343
- // };
344
- // }
345
  },
346
- }).mount('#app')
347
  </script>
348
  </div>
349
  </body>
 
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
  <meta name="csrf-token" content="{{ csrf_token }}">
9
  <script src="https://cdn.tailwindcss.com"></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/[email protected]/marked.min.js"></script>
 
 
 
 
 
 
 
11
  <style>
12
  body {
13
  margin: 0;
 
34
  padding: 20px;
35
  overflow-y: auto;
36
  }
37
+
38
  .logout-button {
39
+ margin-left: 30px;
40
+ /* Adjust this value for more space */
41
  }
42
  </style>
43
  </head>
44
  <script>
45
  function textAreaAdjust(element) {
46
  element.style.height = "1px";
47
+ element.style.height = (element.scrollHeight/2) + "px";
48
  }
49
  </script>
50
 
51
  <body>
52
  <div id="app" class="container">
53
  <div class="left-column">
54
+ <h2 class="text-xl font-medium mb-4">Lịch sử đoạn chat<button @click="logout"
55
+ class="bg-blue-500 text-white px-2 py-1 rounded mt-2 logout-button">
56
+ <a :href="`/users/logout`">Logout</a>
57
+ </button></h2>
58
  <ul class="list-none">
59
  {% for x in rooms %}
60
+ <li class="p-2 bg-[#4A4A4A] mb-2 rounded flex justify-between items-center">
61
+ <a :href="`/chat?id={{x.id}}`" class="cursor-pointer">{{ x.name }}</a>
62
+ <a :href="`/chat/delete?id={{x.id}}`" class="bg-red-500 text-white px-2 py-1 rounded">
63
+ Xoá
64
+ </a>
65
+ </li>
66
  {% endfor %}
67
  </ul>
68
+
69
  </div>
70
 
71
  <div class="right-column flex flex-col md:mx-auto mx-0 bg-[#2E2E2E] w-full h-screen">
 
74
  <!-- head -->
75
  <div class="flex flex-row justify-between items-center p-4 select-none">
76
  <h1 class="text-2xl font-medium text-center">
77
+ <a :href="`/chat`">Create new</a>
78
  </h1>
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  </div>
80
  <!-- config -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  <!-- messages -->
82
  <div class="flex flex-col overflow-y-auto scroll-smooth" id="messages">
83
  <div v-for="(message,index) in messages" :key="message.id"
84
  class="flex flex-col odd:bg-[#F7F7F7]/10 group">
85
  <div class="p-4 flex flex-col justify-between gap-4">
86
  <div class="flex flex-row gap-4 capitalize">
87
+
88
  <div class="text-gray-400 text-sm">
89
  <textarea
90
  class="text-gray-400 text-sm size-full outline-0 bg-transparent border-none text-white rounded-lg resize-none"
91
+ :rows="message.role" v-model="message.role" readonly>
92
+ </textarea>
93
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
 
95
+ <div class="flex flex-col w-full">
96
+ <div v-html="renderedMarkdown(message.content)" class="markdown-preview"></div>
97
  </div>
98
+
99
  </div>
100
  </div>
101
  </div>
 
106
  <div class="w-full flex flex-row border border-1 border-[#919191] rounded-xl px-4 py-6 items-center">
107
  <textarea
108
  class="w-full h-full outline-0 bg-transparent border-none text-white resize-none text-md max-h-[100px]"
109
+ v-on:keyup.enter="sendMessageAPI" placeholder="Type a message"
110
+ :rows="message.split('\n').length" v-model="message"></textarea>
111
  <div class="flex flex-col justify-end gap-4 text-[#2E2E2E] rounded-md p-1"
112
  :class="{'bg-white':message!='','bg-white/10':message==''}">
113
  <button @click="sendMessageAPI">
 
122
  </div>
123
 
124
  </div>
125
+
126
  <script type="module">
127
+ import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js';
128
+
129
+
130
+
131
+ var roomdata = {{ roomdata| safe }};
132
 
133
  createApp({
134
  data() {
 
172
  },
173
  ],
174
  isLoading: false,
175
+ isFirst: true,
176
  message: '',
177
  messages: roomdata.messages,
178
  // cs:roomdata,
 
200
  }
201
  // this.connect()
202
  this.ques = params.get('ques');
203
+ if (this.ques != null && this.isFirst == true) {
204
  this.message = this.ques;
205
  this.isFirst = false;
206
  this.sendMessageAPI();
 
210
  refresh() {
211
  this.send(true);
212
  },
213
+ renderedMarkdown(content) {
214
+ return marked.parse(content);
215
+ }
216
+ ,
217
+
218
  deleteChat(id) {
219
  window.location.href = '/chat/delete?id=' + id;
220
  return;
 
234
  fetch('/chat/messages/', {
235
  method: 'POST',
236
  headers: {
237
+ 'Content-Type': 'application/json'
238
  },
239
  body: JSON.stringify({
240
+ 'roomid': this.id,
241
+ 'message': this.ques,
242
+ 'messages': this.messages,
243
  })
244
  })
245
+ .then(response => response.json())
246
+ .then(data => {
247
+ this.messages.push({
248
+ role: "model",
249
+ content: data.message
250
+ });
251
+ })
252
+ .catch(error => {
253
+ console.error('Error sending or fetching messages:', error);
254
  });
 
 
 
 
255
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
256
  },
257
+ }).mount('#app');
258
  </script>
259
  </div>
260
  </body>