File size: 1,769 Bytes
b32fbe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
"""
Knowledge Universe β€” Cache Warmup Script
Pre-populates cache with the most common queries.
Usage: python scripts/warmup_cache.py
"""
import asyncio
import httpx
import sys

API_BASE = "http://localhost:8000"
API_KEY  = "ku_test_warmup"  # Replace with valid key

WARMUP_TOPICS = [
    ("machine learning",                   2),
    ("transformer architecture",           3),
    ("RAG retrieval augmented generation", 3),
    ("python data science",                2),
    ("LLMOps deployment",                  4),
    ("credit scoring models",              3),
    ("fraud detection machine learning",   3),
    ("neural networks introduction",       1),
    ("attention mechanism",                3),
    ("vector databases",                   3),
]

async def warmup():
    print(f"Warming up {len(WARMUP_TOPICS)} queries...\n")
    async with httpx.AsyncClient(timeout=60) as client:
        for topic, difficulty in WARMUP_TOPICS:
            try:
                resp = await client.post(
                    f"{API_BASE}/v1/discover",
                    headers={"X-API-Key": API_KEY},
                    json={"topic": topic, "difficulty": difficulty,
                          "formats": ["pdf", "github", "stackoverflow"], "max_results": 5}
                )
                status = "βœ“" if resp.status_code == 200 else "βœ—"
                data = resp.json()
                results = data.get("total_found", 0)
                print(f"{status} [{difficulty}] {topic} β†’ {results} results")
            except Exception as e:
                print(f"βœ— {topic}: {e}")
            await asyncio.sleep(1)   # Be polite to upstream APIs

    print("\nWarmup complete.")

if __name__ == "__main__":
    asyncio.run(warmup())