mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Better naming
This commit is contained in:
@ -64,7 +64,6 @@ import EventSourceStream from './sse-stream.js';
|
|||||||
* @property {Object} state - Generated state
|
* @property {Object} state - Generated state
|
||||||
* @property {string?} [state.reasoning] - Generated reasoning
|
* @property {string?} [state.reasoning] - Generated reasoning
|
||||||
* @property {string?} [state.image] - Generated image
|
* @property {string?} [state.image] - Generated image
|
||||||
* @returns {StreamResponse}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// #endregion
|
// #endregion
|
||||||
@ -412,7 +411,7 @@ export class ChatCompletionService {
|
|||||||
|
|
||||||
const reply = getStreamingReply(parsed, state, {
|
const reply = getStreamingReply(parsed, state, {
|
||||||
chatCompletionSource: data.chat_completion_source,
|
chatCompletionSource: data.chat_completion_source,
|
||||||
ignoreShowThoughts: true,
|
overrideShowThoughts: true,
|
||||||
});
|
});
|
||||||
if (Array.isArray(parsed?.choices) && parsed?.choices?.[0]?.index > 0) {
|
if (Array.isArray(parsed?.choices) && parsed?.choices?.[0]?.index > 0) {
|
||||||
const swipeIndex = parsed.choices[0].index - 1;
|
const swipeIndex = parsed.choices[0].index - 1;
|
||||||
|
@ -1444,9 +1444,9 @@ 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?} [supressToastr=false]
|
* @param {boolean?} [quiet=false]
|
||||||
*/
|
*/
|
||||||
export function tryParseStreamingError(response, decoded, supressToastr = false) {
|
export function tryParseStreamingError(response, decoded, quiet = false) {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(decoded);
|
const data = JSON.parse(decoded);
|
||||||
|
|
||||||
@ -1454,19 +1454,19 @@ export function tryParseStreamingError(response, decoded, supressToastr = false)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
checkQuotaError(data, supressToastr);
|
checkQuotaError(data, quiet);
|
||||||
checkModerationError(data, supressToastr);
|
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
|
||||||
|
|
||||||
if (data.error) {
|
if (data.error) {
|
||||||
!supressToastr && toastr.error(data.error.message || response.statusText, 'Chat Completion API');
|
!quiet && toastr.error(data.error.message || response.statusText, 'Chat Completion API');
|
||||||
throw new Error(data);
|
throw new Error(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.message) {
|
if (data.message) {
|
||||||
!supressToastr && toastr.error(data.message, 'Chat Completion API');
|
!quiet && toastr.error(data.message, 'Chat Completion API');
|
||||||
throw new Error(data);
|
throw new Error(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1478,17 +1478,17 @@ export function tryParseStreamingError(response, decoded, supressToastr = 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?} [supressToastr=false]
|
* @param {boolean?} [quiet=false]
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
* @throws {object} - response JSON
|
* @throws {object} - response JSON
|
||||||
*/
|
*/
|
||||||
function checkQuotaError(data, supressToastr = false) {
|
function checkQuotaError(data, quiet = false) {
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.quota_error) {
|
if (data.quota_error) {
|
||||||
!supressToastr && renderTemplateAsync('quotaError').then((html) => Popup.show.text('Quota Error', html));
|
!quiet && renderTemplateAsync('quotaError').then((html) => Popup.show.text('Quota Error', html));
|
||||||
|
|
||||||
// this does not throw correctly (equiv to Error("[object Object]"))
|
// this does 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
|
||||||
@ -1498,11 +1498,11 @@ function checkQuotaError(data, supressToastr = false) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {any} data
|
* @param {any} data
|
||||||
* @param {boolean?} [supressToastr=false]
|
* @param {boolean?} [quiet=false]
|
||||||
*/
|
*/
|
||||||
function checkModerationError(data, supressToastr = false) {
|
function checkModerationError(data, quiet = false) {
|
||||||
const moderationError = data?.error?.message?.includes('requires moderation');
|
const moderationError = data?.error?.message?.includes('requires moderation');
|
||||||
if (moderationError && !supressToastr) {
|
if (moderationError && !quiet) {
|
||||||
const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;
|
const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;
|
||||||
const flaggedText = data?.error?.metadata?.flagged_input ?? '(N/A)';
|
const flaggedText = data?.error?.metadata?.flagged_input ?? '(N/A)';
|
||||||
toastr.info(flaggedText, moderationReason, { timeOut: 10000 });
|
toastr.info(flaggedText, moderationReason, { timeOut: 10000 });
|
||||||
@ -2261,14 +2261,14 @@ async function sendOpenAIRequest(type, messages, signal) {
|
|||||||
* Extracts the reply from the response data from a chat completions-like source
|
* Extracts the reply from the response data from a chat completions-like source
|
||||||
* @param {object} data Response data from the chat completions-like source
|
* @param {object} data Response data from the chat completions-like source
|
||||||
* @param {object} state Additional state to keep track of
|
* @param {object} state Additional state to keep track of
|
||||||
* @param {object} options Additional options
|
* @param {object} [options] Additional options
|
||||||
* @param {string?} [options.chatCompletionSource] Chat completion source
|
* @param {string?} [options.chatCompletionSource] Chat completion source
|
||||||
* @param {boolean?} [options.ignoreShowThoughts] Ignore show thoughts
|
* @param {boolean?} [options.overrideShowThoughts] Override show thoughts
|
||||||
* @returns {string} The reply extracted from the response data
|
* @returns {string} The reply extracted from the response data
|
||||||
*/
|
*/
|
||||||
export function getStreamingReply(data, state, { chatCompletionSource = null, ignoreShowThoughts = false } = {}) {
|
export function getStreamingReply(data, state, { chatCompletionSource = null, overrideShowThoughts } = {}) {
|
||||||
const chat_completion_source = chatCompletionSource ?? oai_settings.chat_completion_source;
|
const chat_completion_source = chatCompletionSource ?? oai_settings.chat_completion_source;
|
||||||
const show_thoughts = ignoreShowThoughts ? true : oai_settings.show_thoughts;
|
const show_thoughts = overrideShowThoughts !== undefined ? overrideShowThoughts : oai_settings.show_thoughts;
|
||||||
|
|
||||||
if (chat_completion_source === chat_completion_sources.CLAUDE) {
|
if (chat_completion_source === chat_completion_sources.CLAUDE) {
|
||||||
if (show_thoughts) {
|
if (show_thoughts) {
|
||||||
|
Reference in New Issue
Block a user