Spaces:
Sleeping
Sleeping
Priyanshi Saxena
commited on
Commit
Β·
4c07e01
1
Parent(s):
254afdc
Enhanced status checking and error handling
Browse files- Added detailed logging to status endpoint
- Improved error handling in status check function
- Added retry mechanism for failed status checks
- Enhanced service initialization logging
- Better debugging information in status response
app.py
CHANGED
|
@@ -46,13 +46,20 @@ class Web3CoPilotService:
|
|
| 46 |
def __init__(self):
|
| 47 |
try:
|
| 48 |
logger.info("Initializing Web3 Research Service...")
|
|
|
|
| 49 |
|
| 50 |
if config.GEMINI_API_KEY:
|
| 51 |
logger.info("AI research capabilities enabled")
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
else:
|
| 55 |
-
logger.
|
| 56 |
self.agent = None
|
| 57 |
self.enabled = False
|
| 58 |
|
|
@@ -1199,13 +1206,22 @@ async def get_homepage(request: Request):
|
|
| 1199 |
let messageCount = 0;
|
| 1200 |
|
| 1201 |
async function checkStatus() {
|
|
|
|
| 1202 |
try {
|
| 1203 |
const response = await fetch('/status');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1204 |
const status = await response.json();
|
|
|
|
| 1205 |
|
| 1206 |
const statusDiv = document.getElementById('status');
|
| 1207 |
|
| 1208 |
if (status.enabled && status.gemini_configured) {
|
|
|
|
| 1209 |
statusDiv.className = 'status online';
|
| 1210 |
statusDiv.innerHTML = `
|
| 1211 |
<span>Research systems online</span>
|
|
@@ -1213,7 +1229,8 @@ async def get_homepage(request: Request):
|
|
| 1213 |
Tools: ${status.tools_available.join(' β’ ')}
|
| 1214 |
</div>
|
| 1215 |
`;
|
| 1216 |
-
} else {
|
|
|
|
| 1217 |
statusDiv.className = 'status offline';
|
| 1218 |
statusDiv.innerHTML = `
|
| 1219 |
<span>Limited mode - Configure GEMINI_API_KEY for full functionality</span>
|
|
@@ -1221,11 +1238,22 @@ async def get_homepage(request: Request):
|
|
| 1221 |
Available: ${status.tools_available.join(' β’ ')}
|
| 1222 |
</div>
|
| 1223 |
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1224 |
}
|
| 1225 |
} catch (error) {
|
|
|
|
| 1226 |
const statusDiv = document.getElementById('status');
|
| 1227 |
statusDiv.className = 'status offline';
|
| 1228 |
-
statusDiv.innerHTML =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1229 |
}
|
| 1230 |
}
|
| 1231 |
|
|
@@ -1497,10 +1525,20 @@ async def get_homepage(request: Request):
|
|
| 1497 |
|
| 1498 |
// Initialize
|
| 1499 |
document.addEventListener('DOMContentLoaded', () => {
|
| 1500 |
-
console.log('Application
|
|
|
|
|
|
|
|
|
|
| 1501 |
initializeTheme();
|
| 1502 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1503 |
document.getElementById('queryInput').focus();
|
|
|
|
| 1504 |
});
|
| 1505 |
</script>
|
| 1506 |
</body>
|
|
@@ -1510,16 +1548,40 @@ async def get_homepage(request: Request):
|
|
| 1510 |
|
| 1511 |
@app.get("/status")
|
| 1512 |
async def get_status():
|
| 1513 |
-
"""System status endpoint"""
|
| 1514 |
-
|
| 1515 |
-
|
| 1516 |
-
|
| 1517 |
-
|
| 1518 |
-
|
| 1519 |
-
|
| 1520 |
-
|
| 1521 |
-
|
| 1522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1523 |
|
| 1524 |
@app.post("/query", response_model=QueryResponse)
|
| 1525 |
async def process_query(request: QueryRequest):
|
|
|
|
| 46 |
def __init__(self):
|
| 47 |
try:
|
| 48 |
logger.info("Initializing Web3 Research Service...")
|
| 49 |
+
logger.info(f"Environment check - GEMINI_API_KEY present: {bool(config.GEMINI_API_KEY)}")
|
| 50 |
|
| 51 |
if config.GEMINI_API_KEY:
|
| 52 |
logger.info("AI research capabilities enabled")
|
| 53 |
+
try:
|
| 54 |
+
self.agent = Web3ResearchAgent()
|
| 55 |
+
self.enabled = self.agent.enabled
|
| 56 |
+
logger.info(f"Web3ResearchAgent initialized - enabled: {self.enabled}")
|
| 57 |
+
except Exception as e:
|
| 58 |
+
logger.error(f"Failed to initialize Web3ResearchAgent: {e}")
|
| 59 |
+
self.agent = None
|
| 60 |
+
self.enabled = False
|
| 61 |
else:
|
| 62 |
+
logger.warning("AI research capabilities disabled - GEMINI_API_KEY not configured")
|
| 63 |
self.agent = None
|
| 64 |
self.enabled = False
|
| 65 |
|
|
|
|
| 1206 |
let messageCount = 0;
|
| 1207 |
|
| 1208 |
async function checkStatus() {
|
| 1209 |
+
console.log('Checking system status...');
|
| 1210 |
try {
|
| 1211 |
const response = await fetch('/status');
|
| 1212 |
+
console.log('Status response:', response.status, response.statusText);
|
| 1213 |
+
|
| 1214 |
+
if (!response.ok) {
|
| 1215 |
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
| 1216 |
+
}
|
| 1217 |
+
|
| 1218 |
const status = await response.json();
|
| 1219 |
+
console.log('Status data:', status);
|
| 1220 |
|
| 1221 |
const statusDiv = document.getElementById('status');
|
| 1222 |
|
| 1223 |
if (status.enabled && status.gemini_configured) {
|
| 1224 |
+
console.log('β
System is fully operational');
|
| 1225 |
statusDiv.className = 'status online';
|
| 1226 |
statusDiv.innerHTML = `
|
| 1227 |
<span>Research systems online</span>
|
|
|
|
| 1229 |
Tools: ${status.tools_available.join(' β’ ')}
|
| 1230 |
</div>
|
| 1231 |
`;
|
| 1232 |
+
} else if (status.enabled) {
|
| 1233 |
+
console.log('β οΈ System is in limited mode');
|
| 1234 |
statusDiv.className = 'status offline';
|
| 1235 |
statusDiv.innerHTML = `
|
| 1236 |
<span>Limited mode - Configure GEMINI_API_KEY for full functionality</span>
|
|
|
|
| 1238 |
Available: ${status.tools_available.join(' β’ ')}
|
| 1239 |
</div>
|
| 1240 |
`;
|
| 1241 |
+
} else {
|
| 1242 |
+
console.log('β System is disabled');
|
| 1243 |
+
statusDiv.className = 'status offline';
|
| 1244 |
+
statusDiv.innerHTML = '<span>System disabled</span>';
|
| 1245 |
}
|
| 1246 |
} catch (error) {
|
| 1247 |
+
console.error('β Status check failed:', error);
|
| 1248 |
const statusDiv = document.getElementById('status');
|
| 1249 |
statusDiv.className = 'status offline';
|
| 1250 |
+
statusDiv.innerHTML = `<span>Connection error: ${error.message}</span>`;
|
| 1251 |
+
|
| 1252 |
+
// Retry after 5 seconds
|
| 1253 |
+
setTimeout(() => {
|
| 1254 |
+
console.log('π Retrying status check...');
|
| 1255 |
+
checkStatus();
|
| 1256 |
+
}, 5000);
|
| 1257 |
}
|
| 1258 |
}
|
| 1259 |
|
|
|
|
| 1525 |
|
| 1526 |
// Initialize
|
| 1527 |
document.addEventListener('DOMContentLoaded', () => {
|
| 1528 |
+
console.log('π Web3 Research Co-Pilot - Application initializing...');
|
| 1529 |
+
console.log('π Current URL:', window.location.href);
|
| 1530 |
+
console.log('π User Agent:', navigator.userAgent.substring(0, 100));
|
| 1531 |
+
|
| 1532 |
initializeTheme();
|
| 1533 |
+
|
| 1534 |
+
// Initial status check with delay to ensure server is ready
|
| 1535 |
+
setTimeout(() => {
|
| 1536 |
+
console.log('π Starting status check...');
|
| 1537 |
+
checkStatus();
|
| 1538 |
+
}, 1000);
|
| 1539 |
+
|
| 1540 |
document.getElementById('queryInput').focus();
|
| 1541 |
+
console.log('β
Application initialization complete');
|
| 1542 |
});
|
| 1543 |
</script>
|
| 1544 |
</body>
|
|
|
|
| 1548 |
|
| 1549 |
@app.get("/status")
|
| 1550 |
async def get_status():
|
| 1551 |
+
"""System status endpoint with detailed debugging information"""
|
| 1552 |
+
try:
|
| 1553 |
+
gemini_configured = bool(config.GEMINI_API_KEY)
|
| 1554 |
+
service_enabled = service.enabled
|
| 1555 |
+
agent_available = service.agent is not None
|
| 1556 |
+
|
| 1557 |
+
status = {
|
| 1558 |
+
"enabled": service_enabled,
|
| 1559 |
+
"gemini_configured": gemini_configured,
|
| 1560 |
+
"agent_available": agent_available,
|
| 1561 |
+
"tools_available": ["Market Data", "DeFi Analytics", "Network Metrics"],
|
| 1562 |
+
"airaa_enabled": service.airaa.enabled if service.airaa else False,
|
| 1563 |
+
"timestamp": datetime.now().isoformat(),
|
| 1564 |
+
"version": "2.0.0",
|
| 1565 |
+
"debug_info": {
|
| 1566 |
+
"gemini_key_length": len(config.GEMINI_API_KEY) if config.GEMINI_API_KEY else 0,
|
| 1567 |
+
"service_enabled": service_enabled,
|
| 1568 |
+
"agent_initialized": agent_available
|
| 1569 |
+
}
|
| 1570 |
+
}
|
| 1571 |
+
logger.info(f"Status check - Enabled: {service_enabled}, Gemini: {gemini_configured}")
|
| 1572 |
+
return status
|
| 1573 |
+
except Exception as e:
|
| 1574 |
+
logger.error(f"Status endpoint error: {e}")
|
| 1575 |
+
return {
|
| 1576 |
+
"enabled": False,
|
| 1577 |
+
"gemini_configured": False,
|
| 1578 |
+
"agent_available": False,
|
| 1579 |
+
"tools_available": [],
|
| 1580 |
+
"airaa_enabled": False,
|
| 1581 |
+
"timestamp": datetime.now().isoformat(),
|
| 1582 |
+
"version": "2.0.0",
|
| 1583 |
+
"error": str(e)
|
| 1584 |
+
}
|
| 1585 |
|
| 1586 |
@app.post("/query", response_model=QueryResponse)
|
| 1587 |
async def process_query(request: QueryRequest):
|