Spaces:
Sleeping
Sleeping
Download test_extractor.py from killbizz/memorymind: direct link, hf CLI and curl.
- Browser
- Download file 1.92 kB
-
https://huggingface.co/spaces/killbizz/memorymind/resolve/main/test_extractor.py
- Command line
-
hf download hf://spaces/killbizz/memorymind/test_extractor.py
-
curl -L -o test_extractor.py https://huggingface.co/spaces/killbizz/memorymind/resolve/main/test_extractor.py
1.92 kB
| """Quick smoke test for Day 1 — run with: python test_extractor.py""" | |
| from extractor import extract_facts | |
| from memory import ( | |
| add_memory, | |
| delete_all_memories, | |
| get_all_memories, | |
| is_duplicate, | |
| retrieve_relevant, | |
| ) | |
| def test_extraction(): | |
| print("=== Fact Extraction ===") | |
| facts = extract_facts( | |
| user_message="Hi, my name is Stefan and I'm a Python developer. I love working with AI.", | |
| bot_reply="Nice to meet you, Stefan! AI development is fascinating.", | |
| ) | |
| print(f"Extracted {len(facts)} facts:") | |
| for f in facts: | |
| print(f" [{f['type']}] {f['fact']}") | |
| assert len(facts) > 0, "Extractor returned nothing — check GROQ_API_KEY" | |
| return facts | |
| def test_memory_store(facts): | |
| print("\n=== Memory Storage ===") | |
| delete_all_memories() | |
| for f in facts: | |
| mid = add_memory(f["fact"], {"type": f["type"]}) | |
| print(f" Stored: {f['fact']} (id: {mid[:8]}...)") | |
| all_memories = get_all_memories() | |
| print(f" Total in DB: {len(all_memories)}") | |
| assert len(all_memories) == len(facts) | |
| def test_retrieval(): | |
| print("\n=== Semantic Retrieval ===") | |
| results = retrieve_relevant("what does the user do for work?") | |
| print(f" Query: 'what does the user do for work?'") | |
| for r in results: | |
| print(f" → {r['fact']}") | |
| assert len(results) > 0 | |
| def test_deduplication(): | |
| print("\n=== Deduplication ===") | |
| dup = is_duplicate("user's name is Stefan") | |
| print(f" is_duplicate('user's name is Stefan'): {dup} (expected: True)") | |
| not_dup = is_duplicate("user lives in Tokyo and loves sushi") | |
| print(f" is_duplicate('user lives in Tokyo...'): {not_dup} (expected: False)") | |
| assert dup is True | |
| assert not_dup is False | |
| if __name__ == "__main__": | |
| facts = test_extraction() | |
| test_memory_store(facts) | |
| test_retrieval() | |
| test_deduplication() | |
| print("\n✓ All Day 1 tests passed") | |