coyotte508 HF staff commited on
Commit
1eb0e2e
β€’
1 Parent(s): 5741be4

πŸ› Make it work with default model

Browse files

Truncate was too high (1024 vs 1000)

.env CHANGED
@@ -5,7 +5,8 @@ MONGODB_URL=#your mongodb URL here
5
  MONGODB_DB_NAME=chat-ui
6
  COOKIE_NAME=hf-chat
7
 
8
- PUBLIC_MAX_INPUT_TOKENS=1024
 
9
  PUBLIC_ORIGIN=#https://hf.co
10
  PUBLIC_MODEL_NAME=OpenAssistant/oasst-sft-6-llama-30b # public facing link
11
  PUBLIC_MODEL_ID=OpenAssistant/oasst-sft-6-llama-30b-xor # used to link to model page
 
5
  MONGODB_DB_NAME=chat-ui
6
  COOKIE_NAME=hf-chat
7
 
8
+ # Increase depending on the model
9
+ PUBLIC_MAX_INPUT_TOKENS=1000
10
  PUBLIC_ORIGIN=#https://hf.co
11
  PUBLIC_MODEL_NAME=OpenAssistant/oasst-sft-6-llama-30b # public facing link
12
  PUBLIC_MODEL_ID=OpenAssistant/oasst-sft-6-llama-30b-xor # used to link to model page
src/lib/components/chat/ChatMessage.svelte CHANGED
@@ -7,12 +7,14 @@
7
  import CodeBlock from "../CodeBlock.svelte";
8
  import IconLoading from "../icons/IconLoading.svelte";
9
  import CarbonRotate360 from "~icons/carbon/rotate-360";
 
10
 
11
  function sanitizeMd(md: string) {
12
  return md
13
  .replace(/<\|[a-z]*$/, "")
14
  .replace(/<\|[a-z]+\|$/, "")
15
  .replace(/<$/, "")
 
16
  .replaceAll(/<\|[a-z]+\|>/g, " ")
17
  .replaceAll(/<br\s?\/?>/gi, "\n")
18
  .trim()
 
7
  import CodeBlock from "../CodeBlock.svelte";
8
  import IconLoading from "../icons/IconLoading.svelte";
9
  import CarbonRotate360 from "~icons/carbon/rotate-360";
10
+ import { PUBLIC_SEP_TOKEN } from "$env/static/public";
11
 
12
  function sanitizeMd(md: string) {
13
  return md
14
  .replace(/<\|[a-z]*$/, "")
15
  .replace(/<\|[a-z]+\|$/, "")
16
  .replace(/<$/, "")
17
+ .replaceAll(PUBLIC_SEP_TOKEN, " ")
18
  .replaceAll(/<\|[a-z]+\|>/g, " ")
19
  .replaceAll(/<br\s?\/?>/gi, "\n")
20
  .trim()
src/routes/conversation/[id]/summarize/+server.ts CHANGED
@@ -2,6 +2,8 @@ import { PUBLIC_MAX_INPUT_TOKENS, PUBLIC_SEP_TOKEN } from "$env/static/public";
2
  import { buildPrompt } from "$lib/buildPrompt";
3
  import { collections } from "$lib/server/database.js";
4
  import { modelEndpoint } from "$lib/server/modelEndpoint.js";
 
 
5
  import { textGeneration } from "@huggingface/inference";
6
  import { error } from "@sveltejs/kit";
7
  import { ObjectId } from "mongodb";
@@ -39,7 +41,7 @@ export async function POST({ params, locals, fetch }) {
39
  };
40
 
41
  const endpoint = modelEndpoint();
42
- const { generated_text } = await textGeneration(
43
  {
44
  model: endpoint.endpoint,
45
  inputs: prompt,
@@ -54,6 +56,8 @@ export async function POST({ params, locals, fetch }) {
54
  }
55
  );
56
 
 
 
57
  if (generated_text) {
58
  await collections.conversations.updateOne(
59
  {
 
2
  import { buildPrompt } from "$lib/buildPrompt";
3
  import { collections } from "$lib/server/database.js";
4
  import { modelEndpoint } from "$lib/server/modelEndpoint.js";
5
+ import { trimPrefix } from "$lib/utils/trimPrefix.js";
6
+ import { trimSuffix } from "$lib/utils/trimSuffix.js";
7
  import { textGeneration } from "@huggingface/inference";
8
  import { error } from "@sveltejs/kit";
9
  import { ObjectId } from "mongodb";
 
41
  };
42
 
43
  const endpoint = modelEndpoint();
44
+ let { generated_text } = await textGeneration(
45
  {
46
  model: endpoint.endpoint,
47
  inputs: prompt,
 
56
  }
57
  );
58
 
59
+ generated_text = trimSuffix(trimPrefix(generated_text, "<|startoftext|>"), PUBLIC_SEP_TOKEN);
60
+
61
  if (generated_text) {
62
  await collections.conversations.updateOne(
63
  {