Begin adding AI memory
This commit is contained in:
@@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import time
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from core.models import ConversationEvent
|
||||
|
||||
@@ -16,6 +16,8 @@ class Command(BaseCommand):
|
||||
parser.add_argument("--service", default="")
|
||||
parser.add_argument("--user-id", default="")
|
||||
parser.add_argument("--limit", type=int, default=200)
|
||||
parser.add_argument("--require-types", default="")
|
||||
parser.add_argument("--fail-if-empty", action="store_true", default=False)
|
||||
parser.add_argument("--json", action="store_true", default=False)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
@@ -23,7 +25,14 @@ class Command(BaseCommand):
|
||||
service = str(options.get("service") or "").strip().lower()
|
||||
user_id = str(options.get("user_id") or "").strip()
|
||||
limit = max(1, int(options.get("limit") or 200))
|
||||
require_types_raw = str(options.get("require_types") or "").strip()
|
||||
fail_if_empty = bool(options.get("fail_if_empty"))
|
||||
as_json = bool(options.get("json"))
|
||||
required_types = [
|
||||
item.strip().lower()
|
||||
for item in require_types_raw.split(",")
|
||||
if item.strip()
|
||||
]
|
||||
|
||||
cutoff_ts = int(time.time() * 1000) - (minutes * 60 * 1000)
|
||||
queryset = ConversationEvent.objects.filter(ts__gte=cutoff_ts).order_by("-ts")
|
||||
@@ -48,6 +57,11 @@ class Command(BaseCommand):
|
||||
for row in rows:
|
||||
key = str(row.get("event_type") or "")
|
||||
event_type_counts[key] = int(event_type_counts.get(key) or 0) + 1
|
||||
missing_required_types = [
|
||||
event_type
|
||||
for event_type in required_types
|
||||
if int(event_type_counts.get(event_type) or 0) <= 0
|
||||
]
|
||||
|
||||
payload = {
|
||||
"minutes": minutes,
|
||||
@@ -55,6 +69,8 @@ class Command(BaseCommand):
|
||||
"user_id": user_id,
|
||||
"count": len(rows),
|
||||
"event_type_counts": event_type_counts,
|
||||
"required_types": required_types,
|
||||
"missing_required_types": missing_required_types,
|
||||
"sample": rows[:25],
|
||||
}
|
||||
|
||||
@@ -66,3 +82,14 @@ class Command(BaseCommand):
|
||||
f"event-ledger-smoke minutes={minutes} service={service or '-'} user={user_id or '-'} count={len(rows)}"
|
||||
)
|
||||
self.stdout.write(f"event_type_counts={event_type_counts}")
|
||||
if required_types:
|
||||
self.stdout.write(
|
||||
f"required_types={required_types} missing_required_types={missing_required_types}"
|
||||
)
|
||||
|
||||
if fail_if_empty and len(rows) == 0:
|
||||
raise CommandError("No recent ConversationEvent rows found.")
|
||||
if missing_required_types:
|
||||
raise CommandError(
|
||||
"Missing required event types: " + ", ".join(missing_required_types)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user