This is a Python-based command-line interface (CLI) application that functions as a flashcard system, similar to Anki. It allows you to add flashcards, review them using the SM-2 spaced repetition algorithm, and utilizes OpenAI's GPT-4 to grade your answers. The application runs entirely in the terminal, making it lightweight and easy to use.
- Add Flashcards: Quickly add new flashcards with front and back text, along with optional tags for categorization.
- Review Flashcards: Review flashcards that are due based on the SM-2 algorithm, ensuring efficient learning.
- Answer Grading: Input your answer during reviews and receive immediate feedback graded by OpenAI's GPT-4.
- Difficulty Rating: After each review, rate the difficulty of recalling the answer to adjust future review intervals.
- Statistics Tracking: View your study progress and flashcard statistics over time.
- Python 3.6 or higher.
- OpenAI API Key: You need an OpenAI API key with access to the GPT-4 model.
Clone this repository to your local machine using:
git clone https://github.com/yourusername/ankicli.git
cd ankicli
Create and activate a virtual environment to manage dependencies:
python3 -m venv venv
source venv/bin/activate
Install the required Python packages:
pip install openai python-dotenv
Create a .env
file in the project directory:
touch .env
Add your OpenAI API key to the .env
file:
OPENAI_API_KEY=your_api_key_here
Replace your_api_key_here
with your actual OpenAI API key.
Ensure the anki
script has execute permissions:
chmod +x anki
To run the anki
command from anywhere without using sudo
, add the script's directory to your PATH
environment variable.
Depending on your shell (zsh
or bash
), open the appropriate configuration file:
-
For
zsh
users (default on macOS Catalina and later):nano ~/.zshrc
-
For
bash
users:nano ~/.bash_profile
Add the following line at the end of the file:
export PATH="/path/to/ankicli:$PATH"
Replace /path/to/ankicli
with the actual path to your ankicli
directory.
Apply the changes by reloading your shell configuration:
-
For
zsh
users:source ~/.zshrc
-
For
bash
users:source ~/.bash_profile
Make sure the anki
script is executable:
chmod +x /path/to/ankicli/anki
Test that the anki
command is recognized:
anki --help
You should see the help message for the anki
command. If you encounter any errors, double-check the steps above.
Add a new flashcard using the add
command with the --front
and --back
options. You can also add tags using --tags
.
Example:
anki add --front "What is the capital of France?" --back "Paris" --tags "geography,Europe"
Using Shorthand Flags:
anki add -f "What is the capital of France?" -b "Paris" -t "geography,Europe"
Review due flashcards using the review
command:
anki review
Review Process:
- The application displays the front text of the flashcard.
- You input your answer.
- GPT-4 grades your answer and provides feedback.
- The correct answer is displayed.
- You rate your recall as
easy
,medium
, orhard
. - The flashcard's review interval is updated based on your rating.
View your study statistics using the stats
command:
anki stats
This displays:
- Total number of flashcards.
- Number of flashcards due today.
- Average easiness factor.
anki add -f "What is the process by which plants make their food?" -b "Photosynthesis" -t "biology,plants"
anki add -f "Who wrote 'To Kill a Mockingbird'?" -b "Harper Lee" -t "literature,authors"
anki review
Sample Output:
Front: What is the process by which plants make their food?
Your answer: Photosynthesis
GPT-4 Assessment: Correct! Plants make their food through photosynthesis.
Correct Answer: Photosynthesis
Rate your recall ('easy', 'medium', 'hard'): easy
Next review in 6 day(s).
Front: Who wrote 'To Kill a Mockingbird'?
Your answer: J.K. Rowling
GPT-4 Assessment: Incorrect. The correct author is Harper Lee, not J.K. Rowling.
Correct Answer: Harper Lee
Rate your recall ('easy', 'medium', 'hard'): hard
Next review in 1 day(s).
Review session complete.
anki stats
Sample Output:
Total flashcards: 2
Flashcards due today: 0
Average Easiness Factor: 2.55
- Flashcards File: The flashcards are stored in a file named
flashcards.json
in the project directory. - Backup: Regularly back up
flashcards.json
to prevent data loss. - Manual Editing: Avoid manually editing
flashcards.json
to prevent data corruption.
- openai: For interacting with the OpenAI API.
- python-dotenv: For loading environment variables from the
.env
file.
Install all dependencies using:
pip install -r requirements.txt
Alternatively, install individually:
pip install openai python-dotenv
- API Usage and Costs: Using the OpenAI API incurs costs based on usage. Monitor your API usage on the OpenAI dashboard to manage expenses.
- Model Access: Ensure your OpenAI API key has access to the GPT-4 model. If not, you can modify the script to use
gpt-3.5-turbo
in thegrade_answer
function. - Data Privacy: Your answers and the correct answers are sent to OpenAI's servers for processing. Be mindful of any sensitive information.
anki
Command Not Found: Ensure that the script's directory is correctly added to yourPATH
and that the script is executable.- OpenAI API Errors: Double-check your API key in the
.env
file and ensure you have internet connectivity. - Permission Denied: If you receive a permission error, make sure the script has execute permissions (
chmod +x anki
).
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes with clear messages.
- Open a pull request describing your changes.
This project is licensed under the MIT License.
- Anki: Inspiration for the spaced repetition algorithm and flashcard concept.
- OpenAI: Providing the GPT-4 model for answer grading.
Enjoy efficient and intelligent studying with your new CLI flashcard application!