-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
27 lines (23 loc) · 896 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import ast
import streamlit as st
from langchain_core.agents import AgentAction
def streamlit_callback(step_output):
"""
This function will be called after each step of the agent's execution.
"""
for step in step_output:
action, observations = step
if isinstance(action, AgentAction):
if action.tool != "_Exception":
st.subheader("Action", divider="violet")
st.json(action.json())
if isinstance(observations, str):
try:
observation = ast.literal_eval(observations)
st.subheader("Observation", divider="violet")
st.json(observation)
except:
st.subheader("Observation", divider="violet")
st.write(observations)
else:
pass