PD03 commited on
Commit
45f480f
·
verified ·
1 Parent(s): 1b78660

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -2,13 +2,9 @@ import gradio as gr
2
  import openai
3
  import requests
4
  import json
5
- import asyncio
6
- import aiohttp
7
  from typing import Dict, Any, List, Tuple
8
  from datetime import datetime
9
  import os
10
- import threading
11
- import concurrent.futures
12
 
13
  class MCPClient:
14
  """MCP Client for communicating with the MCP server"""
@@ -352,7 +348,20 @@ def chat_interface(message, history, openai_key, mcp_url):
352
  return history, ""
353
 
354
  try:
355
- response, tool_info = assistant.process_message(message)
 
 
 
 
 
 
 
 
 
 
 
 
 
356
 
357
  # Format response with tool info if available
358
  if tool_info:
@@ -363,7 +372,9 @@ def chat_interface(message, history, openai_key, mcp_url):
363
  history.append([message, full_response])
364
  return history, ""
365
  except Exception as e:
366
- error_response = f"❌ Error: {str(e)}"
 
 
367
  history.append([message, error_response])
368
  return history, ""
369
 
 
2
  import openai
3
  import requests
4
  import json
 
 
5
  from typing import Dict, Any, List, Tuple
6
  from datetime import datetime
7
  import os
 
 
8
 
9
  class MCPClient:
10
  """MCP Client for communicating with the MCP server"""
 
348
  return history, ""
349
 
350
  try:
351
+ print(f"Calling process_message with: {message}")
352
+
353
+ # Make sure we call the synchronous method
354
+ result = assistant.process_message(message)
355
+ print(f"process_message returned: {type(result)} - {result}")
356
+
357
+ # Check if result is a tuple (response, tool_info)
358
+ if isinstance(result, tuple) and len(result) == 2:
359
+ response, tool_info = result
360
+ print(f"Unpacked: response={response}, tool_info={tool_info}")
361
+ else:
362
+ response = str(result)
363
+ tool_info = ""
364
+ print(f"Single result: {response}")
365
 
366
  # Format response with tool info if available
367
  if tool_info:
 
372
  history.append([message, full_response])
373
  return history, ""
374
  except Exception as e:
375
+ import traceback
376
+ error_response = f"❌ Error: {str(e)}\n\nTraceback:\n{traceback.format_exc()}"
377
+ print(f"Error in chat_interface: {error_response}")
378
  history.append([message, error_response])
379
  return history, ""
380