Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 += "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|