-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bot.py
More file actions
126 lines (97 loc) · 3.48 KB
/
Copy pathtest_bot.py
File metadata and controls
126 lines (97 loc) · 3.48 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
#!/usr/bin/env python3
"""
Quick test script for Mudrex API Bot
Tests core functionality without running the full bot
"""
import asyncio
import sys
def test_config():
"""Test configuration loading"""
print("1. Testing configuration...")
from src.config import config
errors = config.validate()
if errors:
print(f" ⚠️ Config warnings: {errors}")
print(" (Add TELEGRAM_BOT_TOKEN to .env to run the bot)")
else:
print(" ✓ Configuration valid")
print(f" Model: {config.GEMINI_MODEL}")
print(f" MCP: {'Enabled' if config.MCP_ENABLED else 'Disabled'}")
return True
def test_mcp_tools():
"""Test MCP tool definitions"""
print("\n2. Testing MCP tools...")
from src.mcp import MudrexTools
safe_tools = MudrexTools.get_safe_tools()
conf_tools = MudrexTools.get_confirmation_tools()
print(f" ✓ {len(safe_tools)} safe (read-only) tools")
print(f" ✓ {len(conf_tools)} confirmation-required tools")
# List a few
print(" Safe tools:", list(safe_tools.keys())[:4], "...")
return True
def test_document_loader():
"""Test document loading"""
print("\n3. Testing document loader...")
from src.rag import DocumentLoader
loader = DocumentLoader()
docs = loader.load_from_directory('docs')
if docs:
print(f" ✓ Loaded {len(docs)} documents")
texts, metas, ids = loader.process_documents(docs)
print(f" ✓ Created {len(texts)} chunks")
else:
print(" ⚠️ No documents found in docs/")
return True
async def test_mcp_client():
"""Test MCP client"""
print("\n4. Testing MCP client...")
from src.mcp import MudrexMCPClient
client = MudrexMCPClient()
try:
connected = await client.connect()
print(f" ✓ MCP client ready")
print(f" Authenticated: {client.is_authenticated()}")
print(f" Safe tools: {len(client.get_safe_tools())}")
except Exception as e:
print(f" ⚠️ MCP error: {e}")
finally:
await client.close()
return True
def test_gemini_client():
"""Test Gemini client"""
print("\n5. Testing Gemini client...")
from src.config import config
if not config.GEMINI_API_KEY:
print(" ⚠️ GEMINI_API_KEY not set")
return False
try:
from src.rag import GeminiClient
client = GeminiClient()
print(f" ✓ Gemini client initialized")
except Exception as e:
print(f" ✗ Error: {e}")
return False
return True
def main():
print("=" * 50)
print("Mudrex API Bot - Final Test")
print("=" * 50)
results = []
results.append(("Config", test_config()))
results.append(("MCP Tools", test_mcp_tools()))
results.append(("Documents", test_document_loader()))
results.append(("Gemini", test_gemini_client()))
results.append(("MCP Client", asyncio.run(test_mcp_client())))
print("\n" + "=" * 50)
print("Summary")
print("=" * 50)
passed = sum(1 for _, r in results if r)
for name, result in results:
print(f" {'✓' if result else '✗'} {name}")
print(f"\n{passed}/{len(results)} tests passed")
if passed == len(results):
print("\n🎉 All good! Add TELEGRAM_BOT_TOKEN to .env and run:")
print(" python3 main.py")
return 0 if passed == len(results) else 1
if __name__ == "__main__":
sys.exit(main())