#!/usr/bin/env python3 """WEVIA Learning Loop - Analyze unmatched queries and propose intents""" import json, os, collections LOG = "/var/log/wevia/llm-queries.jsonl" OUT = "/var/log/wevia/proposed-intents.json" if not os.path.exists(LOG): print("No queries logged yet") exit() queries = [] for line in open(LOG): try: queries.append(json.loads(line.strip())) except: pass # Find patterns words = collections.Counter() for q in queries: for w in q.get("q","").lower().split(): if len(w) > 3: words[w] += 1 # Top 20 most common words in unmatched queries top = words.most_common(20) proposals = [] for word, count in top: if count >= 3: # appeared 3+ times proposals.append({"pattern": word, "count": count, "action": "TO_WIRE"}) json.dump({"total_queries": len(queries), "proposals": proposals, "top_words": dict(top)}, open(OUT, "w"), indent=2, ensure_ascii=False) print(f"Analyzed {len(queries)} queries, {len(proposals)} proposals")