mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
fix tryParseStreamingError
response.statusText was never available
This commit is contained in:
@@ -539,9 +539,9 @@ function getSystemPrompt(systemPrompt, nsfw_toggle_prompt, enhance_definitions_p
|
|||||||
return whole_prompt;
|
return whole_prompt;
|
||||||
}
|
}
|
||||||
|
|
||||||
function tryParseStreamingError(str) {
|
function tryParseStreamingError(response, decoded) {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(str);
|
const data = JSON.parse(decoded);
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
@@ -550,7 +550,7 @@ function tryParseStreamingError(str) {
|
|||||||
checkQuotaError(data);
|
checkQuotaError(data);
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
toastr.error(response.statusText, 'API returned an error');
|
toastr.error(data.error.message || response.statusText, 'API returned an error');
|
||||||
throw new Error(data);
|
throw new Error(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -784,26 +784,26 @@ async function sendOpenAIRequest(type, openai_msgs_tosend, signal) {
|
|||||||
let messageBuffer = "";
|
let messageBuffer = "";
|
||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
let response = decoder.decode(value);
|
let decoded = decoder.decode(value);
|
||||||
|
|
||||||
// Claude's streaming SSE messages are separated by \r
|
// Claude's streaming SSE messages are separated by \r
|
||||||
if (oai_settings.chat_completion_source == chat_completion_sources.CLAUDE) {
|
if (oai_settings.chat_completion_source == chat_completion_sources.CLAUDE) {
|
||||||
response = response.replace(/\r/g, "");
|
decoded = decoded.replace(/\r/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
tryParseStreamingError(response);
|
tryParseStreamingError(response, decoded);
|
||||||
|
|
||||||
let eventList = [];
|
let eventList = [];
|
||||||
|
|
||||||
// ReadableStream's buffer is not guaranteed to contain full SSE messages as they arrive in chunks
|
// ReadableStream's buffer is not guaranteed to contain full SSE messages as they arrive in chunks
|
||||||
// We need to buffer chunks until we have one or more full messages (separated by double newlines)
|
// We need to buffer chunks until we have one or more full messages (separated by double newlines)
|
||||||
if (!oai_settings.legacy_streaming) {
|
if (!oai_settings.legacy_streaming) {
|
||||||
messageBuffer += response;
|
messageBuffer += decoded;
|
||||||
eventList = messageBuffer.split("\n\n");
|
eventList = messageBuffer.split("\n\n");
|
||||||
// Last element will be an empty string or a leftover partial message
|
// Last element will be an empty string or a leftover partial message
|
||||||
messageBuffer = eventList.pop();
|
messageBuffer = eventList.pop();
|
||||||
} else {
|
} else {
|
||||||
eventList = response.split("\n");
|
eventList = decoded.split("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let event of eventList) {
|
for (let event of eventList) {
|
||||||
@@ -837,7 +837,7 @@ async function sendOpenAIRequest(type, openai_msgs_tosend, signal) {
|
|||||||
checkQuotaError(data);
|
checkQuotaError(data);
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
toastr.error(response.statusText, 'API returned an error');
|
toastr.error(data.error.message || response.statusText, 'API returned an error');
|
||||||
throw new Error(data);
|
throw new Error(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user