Spaces:
Build error
Build error
andreasmadsen
commited on
Commit
•
d2a650e
1
Parent(s):
54e8a52
trim and remove stop-suffixes from summary (#369)
Browse filesThe chat generation removes parameters.stop and <|endoftext|>
from the generated text. And additionally trims trailing whitespace.
This PR copies that behavior to the summarize functionality, when the
summary is produced by a the chat model.
src/lib/server/generateFromDefaultEndpoint.ts
CHANGED
@@ -37,7 +37,16 @@ export async function generateFromDefaultEndpoint(
|
|
37 |
}
|
38 |
);
|
39 |
|
40 |
-
generated_text = trimSuffix(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
return generated_text;
|
43 |
}
|
|
|
37 |
}
|
38 |
);
|
39 |
|
40 |
+
generated_text = trimSuffix(
|
41 |
+
trimPrefix(generated_text, "<|startoftext|>"),
|
42 |
+
PUBLIC_SEP_TOKEN
|
43 |
+
).trimEnd();
|
44 |
+
|
45 |
+
for (const stop of [...(newParameters?.stop ?? []), "<|endoftext|>"]) {
|
46 |
+
if (generated_text.endsWith(stop)) {
|
47 |
+
generated_text = generated_text.slice(0, -stop.length).trimEnd();
|
48 |
+
}
|
49 |
+
}
|
50 |
|
51 |
return generated_text;
|
52 |
}
|