coyotte508 HF staff commited on
Commit
9b20b88
1 Parent(s): c922d39

🩹 Do not flash endoftext (#89)

Browse files
src/lib/components/chat/ChatMessage.svelte CHANGED
@@ -8,7 +8,11 @@
8
  import IconLoading from "../icons/IconLoading.svelte";
9
 
10
  function sanitizeMd(md: string) {
11
- return md.replaceAll("&", "&amp;").replaceAll("<", "&lt;");
 
 
 
 
12
  }
13
  function unsanitizeMd(md: string) {
14
  return md.replaceAll("&lt;", "<").replaceAll("&amp;", "&");
 
8
  import IconLoading from "../icons/IconLoading.svelte";
9
 
10
  function sanitizeMd(md: string) {
11
+ return md
12
+ .replaceAll(/^(<\|startoftext\|>|<\|startoftext\|$|<\|startoftext$|<\|$|<$)/g, "")
13
+ .replaceAll(/(<\|endoftext\|>|<\|endoftext\|$|<\|endoftext$)/g, "")
14
+ .replaceAll("&", "&amp;")
15
+ .replaceAll("<", "&lt;");
16
  }
17
  function unsanitizeMd(md: string) {
18
  return md.replaceAll("&lt;", "<").replaceAll("&amp;", "&");
src/routes/conversation/[id]/+page.svelte CHANGED
@@ -7,9 +7,7 @@
7
  import { textGenerationStream } from "@huggingface/inference";
8
  import { invalidate } from "$app/navigation";
9
  import { base } from "$app/paths";
10
- import { trimSuffix } from "$lib/utils/trimSuffix";
11
- import { PUBLIC_SEP_TOKEN, PUBLIC_MAX_INPUT_TOKENS } from "$env/static/public";
12
- import { trimPrefix } from "$lib/utils/trimPrefix";
13
  import { shareConversation } from "$lib/shareConversation";
14
  import { UrlDependency } from "$lib/types/UrlDependency";
15
 
@@ -62,10 +60,7 @@
62
  if (data.generated_text) {
63
  const lastMessage = messages.at(-1);
64
  if (lastMessage) {
65
- lastMessage.content = trimPrefix(
66
- trimSuffix(data.generated_text, PUBLIC_SEP_TOKEN),
67
- "<|startoftext|>"
68
- );
69
  messages = [...messages];
70
  }
71
  break;
 
7
  import { textGenerationStream } from "@huggingface/inference";
8
  import { invalidate } from "$app/navigation";
9
  import { base } from "$app/paths";
10
+ import { PUBLIC_MAX_INPUT_TOKENS } from "$env/static/public";
 
 
11
  import { shareConversation } from "$lib/shareConversation";
12
  import { UrlDependency } from "$lib/types/UrlDependency";
13
 
 
60
  if (data.generated_text) {
61
  const lastMessage = messages.at(-1);
62
  if (lastMessage) {
63
+ lastMessage.content = data.generated_text;
 
 
 
64
  messages = [...messages];
65
  }
66
  break;