From 9ee46730bc31006040dd61cd9f1fff1448cbf7c9 Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Sat, 4 Oct 2025 16:41:25 -0700 Subject: [PATCH] Refactor: Make Gemini moderation prompt more lenient --- functions/api/comments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/api/comments.js b/functions/api/comments.js index 1c594d7..004d30e 100644 --- a/functions/api/comments.js +++ b/functions/api/comments.js @@ -32,7 +32,7 @@ export async function onRequestPost({request,env}){ const{post_id,parent_id,content}=body; if(!post_id||!content)return json({error:'Missing fields'},{status:400},request); - const mod=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent?key=${env.GOOGLE_KEY}`,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({contents:[{parts:[{text:`Is this appropriate for a public forum? Respond ONLY "yes" or "no".\n\n${content}`}]}]})}); + const mod=await fetch(`https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-lite:generateContent?key=${env.GOOGLE_KEY}`,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({contents:[{parts:[{text:`Is this content permissible for a public forum that values free speech, even if it's controversial? Offensive content is okay, but illegal content, spam, or direct threats are not. Respond ONLY "yes" or "no".\n\n${content}`}]}]})}); if(!mod.ok){const err=await mod.text();return json({error:{message:`Moderation failed: ${err}`}},{status:500},request)} if(!(await mod.json()).candidates?.[0]?.content.parts[0].text.trim().toLowerCase().includes('yes'))return json({error:{message:'Comment rejected by Gemini 2.5 Flash Lite.'}},{status:400},request);