Better naming

76193960537d0c0fa71de205b7e24c7c92ea52f6

bmen25124 <bmen25124@gmail.com>

2 files changed, +17 -18Ignore whitespace
public/scripts/custom-request.js+1 -2
@@ -64,7 +64,6 @@ import EventSourceStream from './sse-stream.js';
64 * @property {Object} state - Generated state64 * @property {Object} state - Generated state
65 * @property {string?} [state.reasoning] - Generated reasoning65 * @property {string?} [state.reasoning] - Generated reasoning
66 * @property {string?} [state.image] - Generated image66 * @property {string?} [state.image] - Generated image
67 * @returns {StreamResponse}
68 */67 */
6968
70// #endregion69// #endregion
@@ -412,7 +411,7 @@ export class ChatCompletionService {
412411
413 const reply = getStreamingReply(parsed, state, {412 const reply = getStreamingReply(parsed, state, {
414 chatCompletionSource: data.chat_completion_source,413 chatCompletionSource: data.chat_completion_source,
415 ignoreShowThoughts: true,414 overrideShowThoughts: true,
416 });415 });
417 if (Array.isArray(parsed?.choices) && parsed?.choices?.[0]?.index > 0) {416 if (Array.isArray(parsed?.choices) && parsed?.choices?.[0]?.index > 0) {
418 const swipeIndex = parsed.choices[0].index - 1;417 const swipeIndex = parsed.choices[0].index - 1;
public/scripts/openai.js+16 -16
@@ -1444,9 +1444,9 @@ export async function prepareOpenAIMessages({
1444 * Handles errors during streaming requests.1444 * Handles errors during streaming requests.
1445 * @param {Response} response1445 * @param {Response} response
1446 * @param {string} decoded - response text or decoded stream data1446 * @param {string} decoded - response text or decoded stream data
1447 * @param {boolean?} [supressToastr=false]1447 * @param {boolean?} [quiet=false]
1448 */1448 */
1449export function tryParseStreamingError(response, decoded, supressToastr = false) {1449export function tryParseStreamingError(response, decoded, quiet = false) {
1450 try {1450 try {
1451 const data = JSON.parse(decoded);1451 const data = JSON.parse(decoded);
14521452
@@ -1454,19 +1454,19 @@ export function tryParseStreamingError(response, decoded, supressToastr = false)
1454 return;1454 return;
1455 }1455 }
14561456
1457 checkQuotaError(data, supressToastr);1457 checkQuotaError(data, quiet);
1458 checkModerationError(data, supressToastr);1458 checkModerationError(data, quiet);
14591459
1460 // these do not throw correctly (equiv to Error("[object Object]"))1460 // these do not throw correctly (equiv to Error("[object Object]"))
1461 // if trying to fix "[object Object]" displayed to users, start here1461 // if trying to fix "[object Object]" displayed to users, start here
14621462
1463 if (data.error) {1463 if (data.error) {
1464 !supressToastr && toastr.error(data.error.message || response.statusText, 'Chat Completion API');1464 !quiet && toastr.error(data.error.message || response.statusText, 'Chat Completion API');
1465 throw new Error(data);1465 throw new Error(data);
1466 }1466 }
14671467
1468 if (data.message) {1468 if (data.message) {
1469 !supressToastr && toastr.error(data.message, 'Chat Completion API');1469 !quiet && toastr.error(data.message, 'Chat Completion API');
1470 throw new Error(data);1470 throw new Error(data);
1471 }1471 }
1472 }1472 }
@@ -1478,17 +1478,17 @@ export function tryParseStreamingError(response, decoded, supressToastr = false)
1478/**1478/**
1479 * Checks if the response contains a quota error and displays a popup if it does.1479 * Checks if the response contains a quota error and displays a popup if it does.
1480 * @param data1480 * @param data
1481 * @param {boolean?} [supressToastr=false]1481 * @param {boolean?} [quiet=false]
1482 * @returns {void}1482 * @returns {void}
1483 * @throws {object} - response JSON1483 * @throws {object} - response JSON
1484 */1484 */
1485function checkQuotaError(data, supressToastr = false) {1485function checkQuotaError(data, quiet = false) {
1486 if (!data) {1486 if (!data) {
1487 return;1487 return;
1488 }1488 }
14891489
1490 if (data.quota_error) {1490 if (data.quota_error) {
1491 !supressToastr && renderTemplateAsync('quotaError').then((html) => Popup.show.text('Quota Error', html));1491 !quiet && renderTemplateAsync('quotaError').then((html) => Popup.show.text('Quota Error', html));
14921492
1493 // this does not throw correctly (equiv to Error("[object Object]"))1493 // this does not throw correctly (equiv to Error("[object Object]"))
1494 // if trying to fix "[object Object]" displayed to users, start here1494 // if trying to fix "[object Object]" displayed to users, start here
@@ -1498,11 +1498,11 @@ function checkQuotaError(data, supressToastr = false) {
14981498
1499/**1499/**
1500 * @param {any} data1500 * @param {any} data
1501 * @param {boolean?} [supressToastr=false]1501 * @param {boolean?} [quiet=false]
1502 */1502 */
1503function checkModerationError(data, supressToastr = false) {1503function checkModerationError(data, quiet = false) {
1504 const moderationError = data?.error?.message?.includes('requires moderation');1504 const moderationError = data?.error?.message?.includes('requires moderation');
1505 if (moderationError && !supressToastr) {1505 if (moderationError && !quiet) {
1506 const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;1506 const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;
1507 const flaggedText = data?.error?.metadata?.flagged_input ?? '(N/A)';1507 const flaggedText = data?.error?.metadata?.flagged_input ?? '(N/A)';
1508 toastr.info(flaggedText, moderationReason, { timeOut: 10000 });1508 toastr.info(flaggedText, moderationReason, { timeOut: 10000 });
@@ -2261,14 +2261,14 @@ async function sendOpenAIRequest(type, messages, signal) {
2261 * Extracts the reply from the response data from a chat completions-like source2261 * Extracts the reply from the response data from a chat completions-like source
2262 * @param {object} data Response data from the chat completions-like source2262 * @param {object} data Response data from the chat completions-like source
2263 * @param {object} state Additional state to keep track of2263 * @param {object} state Additional state to keep track of
2264 * @param {object} options Additional options2264 * @param {object} [options] Additional options
2265 * @param {string?} [options.chatCompletionSource] Chat completion source2265 * @param {string?} [options.chatCompletionSource] Chat completion source
2266 * @param {boolean?} [options.ignoreShowThoughts] Ignore show thoughts2266 * @param {boolean?} [options.overrideShowThoughts] Override show thoughts
2267 * @returns {string} The reply extracted from the response data2267 * @returns {string} The reply extracted from the response data
2268 */2268 */
2269export function getStreamingReply(data, state, { chatCompletionSource = null, ignoreShowThoughts = false } = {}) {2269export function getStreamingReply(data, state, { chatCompletionSource = null, overrideShowThoughts } = {}) {
2270 const chat_completion_source = chatCompletionSource ?? oai_settings.chat_completion_source;2270 const chat_completion_source = chatCompletionSource ?? oai_settings.chat_completion_source;
2271 const show_thoughts = ignoreShowThoughts ? true : oai_settings.show_thoughts;2271 const show_thoughts = overrideShowThoughts !== undefined ? overrideShowThoughts : oai_settings.show_thoughts;
22722272
2273 if (chat_completion_source === chat_completion_sources.CLAUDE) {2273 if (chat_completion_source === chat_completion_sources.CLAUDE) {
2274 if (show_thoughts) {2274 if (show_thoughts) {