Keldos commited on
Commit
578e872
·
unverified ·
1 Parent(s): 19fbb51

feat: 将引用网站改为气泡形式 (#806)

Browse files

* feat: 将引用网站改为气泡形式

* feat: 在raw-message中不显示display_append

* feat: 引用网站气泡改为多行气泡

* feat: 在线搜索 append 卡片适配网页标题形式

* fix: 修复网址被escape成字符串显示的错误

这个错误的原因是,形如`https://xxx`的网址也会直接被marked渲染为url的html格式,
因此后面接的)或]符号就会被渲染为输出的字符串的一部分。

这里把冒号也直接escape了,解决了这个问题。

assets/custom.css CHANGED
@@ -204,6 +204,45 @@ input[type=range]::-webkit-slider-runnable-track {
204
  background: transparent;
205
  }
206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
207
  #submit_btn, #cancel_btn {
208
  height: 42px !important;
209
  }
 
204
  background: transparent;
205
  }
206
 
207
+ hr.append-display {
208
+ margin: 8px 0;
209
+ border: none;
210
+ height: 1px;
211
+ border-top-width: 0;
212
+ background-image: linear-gradient(to right, rgba(50,50,50, 0.1), rgba(150, 150, 150, 0.8), rgba(50,50,50, 0.1));
213
+ }
214
+ .source-a {
215
+ font-size: 0.8em;
216
+ max-width: 100%;
217
+ margin: 0;
218
+ display: flex;
219
+ flex-direction: row;
220
+ flex-wrap: wrap;
221
+ align-items: center;
222
+ /* background-color: #dddddd88; */
223
+ border-radius: 1.5rem;
224
+ padding: 0.2em;
225
+ }
226
+ .source-a a {
227
+ display: inline-block;
228
+ background-color: #aaaaaa50;
229
+ border-radius: 1rem;
230
+ padding: 0.5em;
231
+ text-align: center;
232
+ text-overflow: ellipsis;
233
+ overflow: hidden;
234
+ min-width: 20%;
235
+ white-space: nowrap;
236
+ margin: 0.2rem 0.1rem;
237
+ text-decoration: none !important;
238
+ flex: 1;
239
+ transition: flex 0.5s;
240
+ }
241
+ .source-a a:hover {
242
+ background-color: #aaaaaa20;
243
+ flex: 2;
244
+ }
245
+
246
  #submit_btn, #cancel_btn {
247
  height: 42px !important;
248
  }
modules/models/base_model.py CHANGED
@@ -246,7 +246,7 @@ class BaseLLMModel:
246
  stream_iter = self.get_answer_stream_iter()
247
 
248
  if display_append:
249
- display_append = "<hr>" +display_append
250
  for partial_text in stream_iter:
251
  chatbot[-1] = (chatbot[-1][0], partial_text + display_append)
252
  self.all_token_counts[-1] += 1
@@ -348,10 +348,11 @@ class BaseLLMModel:
348
  reference_results.append([result['body'], result['href']])
349
  display_append.append(
350
  # f"{idx+1}. [{domain_name}]({result['href']})\n"
351
- f"<li><a href=\"{result['href']}\" target=\"_blank\">{result['title']}</a></li>\n"
352
  )
353
  reference_results = add_source_numbers(reference_results)
354
- display_append = "<ol>\n\n" + "".join(display_append) + "</ol>"
 
355
  real_inputs = (
356
  replace_today(WEBSEARCH_PTOMPT_TEMPLATE)
357
  .replace("{query}", real_inputs)
 
246
  stream_iter = self.get_answer_stream_iter()
247
 
248
  if display_append:
249
+ display_append = '\n\n<hr class="append-display no-in-raw" />' + display_append
250
  for partial_text in stream_iter:
251
  chatbot[-1] = (chatbot[-1][0], partial_text + display_append)
252
  self.all_token_counts[-1] += 1
 
348
  reference_results.append([result['body'], result['href']])
349
  display_append.append(
350
  # f"{idx+1}. [{domain_name}]({result['href']})\n"
351
+ f"<a href=\"{result['href']}\" target=\"_blank\">{idx+1}.&nbsp;{result['title']}</a>"
352
  )
353
  reference_results = add_source_numbers(reference_results)
354
+ # display_append = "<ol>\n\n" + "".join(display_append) + "</ol>"
355
+ display_append = '<div class = "source-a">' + "".join(display_append) + '</div>'
356
  real_inputs = (
357
  replace_today(WEBSEARCH_PTOMPT_TEMPLATE)
358
  .replace("{query}", real_inputs)
modules/utils.py CHANGED
@@ -217,7 +217,10 @@ def convert_bot_before_marked(chat_message):
217
  non_code_parts = code_block_pattern.split(chat_message)[::2]
218
  result = []
219
 
220
- raw = f'<div class="raw-message hideM">{escape_markdown(chat_message)}</div>'
 
 
 
221
  for non_code, code in zip(non_code_parts, code_blocks + [""]):
222
  if non_code.strip():
223
  result.append(non_code)
 
217
  non_code_parts = code_block_pattern.split(chat_message)[::2]
218
  result = []
219
 
220
+ hr_pattern = r'\n\n<hr class="append-display no-in-raw" />(.*?)'
221
+ hr_match = re.search(hr_pattern, chat_message, re.DOTALL)
222
+ clip_hr = chat_message[:hr_match.start()] if hr_match else chat_message
223
+ raw = f'<div class="raw-message hideM">{escape_markdown(clip_hr)}</div>'
224
  for non_code, code in zip(non_code_parts, code_blocks + [""]):
225
  if non_code.strip():
226
  result.append(non_code)