mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add OpenRouter filtered reason display
This commit is contained in:
@ -1160,6 +1160,7 @@ function tryParseStreamingError(response, decoded) {
|
||||
}
|
||||
|
||||
checkQuotaError(data);
|
||||
checkModerationError(data);
|
||||
|
||||
if (data.error) {
|
||||
toastr.error(data.error.message || response.statusText, 'Chat Completion API');
|
||||
@ -1187,6 +1188,15 @@ function checkQuotaError(data) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkModerationError(data) {
|
||||
const moderationError = data?.error?.message?.includes('requires moderation');
|
||||
if (moderationError) {
|
||||
const moderationReason = `Reasons: ${data?.error?.metadata?.reasons?.join(', ') ?? '(N/A)'}`;
|
||||
const flaggedText = data?.error?.metadata?.flagged_input ?? '(N/A)';
|
||||
toastr.info(flaggedText, moderationReason, { timeOut: 10000 });
|
||||
}
|
||||
}
|
||||
|
||||
async function sendWindowAIRequest(messages, signal, stream) {
|
||||
if (!('ai' in window)) {
|
||||
return showWindowExtensionError();
|
||||
@ -1688,6 +1698,7 @@ async function sendOpenAIRequest(type, messages, signal) {
|
||||
const data = await response.json();
|
||||
|
||||
checkQuotaError(data);
|
||||
checkModerationError(data);
|
||||
|
||||
if (data.error) {
|
||||
toastr.error(data.error.message || response.statusText, 'API returned an error');
|
||||
|
Reference in New Issue
Block a user