Repository navigation
Expand file tree
/
Copy pathtest_migration.py
More file actions
138 lines (106 loc) · 3.51 KB
/
Copy pathtest_migration.py
File metadata and controls
138 lines (106 loc) · 3.51 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
#!/usr/bin/env python3
"""Test script to verify Gemini migration and tool calling without Telegram."""
import asyncio
import sys
from pathlib import Path
# Add parent to path for module imports
sys.path.insert(0, str(Path(__file__).parent))
from src.config import Config
from src.gemini_handler import GeminiHandler
from src.database import DatabaseManager
async def test_basic_conversation():
"""Test basic conversation without tools."""
print("=" * 60)
print("TEST 1: Basic Conversation (No Tools)")
print("=" * 60)
config = Config()
gemini = GeminiHandler(config.google_api_key, config.gemini_model)
db = DatabaseManager(config.db_path)
await db.initialize_db()
user_facts = await db.get_user_facts()
print(f"\nUsing model: {config.gemini_model}")
print(f"User: 你好!How do I say 'good morning'?\n")
try:
response = await gemini.process_text(
"你好!How do I say 'good morning'?",
[],
user_facts
)
print(f"Sifu: {response}\n")
print("✅ Basic conversation works!\n")
return True
except Exception as e:
print(f"❌ Error: {e}\n")
return False
async def test_tool_calling():
"""Test autonomous tool calling."""
print("=" * 60)
print("TEST 2: Autonomous Tool Calling")
print("=" * 60)
config = Config()
gemini = GeminiHandler(config.google_api_key, config.gemini_model)
db = DatabaseManager(config.db_path)
await db.initialize_db()
user_facts = await db.get_user_facts()
print(f"\nUser: Add 早晨 to my vocabulary list\n")
try:
response = await gemini.process_text(
"Add 早晨 to my vocabulary list",
[],
user_facts
)
print(f"Sifu: {response}\n")
print("✅ Tool calling works!\n")
return True
except Exception as e:
print(f"❌ Error: {e}\n")
return False
async def test_vocabulary_retrieval():
"""Test vocabulary list retrieval."""
print("=" * 60)
print("TEST 3: Vocabulary List Retrieval")
print("=" * 60)
config = Config()
gemini = GeminiHandler(config.google_api_key, config.gemini_model)
db = DatabaseManager(config.db_path)
await db.initialize_db()
user_facts = await db.get_user_facts()
print(f"\nUser: What's on my vocabulary list?\n")
try:
response = await gemini.process_text(
"What's on my vocabulary list?",
[],
user_facts
)
print(f"Sifu: {response}\n")
print("✅ Vocabulary retrieval works!\n")
return True
except Exception as e:
print(f"❌ Error: {e}\n")
return False
async def main():
"""Run all tests."""
print("\n" + "=" * 60)
print("GEMINI MIGRATION & TOOL TESTING")
print("=" * 60 + "\n")
results = []
# Test 1: Basic conversation
results.append(await test_basic_conversation())
# Test 2: Tool calling
results.append(await test_tool_calling())
# Test 3: Vocabulary retrieval
results.append(await test_vocabulary_retrieval())
# Summary
print("=" * 60)
print("SUMMARY")
print("=" * 60)
passed = sum(results)
total = len(results)
print(f"\n✅ Passed: {passed}/{total}")
if passed == total:
print("\n🎉 ALL TESTS PASSED! Migration successful!")
else:
print(f"\n⚠️ {total - passed} test(s) failed. Check errors above.")
print("\n" + "=" * 60 + "\n")
if __name__ == "__main__":
asyncio.run(main())