Repository navigation
Ask the AI with @ai in a channel - #3
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>
- ai_chat.py: Workers AI chat on its own background thread; short plain-text
answers for screen readers (Markdown stripped), in the question's language
- A channel message starting with the AI_CHAT_PREFIX ("@ai" followed by a
space, ':' or ',') is forwarded; the answer is posted in that channel as
"[AI] untuk <nick>: ..." plus AI_CHAT_DISCLAIMER. As an admin the bot posts
without joining the channel, so there are no join/leave sounds
- Follow-ups: the channel's last AI_CHAT_HISTORY questions/answers from the
last 10 minutes go along; nicknames are never sent to the AI
- Per-person cooldown and a daily limit (told privately); answers with a
clear badword are replaced by a refusal; failures get a short apology
- Channel messages are intercepted while it is on; /abt aichat (off by
default, refused without credentials); /help ai for users
- ai_review: the HTTP call is shared as call_workers_ai()
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # README.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
Anyone can type in a channel:
and the bot answers in that channel (not by PM), so everyone there hears it:
AI_CHAT_HISTORY(3) questions and answers from the last 10 minutes go along. Nicknames are never sent to the AI.@aimust be followed by a space,:or,(@aisyah halois ignored). Private messages are not answered.AI_CHAT_COOLDOWN_SEC, 20 s) and a server-wide daily limit (AI_CHAT_DAILY_LIMIT, 200), told privately./abt aichat on, refused until the Cloudflare credentials from AI context check for ambiguous badwords #2 are inconfig.json./help aiexplains it to users. Disclaimer text, prefix, model and limits are configurable (docs/ai.md).Tested
max_tokens/temperature, answer cleaning, empty answers.@aisyah; badword in answer replaced; ambiguous word kept; failure apology; PM and the bot's own messages ignored; busy queue; refused without credentials; help texts.🤖 Generated with Claude Code