Changed options type

17e00587634ed9d011226f336e43639d0b18c449

bmen25124 <bmen25124@gmail.com>

2 files changed, +15 -12Showing whitespace changes
public/scripts/custom-request.js+4 -4
@@ -149,7 +149,7 @@ export class TextCompletionService {
149149
150 if (!response.ok) {150 if (!response.ok) {
151 const text = await response.text();151 const text = await response.text();
152 tryParseStreamingError(response, text, true);152 tryParseStreamingError(response, text, { quiet: true });
153153
154 throw new Error(`Got response status ${response.status}`);154 throw new Error(`Got response status ${response.status}`);
155 }155 }
@@ -166,7 +166,7 @@ export class TextCompletionService {
166 if (done) return;166 if (done) return;
167 if (value.data === '[DONE]') return;167 if (value.data === '[DONE]') return;
168168
169 tryParseStreamingError(response, value.data, true);169 tryParseStreamingError(response, value.data, { quiet: true });
170170
171 let data = JSON.parse(value.data);171 let data = JSON.parse(value.data);
172172
@@ -389,7 +389,7 @@ export class ChatCompletionService {
389389
390 if (!response.ok) {390 if (!response.ok) {
391 const text = await response.text();391 const text = await response.text();
392 tryParseStreamingError(response, text, true);392 tryParseStreamingError(response, text, { quiet: true });
393393
394 throw new Error(`Got response status ${response.status}`);394 throw new Error(`Got response status ${response.status}`);
395 }395 }
@@ -406,7 +406,7 @@ export class ChatCompletionService {
406 if (done) return;406 if (done) return;
407 const rawData = value.data;407 const rawData = value.data;
408 if (rawData === '[DONE]') return;408 if (rawData === '[DONE]') return;
409 tryParseStreamingError(response, rawData, true);409 tryParseStreamingError(response, rawData, { quiet: true });
410 const parsed = JSON.parse(rawData);410 const parsed = JSON.parse(rawData);
411411
412 const reply = getStreamingReply(parsed, state, {412 const reply = getStreamingReply(parsed, state, {
public/scripts/openai.js+11 -8
@@ -1444,9 +1444,10 @@ export async function prepareOpenAIMessages({
1444 * Handles errors during streaming requests.1444 * Handles errors during streaming requests.
1445 * @param {Response} response1445 * @param {Response} response
1446 * @param {string} decoded - response text or decoded stream data1446 * @param {string} decoded - response text or decoded stream data
1447 * @param {boolean?} [quiet=false]1447 * @param {object} [options]
1448 * @param {boolean?} [options.quiet=false] Suppress toast messages
1448 */1449 */
1449export function tryParseStreamingError(response, decoded, quiet = false) {1450export function tryParseStreamingError(response, decoded, { quiet = false } = {}) {
1450 try {1451 try {
1451 const data = JSON.parse(decoded);1452 const data = JSON.parse(decoded);
14521453
@@ -1454,8 +1455,8 @@ export function tryParseStreamingError(response, decoded, quiet = false) {
1454 return;1455 return;
1455 }1456 }
14561457
1457 checkQuotaError(data, quiet);1458 checkQuotaError(data, { quiet });
1458 checkModerationError(data, quiet);1459 checkModerationError(data, { quiet });
14591460
1460 // these do not throw correctly (equiv to Error("[object Object]"))1461 // these do not throw correctly (equiv to Error("[object Object]"))
1461 // if trying to fix "[object Object]" displayed to users, start here1462 // 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 * Checks if the response contains a quota error and displays a popup if it does.1480 * Checks if the response contains a quota error and displays a popup if it does.
1480 * @param data1481 * @param data
1481 * @param {boolean?} [quiet=false]1482 * @param {object} [options]
1483 * @param {boolean?} [options.quiet=false] Suppress toast messages
1482 * @returns {void}1484 * @returns {void}
1483 * @throws {object} - response JSON1485 * @throws {object} - response JSON
1484 */1486 */
1485function checkQuotaError(data, quiet = false) {1487function checkQuotaError(data, { quiet = false } = {}) {
1486 if (!data) {1488 if (!data) {
1487 return;1489 return;
1488 }1490 }
@@ -1498,9 +1500,10 @@ function checkQuotaError(data, quiet = false) {
14981500
1499/**1501/**
1500 * @param {any} data1502 * @param {any} data
1501 * @param {boolean?} [quiet=false]1503 * @param {object} [options]
1504 * @param {boolean?} [options.quiet=false] Suppress toast messages
1502 */1505 */
1503function checkModerationError(data, quiet = false) {1506function checkModerationError(data, { quiet = false } = {}) {
1504 const moderationError = data?.error?.message?.includes('requires moderation');1507 const moderationError = data?.error?.message?.includes('requires moderation');
1505 if (moderationError && !quiet) {1508 if (moderationError && !quiet) {
1506 const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;1509 const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;