mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Changed options type
This commit is contained in:
@ -149,7 +149,7 @@ export class TextCompletionService {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
tryParseStreamingError(response, text, true);
|
tryParseStreamingError(response, text, { quiet: true });
|
||||||
|
|
||||||
throw new Error(`Got response status ${response.status}`);
|
throw new Error(`Got response status ${response.status}`);
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ export class TextCompletionService {
|
|||||||
if (done) return;
|
if (done) return;
|
||||||
if (value.data === '[DONE]') return;
|
if (value.data === '[DONE]') return;
|
||||||
|
|
||||||
tryParseStreamingError(response, value.data, true);
|
tryParseStreamingError(response, value.data, { quiet: true });
|
||||||
|
|
||||||
let data = JSON.parse(value.data);
|
let data = JSON.parse(value.data);
|
||||||
|
|
||||||
@ -389,7 +389,7 @@ export class ChatCompletionService {
|
|||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
tryParseStreamingError(response, text, true);
|
tryParseStreamingError(response, text, { quiet: true });
|
||||||
|
|
||||||
throw new Error(`Got response status ${response.status}`);
|
throw new Error(`Got response status ${response.status}`);
|
||||||
}
|
}
|
||||||
@ -406,7 +406,7 @@ export class ChatCompletionService {
|
|||||||
if (done) return;
|
if (done) return;
|
||||||
const rawData = value.data;
|
const rawData = value.data;
|
||||||
if (rawData === '[DONE]') return;
|
if (rawData === '[DONE]') return;
|
||||||
tryParseStreamingError(response, rawData, true);
|
tryParseStreamingError(response, rawData, { quiet: true });
|
||||||
const parsed = JSON.parse(rawData);
|
const parsed = JSON.parse(rawData);
|
||||||
|
|
||||||
const reply = getStreamingReply(parsed, state, {
|
const reply = getStreamingReply(parsed, state, {
|
||||||
|
@ -1444,9 +1444,10 @@ export async function prepareOpenAIMessages({
|
|||||||
* Handles errors during streaming requests.
|
* Handles errors during streaming requests.
|
||||||
* @param {Response} response
|
* @param {Response} response
|
||||||
* @param {string} decoded - response text or decoded stream data
|
* @param {string} decoded - response text or decoded stream data
|
||||||
* @param {boolean?} [quiet=false]
|
* @param {object} [options]
|
||||||
|
* @param {boolean?} [options.quiet=false] Suppress toast messages
|
||||||
*/
|
*/
|
||||||
export function tryParseStreamingError(response, decoded, quiet = false) {
|
export function tryParseStreamingError(response, decoded, { quiet = false } = {}) {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(decoded);
|
const data = JSON.parse(decoded);
|
||||||
|
|
||||||
@ -1454,8 +1455,8 @@ export function tryParseStreamingError(response, decoded, quiet = false) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkQuotaError(data, quiet);
|
checkQuotaError(data, { quiet });
|
||||||
checkModerationError(data, quiet);
|
checkModerationError(data, { quiet });
|
||||||
|
|
||||||
// these do not throw correctly (equiv to Error("[object Object]"))
|
// these do not throw correctly (equiv to Error("[object Object]"))
|
||||||
// if trying to fix "[object Object]" displayed to users, start here
|
// if trying to fix "[object Object]" displayed to users, start here
|
||||||
@ -1478,11 +1479,12 @@ export function tryParseStreamingError(response, decoded, quiet = false) {
|
|||||||
/**
|
/**
|
||||||
* Checks if the response contains a quota error and displays a popup if it does.
|
* Checks if the response contains a quota error and displays a popup if it does.
|
||||||
* @param data
|
* @param data
|
||||||
* @param {boolean?} [quiet=false]
|
* @param {object} [options]
|
||||||
|
* @param {boolean?} [options.quiet=false] Suppress toast messages
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
* @throws {object} - response JSON
|
* @throws {object} - response JSON
|
||||||
*/
|
*/
|
||||||
function checkQuotaError(data, quiet = false) {
|
function checkQuotaError(data, { quiet = false } = {}) {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1498,9 +1500,10 @@ function checkQuotaError(data, quiet = false) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {any} data
|
* @param {any} data
|
||||||
* @param {boolean?} [quiet=false]
|
* @param {object} [options]
|
||||||
|
* @param {boolean?} [options.quiet=false] Suppress toast messages
|
||||||
*/
|
*/
|
||||||
function checkModerationError(data, quiet = false) {
|
function checkModerationError(data, { quiet = false } = {}) {
|
||||||
const moderationError = data?.error?.message?.includes('requires moderation');
|
const moderationError = data?.error?.message?.includes('requires moderation');
|
||||||
if (moderationError && !quiet) {
|
if (moderationError && !quiet) {
|
||||||
const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;
|
const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;
|
||||||
|
Reference in New Issue
Block a user