Better naming

76193960537d0c0fa71de205b7e24c7c92ea52f6

bmen25124 <bmen25124@gmail.com>

2 files changed, +17 -18Showing whitespace changes
public/scripts/custom-request.js+1 -2
@@ -64,7 +64,6 @@ import EventSourceStream from './sse-stream.js';
6464 * @property {Object} state - Generated state
6565 * @property {string?} [state.reasoning] - Generated reasoning
6666 * @property {string?} [state.image] - Generated image
67- * @returns {StreamResponse}
6867 */
6968
7069// #endregion
@@ -412,7 +411,7 @@ export class ChatCompletionService {
412411
413412 const reply = getStreamingReply(parsed, state, {
414413 chatCompletionSource: data.chat_completion_source,
415414 ignoreShowThoughtsoverrideShowThoughts: true,
416415 });
417416 if (Array.isArray(parsed?.choices) && parsed?.choices?.[0]?.index > 0) {
418417 const swipeIndex = parsed.choices[0].index - 1;
public/scripts/openai.js+16 -16
@@ -1444,9 +1444,9 @@ 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?} [supressToastrquiet=false]
14481448 */
14491449export function tryParseStreamingError(response, decoded, supressToastrquiet = false) {
14501450 try {
14511451 const data = JSON.parse(decoded);
14521452
@@ -1454,19 +1454,19 @@ export function tryParseStreamingError(response, decoded, supressToastr = false)
14541454 return;
14551455 }
14561456
14571457 checkQuotaError(data, supressToastrquiet);
14581458 checkModerationError(data, supressToastrquiet);
14591459
14601460 // these do not throw correctly (equiv to Error("[object Object]"))
14611461 // if trying to fix "[object Object]" displayed to users, start here
14621462
14631463 if (data.error) {
14641464 !supressToastrquiet && toastr.error(data.error.message || response.statusText, 'Chat Completion API');
14651465 throw new Error(data);
14661466 }
14671467
14681468 if (data.message) {
14691469 !supressToastrquiet && toastr.error(data.message, 'Chat Completion API');
14701470 throw new Error(data);
14711471 }
14721472 }
@@ -1478,17 +1478,17 @@ export function tryParseStreamingError(response, decoded, supressToastr = false)
14781478/**
14791479 * Checks if the response contains a quota error and displays a popup if it does.
14801480 * @param data
14811481 * @param {boolean?} [supressToastrquiet=false]
14821482 * @returns {void}
14831483 * @throws {object} - response JSON
14841484 */
14851485function checkQuotaError(data, supressToastrquiet = false) {
14861486 if (!data) {
14871487 return;
14881488 }
14891489
14901490 if (data.quota_error) {
14911491 !supressToastrquiet && renderTemplateAsync('quotaError').then((html) => Popup.show.text('Quota Error', html));
14921492
14931493 // this does not throw correctly (equiv to Error("[object Object]"))
14941494 // if trying to fix "[object Object]" displayed to users, start here
@@ -1498,11 +1498,11 @@ function checkQuotaError(data, supressToastr = false) {
14981498
14991499/**
15001500 * @param {any} data
15011501 * @param {boolean?} [supressToastrquiet=false]
15021502 */
15031503function checkModerationError(data, supressToastrquiet = false) {
15041504 const moderationError = data?.error?.message?.includes('requires moderation');
15051505 if (moderationError && !supressToastrquiet) {
15061506 const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;
15071507 const flaggedText = data?.error?.metadata?.flagged_input ?? '(N/A)';
15081508 toastr.info(flaggedText, moderationReason, { timeOut: 10000 });
@@ -2261,14 +2261,14 @@ async function sendOpenAIRequest(type, messages, signal) {
22612261 * Extracts the reply from the response data from a chat completions-like source
22622262 * @param {object} data Response data from the chat completions-like source
22632263 * @param {object} state Additional state to keep track of
22642264 * @param {object} [options] Additional options
22652265 * @param {string?} [options.chatCompletionSource] Chat completion source
22662266 * @param {boolean?} [options.ignoreShowThoughtsoverrideShowThoughts] IgnoreOverride show thoughts
22672267 * @returns {string} The reply extracted from the response data
22682268 */
22692269export function getStreamingReply(data, state, { chatCompletionSource = null, ignoreShowThoughts = falseoverrideShowThoughts } = {}) {
22702270 const chat_completion_source = chatCompletionSource ?? oai_settings.chat_completion_source;
22712271 const show_thoughts = ignoreShowThoughtsoverrideShowThoughts !== undefined ? trueoverrideShowThoughts : oai_settings.show_thoughts;
22722272
22732273 if (chat_completion_source === chat_completion_sources.CLAUDE) {
22742274 if (show_thoughts) {