fix JSON.parse for summerize (#445)
Browse files* fix JSON.parse for summerize
When serving with TGI, summerize calls this function and it errors with `SyntaxError: Unexpected token d in JSON at position 0`
This PR fixes the problem and keeps existing behaviour.
* fix types
---------
Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
src/lib/server/generateFromDefaultEndpoint.ts
CHANGED
@@ -87,7 +87,12 @@ export async function generateFromDefaultEndpoint(
|
|
87 |
// Close the reader when done
|
88 |
reader.releaseLock();
|
89 |
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
let generated_text = trimSuffix(
|
93 |
trimPrefix(trimPrefix(results[0].generated_text, "<|startoftext|>"), prompt),
|
|
|
87 |
// Close the reader when done
|
88 |
reader.releaseLock();
|
89 |
|
90 |
+
let results;
|
91 |
+
if (result.startsWith("data:")) {
|
92 |
+
results = [JSON.parse(result.split("data:")?.pop() ?? "")];
|
93 |
+
} else {
|
94 |
+
results = JSON.parse(result);
|
95 |
+
}
|
96 |
|
97 |
let generated_text = trimSuffix(
|
98 |
trimPrefix(trimPrefix(results[0].generated_text, "<|startoftext|>"), prompt),
|