mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Linting and commenting
Linting and commenting Linting and commenting Linting and commenting Linting and commenting
This commit is contained in:
@ -1312,6 +1312,11 @@ export async function prepareOpenAIMessages({
|
||||
return [chat, promptManager.tokenHandler.counts];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles errors during streaming requests.
|
||||
* @param {Response} response
|
||||
* @param {string} decoded - response text or decoded stream data
|
||||
*/
|
||||
function tryParseStreamingError(response, decoded) {
|
||||
try {
|
||||
const data = JSON.parse(decoded);
|
||||
@ -1320,9 +1325,12 @@ function tryParseStreamingError(response, decoded) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkQuotaError(data);
|
||||
void checkQuotaError(data);
|
||||
checkModerationError(data);
|
||||
|
||||
// these do not throw correctly (equiv to Error("[object Object]"))
|
||||
// if trying to fix "[object Object]" displayed to users, start here
|
||||
|
||||
if (data.error) {
|
||||
toastr.error(data.error.message || response.statusText, 'Chat Completion API');
|
||||
throw new Error(data);
|
||||
@ -1338,6 +1346,12 @@ function tryParseStreamingError(response, decoded) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the response contains a quota error and displays a popup if it does.
|
||||
* @param data
|
||||
* @returns {Promise<void>}
|
||||
* @throws {object} - response JSON
|
||||
*/
|
||||
async function checkQuotaError(data) {
|
||||
const errorText = await renderTemplateAsync('quotaError');
|
||||
|
||||
@ -1347,6 +1361,9 @@ async function checkQuotaError(data) {
|
||||
|
||||
if (data.quota_error) {
|
||||
callPopup(errorText, 'text');
|
||||
|
||||
// this does not throw correctly (equiv to Error("[object Object]"))
|
||||
// if trying to fix "[object Object]" displayed to users, start here
|
||||
throw new Error(data);
|
||||
}
|
||||
}
|
||||
@ -1765,6 +1782,15 @@ async function sendAltScaleRequest(messages, logit_bias, signal, type) {
|
||||
return data.output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a chat completion request to backend
|
||||
* @param {string} type (impersonate, quiet, continue, etc)
|
||||
* @param {Array} messages
|
||||
* @param {AbortSignal?} signal
|
||||
* @returns {Promise<unknown>}
|
||||
* @throws {Error}
|
||||
*/
|
||||
|
||||
async function sendOpenAIRequest(type, messages, signal) {
|
||||
// Provide default abort signal
|
||||
if (!signal) {
|
||||
|
Reference in New Issue
Block a user