-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtest_profiles.py
More file actions
143 lines (105 loc) · 5.29 KB
/
Copy pathtest_profiles.py
File metadata and controls
143 lines (105 loc) · 5.29 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
"""Quick test of semantic fact extraction and profile systems."""
import asyncio
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent
if str(REPO_ROOT) not in sys.path:
sys.path.insert(0, str(REPO_ROOT))
SCRIPT_RECOVERABLE_ERRORS = (
ImportError,
AttributeError,
RuntimeError,
TypeError,
ValueError,
OSError,
asyncio.TimeoutError,
)
from core.memory.profile_manager import ProfileManager # noqa: E402
from core.memory.semantic_fact_extractor import SemanticFactExtractor # noqa: E402
async def test_fact_extraction():
"""Test fact extraction from sample conversations."""
print("\n=== Testing Semantic Fact Extraction ===\n")
extractor = SemanticFactExtractor()
# Sample conversation
user_msg = "I prefer concise responses with bullet points. I'm a backend developer who specializes in Python and Rust."
aura_resp = "I noticed you like clear, organized information. I've learned that you value efficiency and code quality."
facts = extractor.extract_facts(user_msg, aura_resp)
print(f"Extracted {len(facts)} facts:")
for fact in facts:
print(f" • {fact.to_natural_language()}")
print(f" Type: {fact.fact_type.value}, Confidence: {fact.confidence:.0%}")
return len(facts) > 0
async def test_profile_learning():
"""Test profile learning from facts."""
print("\n=== Testing Profile Learning ===\n")
manager = await ProfileManager.get_instance()
# Simulate a conversation
user_msg = "I prefer bullet points. I specialize in Python and Kubernetes."
aura_resp = "I notice you appreciate clarity and technical depth. You work with cloud infrastructure."
user_learned, aura_learned = await manager.learn_from_turn(
user_id="bryan",
user_message=user_msg,
aura_response=aura_resp,
session_id="test"
)
print(f"Learning results: {user_learned} user facts, {aura_learned} self facts")
# Check profiles
user_profile = manager.get_user_profile()
if user_profile:
print("\nUser Profile:")
print(user_profile.summary("bryan"))
aura_profile = manager.get_aura_profile()
if aura_profile:
print("\nAura Self-Profile:")
print(aura_profile.summary())
return user_learned > 0
async def test_context_injection():
"""Test context generation for LLM injection."""
print("\n=== Testing Context Injection ===\n")
manager = await ProfileManager.get_instance()
context = await manager.get_context_injection("bryan")
if context:
print("Generated context block:")
print(context[:500] + ("..." if len(context) > 500 else ""))
return True
else:
print("No context generated (profiles may be empty)")
return False
async def main():
"""Run all tests."""
print("╔════════════════════════════════════════════════════════════╗")
print("║ Semantic Fact Extraction & Profile System Test ║")
print("╚════════════════════════════════════════════════════════════╝")
results = []
try:
# Test 1: Fact extraction
test1 = await test_fact_extraction()
results.append(("Fact Extraction", test1))
# Test 2: Profile learning
test2 = await test_profile_learning()
results.append(("Profile Learning", test2))
# Test 3: Context injection
test3 = await test_context_injection()
results.append(("Context Injection", test3))
except SCRIPT_RECOVERABLE_ERRORS as e:
print(f"\n❌ Test failed with error: {e}")
import traceback
traceback.print_exc()
return False
# Summary
print("\n╔════════════════════════════════════════════════════════════╗")
print("║ Test Summary ║")
print("╠════════════════════════════════════════════════════════════╣")
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "✅ PASS" if result else "❌ FAIL"
print(f"║ {test_name:<40} {status:>15} ║")
print("╠════════════════════════════════════════════════════════════╣")
print(f"║ Total: {passed}/{total} tests passed ║")
print("╚════════════════════════════════════════════════════════════╝")
return passed == total
if __name__ == "__main__":
success = asyncio.run(main())
sys.exit(0 if success else 1)