Repository navigation
AI context check for ambiguous badwords - #2
Merged
Merged
Conversation
"anjing tetanggaku berisik" is about a dog, "anjing lah" is a curse; a word list cannot tell them apart. - ai_review.py: Cloudflare Workers AI client on a background thread; results are handled on the main thread (the only one allowed to use the SDK) - When every badword in a message is in AI_AMBIGUOUS_WORDS, the bot asks the AI first: insult -> counted, ok -> not counted, no answer -> not counted (agreed policy: better to miss a curse than warn a student about their dog) - Clear badwords, or a mix with one, are still counted immediately - Off by default; /abt ai switches it and refuses without credentials; /bwt shows the AI's verdict; tools/ai_eval.py scores a model on 32 labelled sentences; setup in docs/ai.md - Only the flagged message text is sent, never names or IPs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A lone "anjing" right after "aku punya binatang baru waaa" names the new pet, but on its own the AI reads it as a curse. - Recent messages are kept in memory (only while the AI check is on): per channel for everyone in it, per sender for private messages (the SDK does not say who a PM was for). Commands and answers to the bot's prompts, such as passwords, are never kept; old entries are dropped - On an ambiguous hit the bot waits 8 s, then sends up to AI_CONTEXT_MESSAGES (default 4) earlier messages from the last 2 minutes and up to 2 follow-ups, labelled only [same person] / [someone else] - AI_CONTEXT_MESSAGES=0 sends the flagged message alone, as before - Prompt explains the context and treats a lone swear word as an exclamation; examples and tools/ai_eval.py (38 cases) cover it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 4, 2026
# Conflicts: # README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
"anjing tetanggaku suka berisik kalau malam" is about a dog; "anjing lah" is a curse. The word list counts both, so students get warned for talking about their pets (or a tahi lalat, or mata telanjang).
What
AI_AMBIGUOUS_WORDS(animals,tahi,telanjang,seks,gay, ...), the bot asks an AI model on Cloudflare Workers AI whether it was an insult, in the background:kontol,bangsat, ...), or a message mixing one with an ambiguous word, are still counted immediately, without the AI.AI_CONTEXT_MESSAGES(default 4) earlier messages from the last 2 minutes and up to 2 follow-ups, labelled only[same person]/[someone else](per channel: everyone in it; per PM: the sender only, since the SDK does not say who a PM was for). Kept in memory only while the check is on; commands and answers to the bot's prompts (passwords) are never kept.AI_CONTEXT_MESSAGES=0sends the flagged message alone./abt ai onswitches it on and is refused untilAI_CLOUDFLARE_ACCOUNT_IDandAI_CLOUDFLARE_API_TOKENare inconfig.json. Merging this changes nothing on the server until then./bwt <text>also shows the AI's verdict;tools/ai_eval.pyscores the configured model on 38 labelled sentences (some with context) (dog vs curse, sate babi vs babi lu, mata telanjang vs harassment, ...).@cf/meta/llama-3.3-70b-instruct-fp8-fast(configurable viaAI_MODEL). Setup:docs/ai.md.Tested
Authorization: Bearer, message layout,temperature: 0, answer parsing (JSON, extra text, bare word, errors), timeouts./bwtverdict PM;/abt ai onrefused without credentials.AI_CONTEXT_MESSAGES=0.python3 tools/ai_eval.pyon the server after adding the token.🤖 Generated with Claude Code