Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion .envs/.local/.django
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ CELERY_FLOWER_PASSWORD=QgScyefPrYhHgO6onW61u0nazc5xdBuP4sM7jMRrBBFuA2RjsFhZLp7xb

# Timeout fetch_data
# ------------------------------------------------------------------------------
FETCH_DATA_TIMEOUT=2
FETCH_DATA_TIMEOUT=2


HF_TOKEN=
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,6 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# End of https://www.toptal.com/developers/gitignore/api/django
# End of https://www.toptal.com/developers/gitignore/api/django

llama3/llama-3.2/*
8 changes: 5 additions & 3 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
# core/
APPS_DIR = ROOT_DIR / "core"
LLAMA_MODEL_DIR = ROOT_DIR / "llama3/llama-3.2"
MODEL_LLAMA = "llama-3.2-3b-instruct-q4_k_m.gguf"

env = environ.Env()
READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=False)
Expand Down Expand Up @@ -294,4 +292,8 @@
"ACCESS_TOKEN_LIFETIME": timedelta(minutes=60),
"REFRESH_TOKEN_LIFETIME": timedelta(days=1),
# "AUTH_TOKEN_CLASSES": ("rest_framework_simplejwt.tokens.AccessToken",),
}
}

# LLAMA
LLAMA_MODEL_DIR = ROOT_DIR / "llama3/llama-3.2"
MODEL_LLAMA = "llama-3.2-3b-instruct-q4_k_m.gguf"
15 changes: 0 additions & 15 deletions llama3/download_model.py

This file was deleted.

4 changes: 2 additions & 2 deletions llama3/generic_llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class GenericLlama:

def __init__(self, messages, response_format, max_tokens=4000, temperature=0.5, top_p=0.5):
self. llm = Llama(model_path = os.path.join(LLAMA_MODEL_DIR, MODEL_LLAMA), n_ctx=4000)
self. messages = messages
self.llm = Llama(model_path = os.path.join(LLAMA_MODEL_DIR, MODEL_LLAMA), n_ctx=4000)
self.messages = messages
self.response_format = response_format
self.max_tokens = max_tokens
self.temperature = temperature
Expand Down
48 changes: 48 additions & 0 deletions reference/management/commands/download_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
from pathlib import Path

from django.core.management.base import BaseCommand, CommandError
from huggingface_hub import hf_hub_download, login


class Command(BaseCommand):
help = "Download the model from HuggingFace"

def add_arguments(self, parser):
parser.add_argument(
"--dir",
type=str,
default="llama3/llama-3.2",
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

The hardcoded default path 'llama3/llama-3.2' should reference the Django setting LLAMA_MODEL_DIR to maintain consistency with the configuration defined in settings/base.py.

Copilot uses AI. Check for mistakes.
help="Directory to download the model",
)
parser.add_argument(
"--repo",
type=str,
default="hugging-quants/Llama-3.2-3B-Instruct-Q4_K_M-GGUF",
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

The hardcoded repository ID should be made configurable through Django settings to avoid duplicating model configuration across the codebase.

Copilot uses AI. Check for mistakes.
)
parser.add_argument(
"--filename",
type=str,
default="llama-3.2-3b-instruct-q4_k_m.gguf",
Copy link

Copilot AI Sep 27, 2025

Choose a reason for hiding this comment

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

The hardcoded filename should reference the Django setting MODEL_LLAMA to maintain consistency with the configuration defined in settings/base.py.

Copilot uses AI. Check for mistakes.
help="Model name",
)
parser.add_argument("--force", action="store_true", help="Force download")

def handle(self, *args, **options):
token = os.getenv("HF_TOKEN")
if not token:
raise CommandError("You need to set the HF_TOKEN environment variable")
login(token=token, add_to_git_credential=False)

target_dir = Path(options["dir"])
target_dir.mkdir(parents=True, exist_ok=True)

downloaded_file = hf_hub_download(
repo_id=options["repo"],
filename=options["filename"],
local_dir=str(target_dir),
local_dir_use_symlinks=False,
force_download=options["force"],
resume_download=True,
)
self.stdout.write(self.style.SUCCESS(f"Downloaded {downloaded_file}"))
4 changes: 2 additions & 2 deletions reference/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
from django.core.validators import MinValueValidator, MaxValueValidator
from core.forms import CoreAdminModelForm

# Create your models here

class Reference(CommonControlField, ClusterableModel):
mixed_citation = models.TextField(_("Mixed Citation"), null=False, blank=True)

estatus = models.IntegerField(default=0)

panels = [
FieldPanel('mixed_citation'),
InlinePanel('element_citation')
InlinePanel('element_citation', label=_("Cited Elements"))
]

base_form_class = CoreAdminModelForm
Expand Down
25 changes: 8 additions & 17 deletions reference/wagtail_hooks.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
from django.http import HttpResponseRedirect
from django.utils.translation import gettext_lazy as _
from wagtail_modeladmin.options import (
ModelAdmin,
ModelAdminGroup,
modeladmin_register,
)
from wagtail_modeladmin.views import CreateView
from wagtail.admin.menu import MenuItem
from wagtail.snippets.models import register_snippet
from wagtail.snippets.views.snippets import CreateView, SnippetViewSet

from reference.models import Reference
from reference.tasks import get_reference

from reference.models import (
Reference
)

class ReferenceCreateView(CreateView):
def form_valid(self, form):
Expand All @@ -38,18 +31,16 @@ def form_valid(self, form):



class ReferenceAdmin(ModelAdmin):
class ReferenceAdmin(SnippetViewSet):
model = Reference
create_view_class = ReferenceCreateView
#edit_view_class = ArticleDocxEditView
add_view_class = ReferenceCreateView
menu_label = _("Reference")
menu_icon = "folder"
menu_order = 1
add_to_settings_menu = False # or True to add your model to the Settings sub-menu
exclude_from_explorer = (
False # or True to exclude pages of this type from Wagtail's explorer view
False
)
list_per_page = 20
add_to_admin_menu = True


modeladmin_register(ReferenceAdmin)
register_snippet(ReferenceAdmin)