fix(admin): LLM provider/model switching now reads DB overrides correctly
- get_llm_provider() now accepts provider + model args so DB overrides propagate through to all provider constructors (was always reading env vars, ignoring the admin UI selection) - /test-llm replaced with lightweight ping (max_tokens=20) instead of running a full bill analysis; shows model name + reply, no truncation - /api/settings/llm-models endpoint fetches available models live from each provider's API (OpenAI, Anthropic REST, Gemini, Ollama) - Admin UI model picker dynamically populated from provider API; falls back to manual text input on error; Custom model name option kept - Default Gemini model updated: gemini-1.5-pro → gemini-2.0-flash Co-Authored-By: Jack Levy
This commit is contained in:
@@ -60,7 +60,13 @@ def process_document_with_llm(self, document_id: int):
|
||||
.first()
|
||||
)
|
||||
|
||||
provider = get_llm_provider()
|
||||
from app.models.setting import AppSetting
|
||||
prov_row = db.get(AppSetting, "llm_provider")
|
||||
model_row = db.get(AppSetting, "llm_model")
|
||||
provider = get_llm_provider(
|
||||
prov_row.value if prov_row else None,
|
||||
model_row.value if model_row else None,
|
||||
)
|
||||
|
||||
if previous_full_brief and previous_full_brief.document_id:
|
||||
# New version of a bill we've already analyzed — generate amendment brief
|
||||
@@ -97,6 +103,9 @@ def process_document_with_llm(self, document_id: int):
|
||||
|
||||
logger.info(f"{brief_type.capitalize()} brief {db_brief.id} created for bill {doc.bill_id} using {brief.llm_provider}/{brief.llm_model}")
|
||||
|
||||
# Emit notification events for users who follow this bill
|
||||
_emit_notification_events(db, bill, doc.bill_id, brief_type, brief.summary)
|
||||
|
||||
# Trigger news fetch now that we have topic tags
|
||||
from app.workers.news_fetcher import fetch_news_for_bill
|
||||
fetch_news_for_bill.delay(doc.bill_id)
|
||||
@@ -111,6 +120,35 @@ def process_document_with_llm(self, document_id: int):
|
||||
db.close()
|
||||
|
||||
|
||||
def _emit_notification_events(db, bill, bill_id: str, brief_type: str, summary: str | None) -> None:
|
||||
"""Create a NotificationEvent row for every user following this bill."""
|
||||
from app.models.follow import Follow
|
||||
from app.models.notification import NotificationEvent
|
||||
from app.config import settings
|
||||
|
||||
followers = db.query(Follow).filter_by(follow_type="bill", follow_value=bill_id).all()
|
||||
if not followers:
|
||||
return
|
||||
|
||||
base_url = (settings.PUBLIC_URL or settings.LOCAL_URL).rstrip("/")
|
||||
payload = {
|
||||
"bill_title": bill.short_title or bill.title or "",
|
||||
"bill_label": f"{bill.bill_type.upper()} {bill.bill_number}",
|
||||
"brief_summary": (summary or "")[:300],
|
||||
"bill_url": f"{base_url}/bills/{bill_id}",
|
||||
}
|
||||
event_type = "new_amendment" if brief_type == "amendment" else "new_document"
|
||||
|
||||
for follow in followers:
|
||||
db.add(NotificationEvent(
|
||||
user_id=follow.user_id,
|
||||
bill_id=bill_id,
|
||||
event_type=event_type,
|
||||
payload=payload,
|
||||
))
|
||||
db.commit()
|
||||
|
||||
|
||||
@celery_app.task(bind=True, name="app.workers.llm_processor.backfill_brief_citations")
|
||||
def backfill_brief_citations(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user