Cascade Bot commited on
Commit
4ac9be9
·
1 Parent(s): b4bc78c

fix: improve error handling

Browse files

- Added proper handling for UnifiedResult objects
- Improved response formatting
- Better error messages

Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -363,7 +363,7 @@ class ChatInterface:
363
  """Analyze user message intent with error handling."""
364
  try:
365
  # Use reasoning engine to analyze intent
366
- analysis = await self.reasoning_engine.reason(
367
  query=message,
368
  context={
369
  "chat_history": self.chat_history,
@@ -371,11 +371,21 @@ class ChatInterface:
371
  }
372
  )
373
 
374
- return analysis
 
 
 
 
 
 
 
 
 
 
375
 
376
  except Exception as e:
377
  logger.error(f"Error analyzing intent: {str(e)}")
378
- return {"type": "unknown", "error": str(e)}
379
 
380
  async def _handle_objective(self, message: str, intent: Dict[str, Any]) -> str:
381
  """Handle objective creation and management."""
@@ -403,7 +413,7 @@ class ChatInterface:
403
  """Handle general chat interactions with error recovery."""
404
  try:
405
  # Use reasoning engine for response generation
406
- response = await self.reasoning_engine.reason(
407
  query=message,
408
  context={
409
  "chat_history": self.chat_history,
@@ -411,7 +421,13 @@ class ChatInterface:
411
  }
412
  )
413
 
414
- return response.get('response', "I'm not sure how to respond to that.")
 
 
 
 
 
 
415
 
416
  except Exception as e:
417
  logger.error(f"Error in chat response: {str(e)}")
 
363
  """Analyze user message intent with error handling."""
364
  try:
365
  # Use reasoning engine to analyze intent
366
+ result = await self.reasoning_engine.reason(
367
  query=message,
368
  context={
369
  "chat_history": self.chat_history,
 
371
  }
372
  )
373
 
374
+ # Handle UnifiedResult object
375
+ if isinstance(result, UnifiedResult):
376
+ return {
377
+ "type": "chat",
378
+ "confidence": getattr(result, 'confidence', 0.5),
379
+ "metadata": getattr(result, 'metadata', {})
380
+ }
381
+ elif isinstance(result, dict):
382
+ return result
383
+ else:
384
+ return {"type": "chat", "confidence": 0.5}
385
 
386
  except Exception as e:
387
  logger.error(f"Error analyzing intent: {str(e)}")
388
+ return {"type": "chat", "error": str(e)}
389
 
390
  async def _handle_objective(self, message: str, intent: Dict[str, Any]) -> str:
391
  """Handle objective creation and management."""
 
413
  """Handle general chat interactions with error recovery."""
414
  try:
415
  # Use reasoning engine for response generation
416
+ result = await self.reasoning_engine.reason(
417
  query=message,
418
  context={
419
  "chat_history": self.chat_history,
 
421
  }
422
  )
423
 
424
+ # Handle UnifiedResult object
425
+ if isinstance(result, UnifiedResult):
426
+ return result.response if hasattr(result, 'response') else str(result)
427
+ elif isinstance(result, dict):
428
+ return result.get('response', str(result))
429
+ else:
430
+ return str(result)
431
 
432
  except Exception as e:
433
  logger.error(f"Error in chat response: {str(e)}")