A Chrome extension that answers Віталій's Instagram DMs in casual, funny Ukrainian. It writes in his voice, and the AI runs on his own Mac mini through Ollama.
Chrome holds the extension code. Ollama holds the two AI models, which stay loaded in memory all the time. The internet is used only to look up facts like weather or exchange rates.
Every 5 seconds the bot reads the open chat. The patrol also opens unread chats from the inbox list by itself. A chat that still looks unread after a click is skipped for 3 minutes, so it can't block the others.
The bot only answers when the last message is the friend's, it's new, and you aren't typing yourself. Each chat gets at most one reply every 60 seconds. A message that arrives during that pause waits and gets answered once the pause is over. A chat seen for the first time after a restart is only remembered, not answered.
A friend's picture is downloaded, shrunk to 768 px and described in one Ukrainian sentence, for example «[фото: чоловік у жовтій куртці]». That takes 2–15 seconds. If the friend sent only pictures the bot couldn't make out, it stays silent.
The model gets: the style rules, the date and time, the last 14 messages of the chat, the word list (for example «гаразд → норм»), and about 6 of your old replies to similar messages plus 3 recent ones with this friend. For a question about weather, rates or the news, the facts are looked up first.
A Ukrainian-tuned Gemma 3 model writes one short reply in your voice, in masculine forms, usually within 5–10 seconds. If Ollama fails, a ready-made phrase is used instead.
The text is checked for the model's usual mistakes, then the bot waits 1.5–4 seconds to look human, types the reply and presses Enter.
learn/build_pairs.py read your Instagram export and saved 713 pairs of "what a friend wrote → what you answered" from 78 chats.
For each new message the bot finds the old exchanges with the most similar wording (it compares letter patterns), and gives a bonus to the same friend. The model copies your manner, length and emoji. The rules tell it not to copy text word for word or take facts from these examples.
Local models repeat the same habits, so every reply passes through fixed rules before it's sent.
| Rule | Why |
|---|---|
| Remove a leading «Ну», «Ну і», «Ну, …» | The model copied its own openers and every reply started the same way |
| Remove «[фото…]», «[відео]», «[посилання…]» | Those markers are how the bot shows pictures to the model, and it sometimes copied them |
| Remove «Віталій:», «Я:» at the start | MamayLM sometimes writes the reply like a script line |
| Word list from the popup | Russianisms and words you don't use: «ладно», «гаразд» → «норм», «щас» → «зараз» |
| Grammar fixes | «дякую тебе» → «дякую тобі», «на протязі» → «протягом» |
A macOS background job checks Chrome every 5 minutes. If Chrome is missing on two checks in a row (for example after an overnight macOS update), it reopens Chrome on the Instagram inbox. Creating the file .watchdog-off pauses it.
Chrome starts with flags that stop it from slowing down hidden tabs. The Instagram tab is protected from Memory Saver, and the Mac is kept from sleeping while the bot is on.
The page part and the background part both carry a build number. When they differ after an update, the background reloads itself (log: «🔄 Оновлюю фон: 19 → 20»).
| Line | Meaning |
|---|---|
| Патруль: відкриваю… | The patrol opened an unread chat |
| [бачу] чат=… | What the bot read in the chat: the last 3 messages, «моє» = yours, «їхнє» = the friend's |
| Пауза для «…» | A new message came during the 60 s pause; it will be answered after |
| 👁️ … | What qwen2.5vl saw in a photo, and how long it took |
| «chat»: message → reply | The reply that was written |
| ✅ Надіслано (Enter) | The reply was sent |
| …не відповідаю | Only a picture the bot couldn't make out, so it stayed silent |
| Ollama помилка… | The model failed; a ready-made phrase was sent instead |
| 🛡️ Вкладку… захищено | The Instagram tab is protected from being unloaded |
| File | What it does |
|---|---|
~/insta-joker/content.js | Runs inside the Instagram tab: reads chats, patrols the inbox, types replies |
background.js | Builds the prompt, calls both models, cleans up replies, keeps the log |
memory.js | Finds your old replies that are most similar to the new message |
tools.js | Weather, NBU exchange rates, Wikipedia, web search |
defaults.js | Default settings and the build number |
popup.html, popup.js | The settings window from the toolbar icon |
my-replies.json | Your 713 old reply pairs |
learn/build_pairs.py | Rebuilds that file from a new Instagram export |
watchdog.sh | Reopens Chrome if it closed; writes watchdog.log |