Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
9baef8e
Dropdown menu for llm templates.
andrewsanchez Feb 11, 2025
906e157
Rename stuff.
andrewsanchez Feb 11, 2025
16c906a
Fix dq window display issue and run subprocess properly.
andrewsanchez Feb 11, 2025
277562a
Update note with LLM response.
andrewsanchez Feb 12, 2025
bf6a6cf
Check and install uv.
andrewsanchez Feb 12, 2025
4f87112
Install llm with uv.
andrewsanchez Feb 12, 2025
c0a4bc2
Fix uv run issue.
andrewsanchez Feb 12, 2025
f21819e
Install provides.
andrewsanchez Feb 12, 2025
82e2481
show diff.
andrewsanchez Feb 12, 2025
c0bdc0c
Update ankihub/labs/llm/llm.py
andrewsanchez Feb 12, 2025
4a284db
Show only anki templates.
andrewsanchez Feb 12, 2025
36ff308
Delete templates.py.
andrewsanchez Feb 12, 2025
ca24131
Add prompt templates.
andrewsanchez Feb 12, 2025
f7e1042
Preview prompt.
andrewsanchez Feb 12, 2025
3d0f67a
perf: get templates dir once.
andrewsanchez Feb 12, 2025
e3b30d2
Copy templates.
andrewsanchez Feb 12, 2025
af77d3c
Add support for linux
RisingOrange Feb 12, 2025
299d9e9
Fix error in AddCardsDialog
RisingOrange Feb 12, 2025
d58574a
Fix dialog focus after updating note
RisingOrange Feb 12, 2025
649677e
Add secrets dialog.
andrewsanchez Feb 13, 2025
63f5421
Improve the prompt preview dialog.
andrewsanchez Feb 13, 2025
c948f92
Merge remote-tracking branch 'origin/main' into ai-editor
andrewsanchez Feb 13, 2025
c8da4c2
subproject commit.
andrewsanchez Feb 13, 2025
f5a7106
Move import
andrewsanchez Feb 13, 2025
1bf8f15
Add yaml lib.
andrewsanchez Feb 13, 2025
6899aa6
enable labs.
andrewsanchez Feb 13, 2025
55e3d99
Create add-on first.
andrewsanchez Feb 13, 2025
e3498b9
Save template.
andrewsanchez Feb 14, 2025
ef94d36
always make addon file right away.
andrewsanchez Feb 14, 2025
afcd2b6
Accept result dialog before showing other dialog
RisingOrange Feb 14, 2025
80eba58
Try fix UI issue
RisingOrange Feb 14, 2025
fbf2a90
Use shell scripts and set PATH.
andrewsanchez Feb 14, 2025
df50cc1
Move scripts.
andrewsanchez Feb 14, 2025
33585d6
Make _install_llm work on Windows
RisingOrange Feb 14, 2025
f1b1e93
Fix focus issue
RisingOrange Feb 14, 2025
98e2ba9
Move labs depedenencies installation to background
RisingOrange Feb 14, 2025
3c9f64e
Use without_collection on query op for installing labs dependencies
RisingOrange Feb 14, 2025
8f84e8b
Use shell scripts.
andrewsanchez Feb 15, 2025
1d7b078
Make scripts excutable.
andrewsanchez Feb 15, 2025
90745e8
Combine scripts.
andrewsanchez Feb 15, 2025
44af1fe
Provide path to UV.
andrewsanchez Feb 15, 2025
b5b9b26
utf-8.
andrewsanchez Feb 15, 2025
185ffbe
utf-8
andrewsanchez Feb 15, 2025
bc5957b
FIx secrets dialog.
andrewsanchez Feb 15, 2025
57e5d47
Pass and update only the first field.
andrewsanchez Feb 15, 2025
3c6d2b8
Template.
andrewsanchez Feb 15, 2025
f29e542
Be sure to install providers.
andrewsanchez Feb 16, 2025
15e3abb
Merge branch 'main' into ai-editor
andrewsanchez Feb 16, 2025
ed25344
fix: Add install_providers cmd, don't make UI changes in background
RisingOrange Feb 17, 2025
60c7286
fix: Remove unused note_schema argument
RisingOrange Feb 17, 2025
eb450df
Add "Reset template" button to prompt preview
RisingOrange Feb 17, 2025
b6bf5cd
Don't reinstall providers every time
RisingOrange Feb 17, 2025
aef1b5c
Tweak template.
andrewsanchez Feb 28, 2025
b1a6259
Handle error on user defined templates.
andrewsanchez Feb 28, 2025
0a4837b
Merge branch 'main' into ai-editor
andrewsanchez Mar 7, 2025
ee5b09c
Add llm.ps1 for Windows
abdnh Mar 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ jobs:
google_api_key: ${{ secrets.GOOGLE_API_KEY }}
install_qt: true

- name: Create ankiaddon file
run: |
bash ./scripts/release.sh
env:
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}

- name: Archive .ankiaddon
uses: actions/upload-artifact@v4
with:
name: ankihub_addon_${{ github.sha }}
path: ankihub.ankiaddon

- name: Replace Anki version
if: ${{ matrix.replace_anki_version }}
run: pip install "${{ matrix.anki_package_version }}"
Expand Down Expand Up @@ -159,18 +171,6 @@ jobs:
with:
fail_ci_if_error: false

- name: Create ankiaddon file
run: |
bash ./scripts/release.sh
env:
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}

