Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AI editor #1094

Draft
wants to merge 52 commits into
base: main
Choose a base branch
from
Draft

AI editor #1094

wants to merge 52 commits into from

Conversation

andrewsanchez
Copy link
Contributor

@andrewsanchez andrewsanchez commented Feb 12, 2025

Quick proof of concept PR to prototype in-Anki LLM features for editing and creating cards.

Comment on lines 242 to 245
if config.labs_enabled:
llm.setup()
LOGGER.info("Set up LLM prompt functionality.")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RisingOrange One possibility to implement "AnkiHub Labs": if labs is enabled, we clone/pull from a separate mono repo on GitHub that contains a bunch of community contributed functionality. Users can individually toggle them on/off. We could accept or reject PRs to this mono repo that are basically a bunch of mini standalone add-ons. Except, we could provide facilities for quick and easy development, web capabilities, and maybe mobile integrations. We could provide a replit template, cursor rules, and copilot prompts to make developing these really easy with AI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conda-forge might be a good model to look at for how to do this https://conda-forge.org/docs/maintainer/infrastructure/

@RisingOrange
Copy link
Collaborator

Some UI elements are unreadable on dark mode:

@RisingOrange
Copy link
Collaborator

RisingOrange commented Feb 12, 2025

@andrewsanchez Using llm requires an API key for the LLM provider being set up on the user's device. Will we require users to provide an API key?

@andrewsanchez
Copy link
Contributor Author

andrewsanchez commented Feb 13, 2025

@andrewsanchez Using llm requires an API key for the LLM provider being set up on the user's device. Will we require users to provide an API key?

EDIT: addressed in 649677e

This PR is just a quick proof of concept in order to test out some workflows internally with a few people. So I will provide API keys that testers on our team can use. If we decide to put this in the hands of real users, we would need to migrate the llm related code to our infrastructure or create a new service/API. At that point, we could consider continuing to use llm or use langchain or something else instead.

Comment on lines +288 to +302
def _on_reset(self) -> None:
"""Reset the template to the version in the local templates directory."""
if ask_user(
"Are you sure you want to reset the template to the original version?"
):
local_template_path = (
TemplateManager._local_templates_dir / f"{self.template_name}.yaml"
)
self.template_content = local_template_path.read_text(encoding="utf-8")
self.yaml_data = yaml.safe_load(self.template_content)
if not isinstance(self.yaml_data, dict):
self.yaml_data = {}
self._update_editors() # Update the editors with the reset content
TemplateManager.save_template(self.template_name, self.template_content)
tooltip("Template reset.", parent=self)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why but this results in some funky yaml, @RisingOrange :

model: gpt-4o
system: "You are an expert at creating effective flashcards. Analyze the provided\
  \ cloze deletion note and respond with an improved note according to the users instructions.\n\
  Follow these guidelines:\n- Use cloze deletions to hide key information.\n- Use\
  \ the {{c1::hidden text}} format for cloze deletions. You can also use {{c2::hidden\
  \ text}}, {{c3::hidden text}}, and so on. This will result in multiple cards being\
  \ created for the note by Anki. Cloze deletions with the same number will be hidden\
  \ on the same card, while all the other cloze deletions won't be used for this card.\n\
  - Most notes should only have one cloze deletion. Focus on the highest yield concepts\
  \ and facts. \"high-yield\" means the information is most important or most frequently\
  \ tested on exams.\n- Create focused cards which tests a single concept or fact.\n\
  - Ensure the remaining context provides enough information for the user to recall\
  \ the hidden content.\n\n## Common Mistakes\nAvoid these common mistakes when creating\
  \ cloze deletion cards:\n- Occluding too much information, making the card impossible\
  \ to answer.\n  - E.g., \"The {{c1::sky}} is {{c1::blue}}.\" This card is impossible\
  \ to answer because both \"sky\" and \"blue\" are occluded.\n\n\nHere are some examples\
  \ of well-constructed cloze deletion notes:\n- Persistent {{c1::infection}} is the\
  \ most common symptom of chronic sinopulmonary disease\n- Chronic sinopulmonary\
  \ disease commonly presents with chronic {{c1::cough}} and {{c1::sputum}} production.\n\
  - 11-deoxycorticosterone (DOC) may be converted to {{c1::corticosterone}} via the\
  \ enzyme {{c2::11\u03B2-hydroxylase}}.\n- 11\u03B2-hydroxylase deficiency presents\
  \ with {{c1::hypokalemia}} and {{c1::hypertension}}.\n- The {{c1::orbit}} is the\
  \ bony socket housing the eyeball and contains muscles for {{c2::eye movement}}\
  \ and {{c2::eyelid opening}}.\n- The upper portion of the nasal septum is formed\
  \ by the {{c1::ethmoid}} bone; the lower portion is formed by the {{c2::vomer}}\
  \ bone.\n- {{c1::Bone marrow}} within bones stores {{c2::fat}} and produces {{c3::blood\
  \ cells}}.\n- Two main side effects of osmotic laxatives include {{c1::diarrhea}}\
  \ and {{c1::dehydration}}.\n- Newly synthesized cGMP (from guanylyl cyclase activity)\
  \ activates {{c1::protein kinase G}}, which phosphorylates specific proteins responsible\
  \ for physiologic actions.\n- The posterior lobe of the pituitary gland is derived\
  \ from {{c1::neural}} tissue.\n- The skeleton protects {{c1::internal organs}} and\
  \ stores minerals like {{c2::calcium}} and {{c2::phosphate}}.\n\nImprove the provided\
  \ cloze deletion note based on the instructions above. Ensure that the card is clear,\
  \ and effective for learning and recall. Respond only with the improved note. Do\
  \ not provide any pre-amble, explanation, or surrounding xml tags.\n"
prompt: 'Here is the card to improve:

  <original note>

  $input

  </original note>

  '

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually not sure if it's this or saving user changes. I'll take a look

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya I think it happens when users try to save the template changes but not sure why yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants