PD03 commited on
Commit
4265ed3
Β·
verified Β·
1 Parent(s): 93dde6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -136,16 +136,17 @@ async def initialize_assistant(openai_key, mcp_url):
136
  await assistant.initialize()
137
  return f"βœ… Initialized with {len(assistant.available_tools)} tools"
138
 
139
- def chat_interface(message, history, openai_key, mcp_url):
140
  global assistant
141
  if not assistant:
142
- init_result = asyncio.run(initialize_assistant(openai_key, mcp_url))
143
  if "❌" in init_result:
144
  history.append([message, init_result])
145
  return history, ""
146
 
147
- response, _ = asyncio.run(assistant.process_message(message))
148
- history.append([message, response])
 
149
  return history, ""
150
 
151
  with gr.Blocks() as demo:
@@ -156,7 +157,12 @@ with gr.Blocks() as demo:
156
  mcp_url = gr.Textbox(label="MCP Server URL")
157
 
158
  submit_btn = gr.Button("Send")
159
- submit_btn.click(chat_interface, [msg, chatbot, openai_key, mcp_url], [chatbot, msg])
160
- msg.submit(chat_interface, [msg, chatbot, openai_key, mcp_url], [chatbot, msg])
 
 
 
 
161
 
162
  demo.launch()
 
 
136
  await assistant.initialize()
137
  return f"βœ… Initialized with {len(assistant.available_tools)} tools"
138
 
139
+ async def chat_interface(message, history, openai_key, mcp_url):
140
  global assistant
141
  if not assistant:
142
+ init_result = await initialize_assistant(openai_key, mcp_url)
143
  if "❌" in init_result:
144
  history.append([message, init_result])
145
  return history, ""
146
 
147
+ response, tool_info = await assistant.process_message(message)
148
+ full_response = f"{response}\n\n{tool_info}" if tool_info else response
149
+ history.append([message, full_response])
150
  return history, ""
151
 
152
  with gr.Blocks() as demo:
 
157
  mcp_url = gr.Textbox(label="MCP Server URL")
158
 
159
  submit_btn = gr.Button("Send")
160
+ submit_btn.click(
161
+ chat_interface, [msg, chatbot, openai_key, mcp_url], [chatbot, msg]
162
+ )
163
+ msg.submit(
164
+ chat_interface, [msg, chatbot, openai_key, mcp_url], [chatbot, msg]
165
+ )
166
 
167
  demo.launch()
168
+