Update app.py
Browse files
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 =
|
| 143 |
if "β" in init_result:
|
| 144 |
history.append([message, init_result])
|
| 145 |
return history, ""
|
| 146 |
|
| 147 |
-
response,
|
| 148 |
-
|
|
|
|
| 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(
|
| 160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|