Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,29 +11,22 @@ def query(payload):
|
|
| 11 |
response.raise_for_status() # Raise an error for bad HTTP responses
|
| 12 |
data = response.json() # Parse the JSON response
|
| 13 |
|
| 14 |
-
# Extract toolOutput
|
| 15 |
-
|
| 16 |
if "agentReasoning" in data:
|
| 17 |
for reasoning in data["agentReasoning"]:
|
| 18 |
if "usedTools" in reasoning:
|
| 19 |
-
|
| 20 |
-
tool_input = tool.get("toolInput", {}).get("input", "")
|
| 21 |
-
tool_output = tool.get("toolOutput", "")
|
| 22 |
-
if tool_input and tool_output:
|
| 23 |
-
resources.append({
|
| 24 |
-
"resource_name": tool_input, # Extracted from toolInput -> input
|
| 25 |
-
"resource": tool_output # Extracted from toolOutput
|
| 26 |
-
})
|
| 27 |
|
| 28 |
-
# Return the full response and
|
| 29 |
-
return {"raw_response": data, "
|
| 30 |
except requests.exceptions.RequestException as e:
|
| 31 |
return {"error": str(e)}
|
| 32 |
|
| 33 |
# Streamlit app
|
| 34 |
def main():
|
| 35 |
-
st.title("
|
| 36 |
-
st.write("Ask any question, and
|
| 37 |
|
| 38 |
# Input box for user query
|
| 39 |
user_input = st.text_input("Enter your question below:")
|
|
@@ -47,15 +40,13 @@ def main():
|
|
| 47 |
"question": user_input,
|
| 48 |
})
|
| 49 |
|
| 50 |
-
# Display the
|
| 51 |
-
st.subheader("
|
| 52 |
-
|
| 53 |
-
if
|
| 54 |
-
|
| 55 |
-
with st.expander(resource["resource_name"]):
|
| 56 |
-
st.write(resource["resource"])
|
| 57 |
else:
|
| 58 |
-
st.write("No
|
| 59 |
|
| 60 |
# Display the raw JSON response in the sidebar
|
| 61 |
st.sidebar.header("Raw JSON Response")
|
|
|
|
| 11 |
response.raise_for_status() # Raise an error for bad HTTP responses
|
| 12 |
data = response.json() # Parse the JSON response
|
| 13 |
|
| 14 |
+
# Extract toolOutput if present in the response
|
| 15 |
+
tool_outputs = []
|
| 16 |
if "agentReasoning" in data:
|
| 17 |
for reasoning in data["agentReasoning"]:
|
| 18 |
if "usedTools" in reasoning:
|
| 19 |
+
tool_outputs.extend(reasoning["usedTools"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# Return the full response and toolOutput
|
| 22 |
+
return {"raw_response": data, "tool_output": tool_outputs}
|
| 23 |
except requests.exceptions.RequestException as e:
|
| 24 |
return {"error": str(e)}
|
| 25 |
|
| 26 |
# Streamlit app
|
| 27 |
def main():
|
| 28 |
+
st.title("DEVI RESEARCH")
|
| 29 |
+
st.write("Ask any question, and the API will provide an answer!")
|
| 30 |
|
| 31 |
# Input box for user query
|
| 32 |
user_input = st.text_input("Enter your question below:")
|
|
|
|
| 40 |
"question": user_input,
|
| 41 |
})
|
| 42 |
|
| 43 |
+
# Display the extracted toolOutput on the main page
|
| 44 |
+
st.subheader("Extracted Tool Output:")
|
| 45 |
+
tool_output = response.get("tool_output", [])
|
| 46 |
+
if tool_output:
|
| 47 |
+
st.write(tool_output)
|
|
|
|
|
|
|
| 48 |
else:
|
| 49 |
+
st.write("No toolOutput data found in the response.")
|
| 50 |
|
| 51 |
# Display the raw JSON response in the sidebar
|
| 52 |
st.sidebar.header("Raw JSON Response")
|