Update app.py
Browse files
app.py
CHANGED
@@ -38,25 +38,34 @@ question_examples = [
|
|
38 |
|
39 |
# === Helper: extract tool name from content
|
40 |
def extract_tool_name_and_clean_content(raw_content):
|
|
|
|
|
|
|
41 |
if isinstance(raw_content, (dict, list)):
|
|
|
42 |
return "Tool Result", json.dumps(raw_content, indent=2)
|
|
|
43 |
if not isinstance(raw_content, str):
|
|
|
44 |
return "Tool Result", str(raw_content)
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
try:
|
49 |
start = raw_content.index('"name": "') + 9
|
50 |
end = raw_content.index('"', start)
|
51 |
tool_name = raw_content[start:end]
|
52 |
title = f"Tool: {tool_name}"
|
53 |
-
|
|
|
54 |
title = "Tool Result"
|
55 |
-
|
|
|
56 |
title = "Tool Result"
|
|
|
57 |
|
58 |
return title, raw_content.strip()
|
59 |
|
|
|
60 |
# === Helper: formatted collapsible output
|
61 |
def format_collapsible(content, title="Answer"):
|
62 |
return (
|
|
|
38 |
|
39 |
# === Helper: extract tool name from content
|
40 |
def extract_tool_name_and_clean_content(raw_content):
|
41 |
+
import logging
|
42 |
+
logging.basicConfig(level=logging.INFO)
|
43 |
+
|
44 |
if isinstance(raw_content, (dict, list)):
|
45 |
+
logging.info("[extract_tool_name] Content is dict/list — using default title.")
|
46 |
return "Tool Result", json.dumps(raw_content, indent=2)
|
47 |
+
|
48 |
if not isinstance(raw_content, str):
|
49 |
+
logging.info("[extract_tool_name] Content is not string — using default title.")
|
50 |
return "Tool Result", str(raw_content)
|
51 |
|
52 |
+
try:
|
53 |
+
if '"name": "' in raw_content:
|
|
|
54 |
start = raw_content.index('"name": "') + 9
|
55 |
end = raw_content.index('"', start)
|
56 |
tool_name = raw_content[start:end]
|
57 |
title = f"Tool: {tool_name}"
|
58 |
+
logging.info(f"[extract_tool_name] Parsed tool name: {tool_name}")
|
59 |
+
else:
|
60 |
title = "Tool Result"
|
61 |
+
logging.info("[extract_tool_name] No tool name found in content.")
|
62 |
+
except Exception as e:
|
63 |
title = "Tool Result"
|
64 |
+
logging.warning(f"[extract_tool_name] Failed to extract tool name: {e}")
|
65 |
|
66 |
return title, raw_content.strip()
|
67 |
|
68 |
+
|
69 |
# === Helper: formatted collapsible output
|
70 |
def format_collapsible(content, title="Answer"):
|
71 |
return (
|