summaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-09-29 22:05:47 -0700
committerFuwn <[email protected]>2025-09-29 22:05:47 -0700
commitfd8155fbb5d9c1e1e29ad8427d0f3b7a92b7d172 (patch)
treeec7dc9c9636ef78251c9431919f17ebf07c0dc32 /packages
parentfeat(commands): Clean up bot replies (diff)
downloadumabotdiscord-fd8155fbb5d9c1e1e29ad8427d0f3b7a92b7d172.tar.xz
umabotdiscord-fd8155fbb5d9c1e1e29ad8427d0f3b7a92b7d172.zip
fix(gateway:moderationAgent): Update model response handling
Diffstat (limited to 'packages')
-rw-r--r--packages/gateway/src/listeners/moderationAgent/utilities.ts19
1 files changed, 17 insertions, 2 deletions
diff --git a/packages/gateway/src/listeners/moderationAgent/utilities.ts b/packages/gateway/src/listeners/moderationAgent/utilities.ts
index eb520c7..2e6542e 100644
--- a/packages/gateway/src/listeners/moderationAgent/utilities.ts
+++ b/packages/gateway/src/listeners/moderationAgent/utilities.ts
@@ -272,16 +272,18 @@ CONFIDENCE GUIDELINES:
- 0-39%: Low confidence, likely false positive
RESPONSE FORMAT:
-You must respond with valid JSON in this exact format:
+You must respond with ONLY valid JSON in this exact format. Do not include any text before or after the JSON:
{
"violation": boolean,
"rule": "Rule number and brief description if violation found, empty string if none",
"severity": "low|medium|high|critical",
"explanation": "Detailed explanation of the violation or why it's acceptable",
"brief": "Short one-sentence explanation for why it was flagged (if violation) or why it's acceptable (if no violation)",
- "confidence": number (0-100, how confident you are in this assessment)
+ "confidence": number
}
+CRITICAL: Your response must be ONLY the JSON object above. No explanations, no markdown, no additional text. Start with { and end with }. All string values must use double quotes, not single quotes. Escape any quotes in string values with backslashes.
+
If no violation is found, set "violation" to false and provide a brief explanation of why the message is acceptable.
Remember: Only enforce the exact rules provided. Do not make assumptions or interpretations beyond what is explicitly stated in the SERVER_RULES section. Adult sexual content between adults is NOT a violation unless it explicitly breaks a stated rule.`;
@@ -350,6 +352,19 @@ Remember: Only enforce the exact rules provided. Do not make assumptions or inte
}
}
+ if (!jsonContent.startsWith("{")) {
+ const jsonMatch = jsonContent.match(/\{[\s\S]*\}/);
+
+ if (jsonMatch) jsonContent = jsonMatch[0];
+ }
+
+ jsonContent = jsonContent
+ .replace(/\\'/g, "'")
+ .replace(/'/g, '"')
+ .replace(/(\w+):/g, '"$1":')
+ .replace(/,\s*}/g, "}")
+ .replace(/,\s*]/g, "]");
+
return JSON.parse(jsonContent);
} catch (parseError) {
console.error("Failed to parse OpenRouter response as JSON:", content);