Changed options type
| @@ -149,7 +149,7 @@ export class TextCompletionService { | ||
| 149 | 149 | |
| 150 | 150 | if (!response.ok) { |
| 151 | 151 | const text = await response.text(); |
| 152 | 152 | tryParseStreamingError(response, text, { quiet: true }); |
| 153 | 153 | |
| 154 | 154 | throw new Error(`Got response status ${response.status}`); |
| 155 | 155 | } |
| @@ -166,7 +166,7 @@ export class TextCompletionService { | ||
| 166 | 166 | if (done) return; |
| 167 | 167 | if (value.data === '[DONE]') return; |
| 168 | 168 | |
| 169 | 169 | tryParseStreamingError(response, value.data, { quiet: true }); |
| 170 | 170 | |
| 171 | 171 | let data = JSON.parse(value.data); |
| 172 | 172 | |
| @@ -389,7 +389,7 @@ export class ChatCompletionService { | ||
| 389 | 389 | |
| 390 | 390 | if (!response.ok) { |
| 391 | 391 | const text = await response.text(); |
| 392 | 392 | tryParseStreamingError(response, text, { quiet: true }); |
| 393 | 393 | |
| 394 | 394 | throw new Error(`Got response status ${response.status}`); |
| 395 | 395 | } |
| @@ -406,7 +406,7 @@ export class ChatCompletionService { | ||
| 406 | 406 | if (done) return; |
| 407 | 407 | const rawData = value.data; |
| 408 | 408 | if (rawData === '[DONE]') return; |
| 409 | 409 | tryParseStreamingError(response, rawData, { quiet: true }); |
| 410 | 410 | const parsed = JSON.parse(rawData); |
| 411 | 411 | |
| 412 | 412 | const reply = getStreamingReply(parsed, state, { |
| @@ -1444,9 +1444,10 @@ export async function prepareOpenAIMessages({ | ||
| 1444 | 1444 | * Handles errors during streaming requests. |
| 1445 | 1445 | * @param {Response} response |
| 1446 | 1446 | * @param {string} decoded - response text or decoded stream data |
| 1447 | 1447 | * @param {boolean?object} [quiet=falseoptions] |
| 1448 | + * @param {boolean?} [options.quiet=false] Suppress toast messages | |
| 1448 | 1449 | */ |
| 1449 | 1450 | export function tryParseStreamingError(response, decoded, { quiet = false } = {}) { |
| 1450 | 1451 | try { |
| 1451 | 1452 | const data = JSON.parse(decoded); |
| 1452 | 1453 | |
| @@ -1454,8 +1455,8 @@ export function tryParseStreamingError(response, decoded, quiet = false) { | ||
| 1454 | 1455 | return; |
| 1455 | 1456 | } |
| 1456 | 1457 | |
| 1457 | 1458 | checkQuotaError(data, { quiet }); |
| 1458 | 1459 | checkModerationError(data, { quiet }); |
| 1459 | 1460 | |
| 1460 | 1461 | // these do not throw correctly (equiv to Error("[object Object]")) |
| 1461 | 1462 | // if trying to fix "[object Object]" displayed to users, start here |
| @@ -1478,11 +1479,12 @@ export function tryParseStreamingError(response, decoded, quiet = false) { | ||
| 1478 | 1479 | /** |
| 1479 | 1480 | * Checks if the response contains a quota error and displays a popup if it does. |
| 1480 | 1481 | * @param data |
| 1481 | 1482 | * @param {boolean?object} [quiet=falseoptions] |
| 1483 | + * @param {boolean?} [options.quiet=false] Suppress toast messages | |
| 1482 | 1484 | * @returns {void} |
| 1483 | 1485 | * @throws {object} - response JSON |
| 1484 | 1486 | */ |
| 1485 | 1487 | function checkQuotaError(data, { quiet = false } = {}) { |
| 1486 | 1488 | if (!data) { |
| 1487 | 1489 | return; |
| 1488 | 1490 | } |
| @@ -1498,9 +1500,10 @@ function checkQuotaError(data, quiet = false) { | ||
| 1498 | 1500 | |
| 1499 | 1501 | /** |
| 1500 | 1502 | * @param {any} data |
| 1501 | 1503 | * @param {boolean?object} [quiet=falseoptions] |
| 1504 | + * @param {boolean?} [options.quiet=false] Suppress toast messages | |
| 1502 | 1505 | */ |
| 1503 | 1506 | function checkModerationError(data, { quiet = false } = {}) { |
| 1504 | 1507 | const moderationError = data?.error?.message?.includes('requires moderation'); |
| 1505 | 1508 | if (moderationError && !quiet) { |
| 1506 | 1509 | const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`; |