-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_chatbot.py
More file actions
408 lines (333 loc) Β· 14.7 KB
/
test_chatbot.py
File metadata and controls
408 lines (333 loc) Β· 14.7 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/usr/bin/env python3
"""
Grace System Diagnostic Tool
Checks all components to identify what's broken
"""
import os
import sys
import requests
import json
from pathlib import Path
print("=" * 70)
print("GRACE SYSTEM DIAGNOSTIC")
print("=" * 70)
print()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 1. CHECK PYTHON DEPENDENCIES
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
print("1. CHECKING PYTHON DEPENDENCIES")
print("-" * 70)
dependencies = {
'rclpy': False,
'dotenv': False,
'slack_sdk': False,
'requests': False
}
for package in dependencies.keys():
try:
if package == 'dotenv':
from dotenv import load_dotenv
dependencies[package] = True
print(f" β
python-dotenv installed")
elif package == 'slack_sdk':
from slack_sdk import WebClient
dependencies[package] = True
print(f" β
slack-sdk installed")
elif package == 'rclpy':
import rclpy
dependencies[package] = True
print(f" β
rclpy installed")
elif package == 'requests':
import requests
dependencies[package] = True
print(f" β
requests installed")
except ImportError:
print(f" β {package} NOT installed")
if package == 'dotenv':
print(f" Install: pip3 install python-dotenv")
elif package == 'slack_sdk':
print(f" Install: pip3 install slack-sdk")
print()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 2. CHECK ENVIRONMENT VARIABLES
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
print("2. CHECKING ENVIRONMENT VARIABLES")
print("-" * 70)
# Try to load .env
if dependencies['dotenv']:
from dotenv import load_dotenv
load_dotenv()
print(" β
Loaded .env file (if exists)")
else:
print(" β οΈ python-dotenv not available")
# Check Slack token
slack_token = os.getenv('SLACK_BOT_TOKEN', '')
if not slack_token:
print(" β SLACK_BOT_TOKEN not set")
print(" Create .env file with: SLACK_BOT_TOKEN=xoxb-your-token")
elif slack_token.startswith("xoxb-your"):
print(" β οΈ SLACK_BOT_TOKEN is placeholder")
print(" Update with real token from https://api.slack.com/apps")
else:
print(f" β
SLACK_BOT_TOKEN found: {slack_token[:15]}...{slack_token[-4:]}")
# Check Slack channel
slack_channel = os.getenv('SLACK_CHANNEL', '#grace-logs')
print(f" β
SLACK_CHANNEL: {slack_channel}")
print()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 3. CHECK OLLAMA
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
print("3. CHECKING OLLAMA")
print("-" * 70)
ollama_url = "http://localhost:11434"
try:
response = requests.get(f"{ollama_url}/api/tags", timeout=5)
if response.status_code == 200:
print(" β
Ollama is running")
models = response.json().get('models', [])
print(f" β
Found {len(models)} models:")
target_model = "huihui_ai/qwen3-vl-abliterated:4b-instruct-q4_K_M"
model_found = False
for model in models:
name = model.get('name', 'unknown')
size = model.get('size', 0) / (1024**3) # Convert to GB
print(f" - {name} ({size:.1f}GB)")
if target_model in name:
model_found = True
print()
if model_found:
print(f" β
Target model found: {target_model}")
else:
print(f" β οΈ Target model NOT found: {target_model}")
print(f" You need to pull it: ollama pull {target_model}")
else:
print(f" β Ollama returned status {response.status_code}")
except requests.exceptions.ConnectionError:
print(" β Cannot connect to Ollama")
print(" Is Ollama running? Check: curl http://localhost:11434")
except Exception as e:
print(f" β Ollama check failed: {e}")
print()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 4. CHECK SEARXNG (WEB SEARCH)
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
print("4. CHECKING SEARXNG (Web Search)")
print("-" * 70)
searxng_url = "http://127.0.0.1:8080"
try:
response = requests.get(searxng_url, timeout=5)
if response.status_code in [200, 403]:
print(f" β
SearXNG is running (status {response.status_code})")
# Try a test search
try:
search_response = requests.get(
f"{searxng_url}/search",
params={"q": "test", "format": "json"},
timeout=5
)
if search_response.status_code == 200:
results = search_response.json().get('results', [])
print(f" β
Web search working ({len(results)} results for 'test')")
else:
print(f" β οΈ Search returned status {search_response.status_code}")
except Exception as e:
print(f" β οΈ Search test failed: {e}")
else:
print(f" β οΈ SearXNG returned status {response.status_code}")
except requests.exceptions.ConnectionError:
print(" β Cannot connect to SearXNG")
print(" Is SearXNG running? Check: curl http://127.0.0.1:8080")
print(" Web search will be disabled")
except Exception as e:
print(f" β SearXNG check failed: {e}")
print()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 5. CHECK ROS2
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
print("5. CHECKING ROS2")
print("-" * 70)
if dependencies['rclpy']:
try:
import subprocess
result = subprocess.run(['ros2', 'topic', 'list'],
capture_output=True,
text=True,
timeout=5)
if result.returncode == 0:
topics = result.stdout.strip().split('\n')
print(f" β
ROS2 is working ({len(topics)} topics)")
# Check for Grace's topics
grace_topics = {
'/cns/neural_input': False,
'/cns/image_input': False,
'/gce/response': False
}
for topic in topics:
if topic in grace_topics:
grace_topics[topic] = True
print()
print(" Grace topics:")
for topic, found in grace_topics.items():
if found:
print(f" β
{topic}")
else:
print(f" β {topic} (Grace not running)")
else:
print(" β ROS2 command failed")
print(f" Error: {result.stderr}")
except FileNotFoundError:
print(" β ros2 command not found")
print(" Is ROS2 installed and sourced?")
print(" Run: source /opt/ros/humble/setup.bash")
except Exception as e:
print(f" β ROS2 check failed: {e}")
else:
print(" β οΈ rclpy not installed, skipping ROS2 check")
print()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 6. CHECK ROSBRIDGE (for Web Interface)
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
print("6. CHECKING ROSBRIDGE (Web Interface Connection)")
print("-" * 70)
try:
import subprocess
result = subprocess.run(['ros2', 'node', 'list'],
capture_output=True,
text=True,
timeout=5)
if result.returncode == 0:
nodes = result.stdout.strip().split('\n')
rosbridge_found = any('rosbridge' in node for node in nodes)
if rosbridge_found:
print(" β
ROSbridge is running")
print(" Web interface should be able to connect")
else:
print(" β ROSbridge NOT running")
print(" Start it: ros2 launch rosbridge_server rosbridge_websocket_launch.xml")
print(" Without ROSbridge, web interface cannot connect!")
else:
print(" β οΈ Cannot check ROSbridge")
except Exception as e:
print(f" β οΈ ROSbridge check failed: {e}")
print()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 7. CHECK SLACK CONNECTION
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
print("7. CHECKING SLACK CONNECTION")
print("-" * 70)
if dependencies['slack_sdk'] and slack_token and not slack_token.startswith("xoxb-your"):
try:
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
client = WebClient(token=slack_token)
# Test authentication
response = client.auth_test()
print(f" β
Slack authenticated")
print(f" Bot: {response['user']}")
print(f" Team: {response['team']}")
# Try to send test message
try:
test_response = client.chat_postMessage(
channel=slack_channel,
text="π§ͺ Grace diagnostic test - Slack is working!"
)
if test_response['ok']:
print(f" β
Test message sent to {slack_channel}")
else:
print(f" β οΈ Message send returned not OK")
except SlackApiError as e:
error = e.response['error']
print(f" β Message send failed: {error}")
if error == 'channel_not_found':
print(f" Channel {slack_channel} not found")
elif error == 'not_in_channel':
print(f" Bot not in channel {slack_channel}")
print(f" In Slack, type: /invite @{response['user']}")
elif error == 'missing_scope':
print(f" Bot missing permissions")
print(f" Add 'chat:write' scope at https://api.slack.com/apps")
except SlackApiError as e:
print(f" β Slack API error: {e.response['error']}")
except Exception as e:
print(f" β Slack check failed: {e}")
else:
if not dependencies['slack_sdk']:
print(" β οΈ slack-sdk not installed")
elif not slack_token:
print(" β οΈ SLACK_BOT_TOKEN not set")
else:
print(" β οΈ Slack token is placeholder")
print()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 8. CHECK FILE PERMISSIONS
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
print("8. CHECKING FILE SYSTEM")
print("-" * 70)
home = Path.home()
# Check if we can write to home directory
try:
test_file = home / '.grace_test'
test_file.write_text('test')
test_file.unlink()
print(" β
Can write to home directory")
except Exception as e:
print(f" β Cannot write to home: {e}")
# Check for existing Grace files
grace_files = {
'.chat_history.json': home / '.chat_history.json',
'.daily_reflections.json': home / '.daily_reflections.json',
'.env': Path('.env')
}
for name, path in grace_files.items():
if path.exists():
size = path.stat().st_size
print(f" β
{name} exists ({size} bytes)")
else:
print(f" β οΈ {name} not found (will be created)")
print()
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 9. SUMMARY
# βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
print("=" * 70)
print("DIAGNOSTIC SUMMARY")
print("=" * 70)
issues = []
if not dependencies['rclpy']:
issues.append("β rclpy not installed (pip3 install rclpy)")
if not dependencies['dotenv']:
issues.append("β οΈ python-dotenv not installed (pip3 install python-dotenv)")
if not dependencies['slack_sdk']:
issues.append("β οΈ slack-sdk not installed (pip3 install slack-sdk)")
if not slack_token or slack_token.startswith("xoxb-your"):
issues.append("β SLACK_BOT_TOKEN not configured")
# Check Ollama
try:
response = requests.get(f"{ollama_url}/api/tags", timeout=2)
if response.status_code != 200:
issues.append("β Ollama not running")
except:
issues.append("β Ollama not running")
# Check SearXNG
try:
response = requests.get(searxng_url, timeout=2)
if response.status_code not in [200, 403]:
issues.append("β οΈ SearXNG not running (web search disabled)")
except:
issues.append("β οΈ SearXNG not running (web search disabled)")
if issues:
print()
print("ISSUES FOUND:")
for issue in issues:
print(f" {issue}")
print()
print("Fix these issues before running Grace!")
else:
print()
print("β
ALL SYSTEMS OPERATIONAL!")
print()
print("Grace should be ready to run:")
print(" 1. Terminal 1: ros2 launch rosbridge_server rosbridge_websocket_launch.xml")
print(" 2. Terminal 2: python3 grace_final.py")
print(" 3. Terminal 3: python3 flask_server.py")
print(" 4. Browser: http://localhost:5000")
print("=" * 70)