Skip to content

barisayyildiz/contextual-flashcards

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contextual Language Flashcards (Anki Addon & CLI)

This project provides an Anki Addon and a standalone CLI tool to automatically generate rich language learning flashcards using Large Language Models (LLMs) like Google Gemini. By providing a target word and the sentence where you found it, the tool extracts its context-specific definition, uncovers its grammatical type, and generates relevant example sentences.

Features

  • Context-Aware Definitions: Resolves word ambiguity by analyzing the context you saw the word in.
  • Auto-Generated Examples: Automatically populates the card with multiple usage examples.
  • Anki Addon: Seamless UI to generate and add cards straight into your daily deck.
  • CLI Interface: Generate and insert cards via terminal (using AnkiConnect).
  • Customizable Card Template: Map the output fields (word, context, definition, type, synonyms, examples) to your own Anki Note format!

Setup

Requirements

  • Python 3.9+ (if using the CLI standalone)
  • A Google Gemini API Key

1. Installation (Anki Addon)

  1. Locate your Anki Addons folder. Open Anki and go to Tools -> Add-ons -> View Files.
  2. Copy this entire project directory (polar-orion) into the addons folder. Let's rename it to something recognizable like contextual_flashcards.
  3. Restart Anki.

2. Configuration

  1. Open Anki.
  2. Go to Tools -> Contextual Flashcards.
  3. Click on the Settings button.
  4. Go to the Basic tab and enter your Google Gemini API Key. (You can get one from Google AI Studio).
  5. In the Anki Settings tab, ensure the mapping of outputs fits your Note Type. The generator outputs the following internal properties:
    • word: The target word.
    • context: The sentence where you saw it.
    • definition: The meaning of the word in that specific context.
    • type: The grammatical type (noun, verb, etc).
    • synonyms: A list of synonyms for the word in this context.
    • examples: A list of 1-3 example sentences.

Creating your custom Anki Note Type

If you don't have a template ready, go to Tools -> Manage Note Types -> Add in Anki and create a new Note Type (e.g., based on "Basic") with the following fields:

  • Word
  • Context
  • Definition
  • Type
  • Synonyms
  • Examples

Then in the Addon settings, map word -> Word, context -> Context, synonyms -> Synonyms, etc.

Usage

Using the Anki Addon

  1. While studying or browsing, if you find a word you want to study, go to Anki's Tools -> Contextual Flashcards.
  2. Enter the Word and paste the Context.
  3. Select your target language and click "Generate".
  4. After reviewing the generated content in the preview box, click "Add to Anki".

Using the CLI

To use the CLI, Anki must be running and have the AnkiConnect addon installed (Addon Code: 2055492159).

Configure your CLI tools by saving your settings to ~/.anki_context_flashcard_config.json:

{
    "gemini_api_key": "YOUR_API_KEY",
    "default_model": "gemini",
    "default_language": "English",
    "deck_name": "Default",
    "note_type": "Language",
    "field_mapping": {
        "word": "Word",
        "definition": "Definition",
        "context": "Context",
        "type": "Type",
        "synonyms": "Synonyms",
        "example1": "Example 1",
        "example2": "Example 2",
        "example3": "Example 3"
    }
}

Run the script from your terminal:

python ./cli.py --word "aberration" --context "She is normally calm and level headed, so this outburst is an aberration." --lang "Spanish"

Future Plans

  • Support for Local LLM inference (e.g., via LM Studio / Ollama).

About

An Anki Addon & CLI tool that uses LLMs to generate context-aware language flashcards with definitions, grammatical types, and example sentences.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages