JC321 commited on
Commit
3c65a0d
·
verified ·
1 Parent(s): 601c3de

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -18
app.py CHANGED
@@ -228,28 +228,55 @@ def chatbot_response(message, history):
228
  # 构建响应前缀(简化版)
229
  response_prefix = ""
230
 
231
- # 显示工具调用(简单文本+可展开输出)
232
  if tool_calls_log:
233
- response_prefix += "**🛠️ Tools Used:**\n\n"
 
 
 
 
 
234
  for idx, tool_call in enumerate(tool_calls_log):
235
- # 工具名称和输入
236
- response_prefix += f"**{idx+1}. `{tool_call['name']}`**\n"
237
- response_prefix += f"- 📥 Input: `{json.dumps(tool_call['arguments'], ensure_ascii=False)}`\n"
238
 
239
- # 输出(可展开)
240
- if 'result' in tool_call:
241
- result_str = json.dumps(tool_call['result'], ensure_ascii=False, indent=2)
242
- # 截断过长结果
243
- if len(result_str) > 500:
244
- result_preview = result_str[:500] + "..."
245
- else:
246
- result_preview = result_str
247
-
248
- response_prefix += f"<details>\n<summary>📤 Output (click to expand)</summary>\n\n```json\n{result_preview}\n```\n</details>\n\n"
249
- else:
250
- response_prefix += "\n"
 
 
 
 
 
251
 
252
- response_prefix += "---\n\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
 
254
  # 流式输出最终答案
255
  yield response_prefix
 
228
  # 构建响应前缀(简化版)
229
  response_prefix = ""
230
 
231
+ # 显示工具调用(带展开/折叠按钮)
232
  if tool_calls_log:
233
+ response_prefix += """<div style='margin-bottom: 15px;'>
234
+ <div style='background: #f0f0f0; padding: 8px 12px; border-radius: 6px; font-weight: 600; color: #333;'>
235
+ 🛠️ Tools Used ({} calls)
236
+ </div>
237
+ """.format(len(tool_calls_log))
238
+
239
  for idx, tool_call in enumerate(tool_calls_log):
240
+ tool_id = f"tool_{idx}_{hash(str(tool_call))}"
 
 
241
 
242
+ # 工具卡片
243
+ response_prefix += f"""<div style='margin: 8px 0; border: 1px solid #ddd; border-radius: 6px; overflow: hidden;'>
244
+ <div style='background: #fff; padding: 10px; cursor: pointer; display: flex; justify-content: space-between; align-items: center;' onclick='toggleTool("{tool_id}")'>
245
+ <div>
246
+ <strong style='color: #2c5aa0;'>📌 {idx+1}. {tool_call['name']}</strong>
247
+ <div style='font-size: 0.85em; color: #666; margin-top: 4px;'>📥 Input: <code>{json.dumps(tool_call['arguments'], ensure_ascii=False)}</code></div>
248
+ </div>
249
+ <span id='arrow_{tool_id}' style='font-size: 1.2em; color: #999;'>▶</span>
250
+ </div>
251
+ <div id='{tool_id}' style='display: none; background: #f9f9f9; padding: 12px; border-top: 1px solid #eee;'>
252
+ <div style='font-size: 0.9em; color: #333;'>
253
+ <strong>📤 Output:</strong>
254
+ <pre style='background: #fff; padding: 10px; border-radius: 4px; overflow-x: auto; margin-top: 6px; font-size: 0.85em; border: 1px solid #e0e0e0;'>{json.dumps(tool_call.get('result', {}), ensure_ascii=False, indent=2)[:1000]}{'...' if len(json.dumps(tool_call.get('result', {}), ensure_ascii=False)) > 1000 else ''}</pre>
255
+ </div>
256
+ </div>
257
+ </div>
258
+ """
259
 
260
+ # JavaScript 函数
261
+ response_prefix += """<script>
262
+ function toggleTool(id) {
263
+ var content = document.getElementById(id);
264
+ var arrow = document.getElementById('arrow_' + id);
265
+ if (content.style.display === 'none') {
266
+ content.style.display = 'block';
267
+ arrow.innerHTML = '▼';
268
+ } else {
269
+ content.style.display = 'none';
270
+ arrow.innerHTML = '▶';
271
+ }
272
+ }
273
+ </script>
274
+ </div>
275
+
276
+ ---
277
+
278
+ """
279
+ response_prefix += "\n"
280
 
281
  # 流式输出最终答案
282
  yield response_prefix