- name: Archive .ankiaddon
uses: actions/upload-artifact@v4
with:
name: ankihub_addon_${{ github.sha }}
path: ankihub.ankiaddon

- name: Run pre-commit
run: pre-commit run --all

Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
ankihub/meta.json

# Anki base directory
anki_base

anki_base/
# AnkiHub base directory
ankihub_base
ankihub_base/

# Ignore everything except the README.
/ankihub/user_files/*
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ repos:
hooks:
- id: pycln

- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args: [--remove-all-unused-imports, --in-place]

- repo: local
hooks:
- id: no_absolute_imports_from_ankihub
Expand Down
17 changes: 17 additions & 0 deletions ankihub/entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,23 @@ def _general_setup():
LOGGER.info(
"Set up feature flag fetching (flags will be fetched in the background)."
)
# Make all .sh files executable
for sh_file in Path(__file__).parent.rglob("*.sh"):
current_mode = sh_file.stat().st_mode
executable_mode = (
current_mode | 0o111
) # Add execute permission for user, group and others
sh_file.chmod(executable_mode)
LOGGER.info("Made all .sh files executable.")

if config.labs_enabled:
from .labs.llm import llm

try:
llm.setup()
LOGGER.info("Set up LLM prompt functionality.")
except Exception as e:
LOGGER.exception("Failed to set up LLM prompt functionality", error=e)


def _copy_web_media_to_media_folder():
Expand Down
2 changes: 1 addition & 1 deletion ankihub/gui/ankiaddonconfig
Submodule ankiaddonconfig updated 1 files
+1 −1 manager.py
3 changes: 3 additions & 0 deletions ankihub/gui/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from ..addon_ankihub_client import AddonAnkiHubClient as AnkiHubClient
from ..ankihub_client import AnkiHubHTTPError
from ..db import ankihub_db
from ..labs.gui.menu import setup_labs_menu
from ..media_import.ui import open_import_dialog
from ..settings import ADDON_VERSION, config
from .config_dialog import get_config_dialog_manager
Expand Down Expand Up @@ -74,6 +75,8 @@ def refresh_ankihub_menu() -> None:
_config_setup(parent=menu_state.ankihub_menu)
_ankihub_terms_and_policy_setup(parent=menu_state.ankihub_menu)
_ankihub_help_setup(parent=menu_state.ankihub_menu)
if config.labs_enabled:
setup_labs_menu(menu_state.ankihub_menu)


class AnkiHubLogin(QWidget):
Expand Down
1 change: 1 addition & 0 deletions ankihub/labs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""AnkiHub Labs module for experimental features."""
1 change: 1 addition & 0 deletions ankihub/labs/gui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""GUI components for AnkiHub Labs features."""
18 changes: 18 additions & 0 deletions ankihub/labs/gui/menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""AnkiHub Labs menu setup."""

from aqt.qt import QAction, QMenu, qconnect

from ..secrets import open_secrets_dialog


def setup_labs_menu(parent_menu: QMenu) -> None:
"""Set up the AnkiHub Labs menu if labs are enabled."""
# Create Labs submenu
labs_menu = QMenu("🧪 AnkiHub Labs", parent_menu)

# Add Secrets submenu
secrets_action = QAction("🔑 Secrets", labs_menu)
qconnect(secrets_action.triggered, open_secrets_dialog)
labs_menu.addAction(secrets_action)

parent_menu.addMenu(labs_menu)
1 change: 1 addition & 0 deletions ankihub/labs/llm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""LLM-related functionality for AnkiHub."""
68 changes: 68 additions & 0 deletions ankihub/labs/llm/llm.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Ensure ~/.local/bin is in PATH
$env:PATH = "$HOME\.local\bin;$env:PATH"

# Define UV executable path
$UV_PATH = "$HOME\.local\bin\uv"

function Check-Uv {
& "$UV_PATH" version
}

function Install-Uv {
# Install uv using the official installer
Invoke-RestMethod https://astral.sh/uv/install.ps1 | Invoke-Expression

# Add uv to the current PATH
$env:PATH = "$HOME\.local\bin;$env:PATH"
}

function Check-Llm {
& llm --version
}

function Install-Llm {
# Install llm using uv
& "$UV_PATH" tool install llm
}

function Install-Provider {
param (
[string]$provider
)
Write-Output "Installing provider: '$provider'"
& "$UV_PATH" run --no-project llm install -U $provider
}

function Get-Templates-Path {
& "$UV_PATH" run --no-project llm templates path
}

function Get-Keys-Path {
& "$UV_PATH" run --no-project llm keys path
}

function Execute-Prompt {
param (
[string]$templateName,
[string]$noteContent
)
& "$UV_PATH" run --no-project llm -m gpt-4o --no-stream -t "$templateName" "$noteContent"
}

$cmd = $args[0]
$args = $args[1..$args.Length]

switch ($cmd) {
"check_uv" { Check-Uv }
"install_uv" { Install-Uv }
"check_llm" { Check-Llm }
"install_llm" { Install-Llm }
"install_provider" { Install-Provider -provider $args[0] }
"get_templates_path" { Get-Templates-Path }
"get_keys_path" { Get-Keys-Path }
"execute_prompt" { Execute-Prompt -templateName $args[0] -noteContent $args[1] }
default {
Write-Output "Unknown command: $cmd"
exit 1
}
}
Loading
Loading