Changed options type

17e00587634ed9d011226f336e43639d0b18c449

bmen25124 <bmen25124@gmail.com>

2 files changed, +15 -12Ignore whitespace
public/scripts/custom-request.js+4 -4
@@ -149,7 +149,7 @@ export class TextCompletionService {
149149
150150 if (!response.ok) {
151151 const text = await response.text();
152152 tryParseStreamingError(response, text, { quiet: true });
153153
154154 throw new Error(`Got response status ${response.status}`);
155155 }
@@ -166,7 +166,7 @@ export class TextCompletionService {
166166 if (done) return;
167167 if (value.data === '[DONE]') return;
168168
169169 tryParseStreamingError(response, value.data, { quiet: true });
170170
171171 let data = JSON.parse(value.data);
172172
@@ -389,7 +389,7 @@ export class ChatCompletionService {
389389
390390 if (!response.ok) {
391391 const text = await response.text();
392392 tryParseStreamingError(response, text, { quiet: true });
393393
394394 throw new Error(`Got response status ${response.status}`);
395395 }
@@ -406,7 +406,7 @@ export class ChatCompletionService {
406406 if (done) return;
407407 const rawData = value.data;
408408 if (rawData === '[DONE]') return;
409409 tryParseStreamingError(response, rawData, { quiet: true });
410410 const parsed = JSON.parse(rawData);
411411
412412 const reply = getStreamingReply(parsed, state, {
public/scripts/openai.js+11 -8
@@ -1444,9 +1444,10 @@ export async function prepareOpenAIMessages({
14441444 * Handles errors during streaming requests.
14451445 * @param {Response} response
14461446 * @param {string} decoded - response text or decoded stream data
14471447 * @param {boolean?object} [quiet=falseoptions]
1448+ * @param {boolean?} [options.quiet=false] Suppress toast messages
14481449 */
14491450export function tryParseStreamingError(response, decoded, { quiet = false } = {}) {
14501451 try {
14511452 const data = JSON.parse(decoded);
14521453
@@ -1454,8 +1455,8 @@ export function tryParseStreamingError(response, decoded, quiet = false) {
14541455 return;
14551456 }
14561457
14571458 checkQuotaError(data, { quiet });
14581459 checkModerationError(data, { quiet });
14591460
14601461 // these do not throw correctly (equiv to Error("[object Object]"))
14611462 // if trying to fix "[object Object]" displayed to users, start here
@@ -1478,11 +1479,12 @@ export function tryParseStreamingError(response, decoded, quiet = false) {
14781479/**
14791480 * Checks if the response contains a quota error and displays a popup if it does.
14801481 * @param data
14811482 * @param {boolean?object} [quiet=falseoptions]
1483+ * @param {boolean?} [options.quiet=false] Suppress toast messages
14821484 * @returns {void}
14831485 * @throws {object} - response JSON
14841486 */
14851487function checkQuotaError(data, { quiet = false } = {}) {
14861488 if (!data) {
14871489 return;
14881490 }
@@ -1498,9 +1500,10 @@ function checkQuotaError(data, quiet = false) {
14981500
14991501/**
15001502 * @param {any} data
15011503 * @param {boolean?object} [quiet=falseoptions]
1504+ * @param {boolean?} [options.quiet=false] Suppress toast messages
15021505 */
15031506function checkModerationError(data, { quiet = false } = {}) {
15041507 const moderationError = data?.error?.message?.includes('requires moderation');
15051508 if (moderationError && !quiet) {
15061509 const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;