Auto-filling Back via LLM (w/AnkiConnect)

When reading on my laptop, I drop unknown words into Anki and keep going. Stopping to write the Back (defs/examples/etc.) derails me, and most tools didn’t match the format I wanted as a Korean learner.

I put together a small local script (“AutoAnki”) that, every ~5s, looks for notes with an empty Back and fills it (definition, example, short etymology, synonyms/antonyms). It uses AnkiConnect and your LLM (OpenAI or local-compatible).
Not an add-on (yet). If you want to try: install AnkiConnect, run the script, add only the word, and check back later.

Repo: https://github.com/well-balanced/autoanki
Bug reports or minimal feature requests are appreciated.

2 Likes

If you make this into an addon, then you can set the AI operation to be run on the note_will_be_added hook since that is triggered when AnkiConnect adds a note. There might be some issues if you quickly add two words and a new operation begins before the previous one has finished but other than that it should be fine.

I’ve done similar stuff to automate Japanese vocabulary note stuff with AI: GitHub - jhhr/anki_japanese_note_ai_ops
I don’t import openai as I’d previously had problems with other addons I had installed also importing openai / pydantic. Some better solutions to avoid this are around but I haven’t tried them yet.

The code used to be quite simple but then I made it possible for the operations to be run in async so that multiple API requests can be awaited at once and there’s been some nasty bugs like Qt crashing because an element is in different thread.

1 Like

Thanks! The note_will_be_added hook tip is really helpful — I think that’s a cool approach. I’ll give it a try.

This is a neat idea. A way to make this adapt to various decks and card types could be to use a few shot approach where you feed the LLM examples taken from existing notes of the same type in your deck.

I’ve written something similar as an addon, might be useful to you: https://ankiweb.net/shared/info/2043082246
Code: GitHub - Rizhiy/anki-llm-card-fill

I don’t have note_will_be_added, rather I just manually fill them in when required.
Will try to add such option in the future when I have time.

1 Like