style: ruff format
All checks were successful
CI / lint-and-test (push) Successful in 25s

This commit is contained in:
2026-04-22 10:08:32 +02:00
parent e4bafbc4b0
commit cbd46adaa6
5 changed files with 28 additions and 5 deletions

View File

@@ -56,7 +56,10 @@ async def set_cached_explain(redis, event_id: str, result: dict):
# arq job functions
# ---------------------------------------------------------------------------
async def process_ask_question(ctx, question: str, filters: dict, events: list, total: int, excluded_services: list | None):
async def process_ask_question(
ctx, question: str, filters: dict, events: list, total: int, excluded_services: list | None
):
"""Background job: call LLM for /api/ask and cache result."""
from routes.ask import _call_llm
@@ -92,6 +95,7 @@ async def process_explain_event(ctx, event_id: str, event: dict, related: list):
# arq worker configuration
# ---------------------------------------------------------------------------
async def startup(ctx):
from redis.asyncio import Redis

View File

@@ -813,9 +813,17 @@ async def ask_question(body: AskRequest, user: dict = Depends(require_auth)):
try:
answer = await _call_llm(question, events, total=total, excluded_services=excluded_services)
llm_used = True
await set_cached_ask(redis, question, filters_snapshot, events, {
"answer": answer, "llm_used": True, "llm_error": None,
})
await set_cached_ask(
redis,
question,
filters_snapshot,
events,
{
"answer": answer,
"llm_used": True,
"llm_error": None,
},
)
except Exception as exc:
llm_error = f"LLM call failed: {exc}"
logger.warning("LLM call failed, falling back to structured summary", error=str(exc))

View File

@@ -53,6 +53,7 @@ def client(mock_events_collection, mock_watermarks_collection, monkeypatch):
class FakeRedis:
async def get(self, key):
return None
async def setex(self, key, ttl, value):
pass

View File

@@ -92,6 +92,7 @@ def test_explain_event_with_llm_mock(client, mock_events_collection, monkeypatch
class FakeRedis:
async def get(self, key):
return None
async def setex(self, key, ttl, value):
pass

View File

@@ -405,7 +405,15 @@ class TestAskCaching:
"include_tags": None,
"exclude_tags": None,
}
asyncio.run(set_cached_ask(redis, "What happened to USER-001?", filters_snapshot, [{"id": "evt-cache"}], {"answer": "Cached answer!", "llm_used": True, "llm_error": None}))
asyncio.run(
set_cached_ask(
redis,
"What happened to USER-001?",
filters_snapshot,
[{"id": "evt-cache"}],
{"answer": "Cached answer!", "llm_used": True, "llm_error": None},
)
)
async def fake_get_arq_pool():
return redis
@@ -451,6 +459,7 @@ class TestAskCaching:
async def enqueue_job(self, func, *args, **kwargs):
from unittest.mock import MagicMock
job = MagicMock()
job.job_id = "job-12345"
self.enqueued.append((func, args, kwargs))