ositamiles commited on
Commit
12dfd0c
·
verified ·
1 Parent(s): eec2cf1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -14,18 +14,30 @@ def query(payload):
14
  # Extract toolOutput and tool details
15
  tool_details = []
16
  if "agentReasoning" in data:
17
- for reasoning in data["agentReasoning"]:
18
- if "usedTools" in reasoning:
19
- for tool in reasoning["usedTools"]:
20
- tool_details.append({
21
- "toolInput": tool.get("toolInput", {}).get("input", ""),
22
- "toolOutput": tool.get("toolOutput", "")
23
- })
 
 
 
 
 
 
 
 
 
 
24
 
25
  # Return the full response and tool details
26
  return {"raw_response": data, "tool_details": tool_details}
27
  except requests.exceptions.RequestException as e:
28
  return {"error": str(e)}
 
 
29
 
30
  # Streamlit app
31
  def main():
@@ -67,9 +79,13 @@ def main():
67
  # Check if toolOutput is a list or dict and pretty print
68
  if isinstance(tool_output, (list, dict)):
69
  st.json(tool_output)
70
- else:
71
  st.write(tool_output)
 
 
72
 
 
 
73
  else:
74
  st.write("No resources found.")
75
 
 
14
  # Extract toolOutput and tool details
15
  tool_details = []
16
  if "agentReasoning" in data:
17
+ for reasoning in data.get("agentReasoning", []):
18
+ for tool in reasoning.get("usedTools", []):
19
+ # Safely extract tool input
20
+ tool_input = ""
21
+ if isinstance(tool.get("toolInput"), dict):
22
+ tool_input = tool["toolInput"].get("input", "")
23
+ elif isinstance(tool.get("toolInput"), str):
24
+ tool_input = tool["toolInput"]
25
+
26
+ # Safely extract tool output
27
+ tool_output = tool.get("toolOutput", "No output available")
28
+
29
+ tool_details.append({
30
+ "tool": tool.get("tool", "Unknown Tool"),
31
+ "toolInput": tool_input,
32
+ "toolOutput": tool_output
33
+ })
34
 
35
  # Return the full response and tool details
36
  return {"raw_response": data, "tool_details": tool_details}
37
  except requests.exceptions.RequestException as e:
38
  return {"error": str(e)}
39
+ except Exception as e:
40
+ return {"error": f"Unexpected error: {str(e)}"}
41
 
42
  # Streamlit app
43
  def main():
 
79
  # Check if toolOutput is a list or dict and pretty print
80
  if isinstance(tool_output, (list, dict)):
81
  st.json(tool_output)
82
+ elif isinstance(tool_output, str):
83
  st.write(tool_output)
84
+ else:
85
+ st.write(str(tool_output))
86
 
87
+ # Optional: Add tool type information
88
+ st.caption(f"Source: {tool.get('tool', 'Unknown')}")
89
  else:
90
  st.write("No resources found.")
91