fix: Error occurred: Unexpected token "d", "data: ..." is not a valid JSON (#1332)

This commit is contained in:
Louis 2024-01-04 18:22:07 +07:00 committed by GitHub
parent 97c0fee0b2
commit c07b418ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -30,7 +30,10 @@ export function requestInference(
signal: controller?.signal,
})
.then(async (response) => {
if (model.parameters.stream) {
if (model.parameters.stream === false) {
const data = await response.json();
subscriber.next(data.choices[0]?.message?.content ?? "");
} else {
const stream = response.body;
const decoder = new TextDecoder("utf-8");
const reader = stream?.getReader();
@ -54,9 +57,6 @@ export function requestInference(
}
}
}
} else {
const data = await response.json();
subscriber.next(data.choices[0]?.message?.content ?? "");
}
subscriber.complete();
})

View File

@ -46,7 +46,10 @@ export function requestInference(
subscriber.complete();
return;
}
if (model.parameters.stream) {
if (model.parameters.stream === false) {
const data = await response.json();
subscriber.next(data.choices[0]?.message?.content ?? "");
} else {
const stream = response.body;
const decoder = new TextDecoder("utf-8");
const reader = stream?.getReader();
@ -70,9 +73,6 @@ export function requestInference(
}
}
}
} else {
const data = await response.json();
subscriber.next(data.choices[0]?.message?.content ?? "");
}
subscriber.complete();
})