Skip to content

Commit

Permalink
add sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdai committed Jul 30, 2024
1 parent dea615b commit cff3c3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
9 changes: 4 additions & 5 deletions snowflake_cybersyn_demo/apps/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ def handle_task_submission(self) -> None:
input=task_input,
history=[
ChatMessage(role="user", content=task_input),
ChatMessage(
role="assistant",
content=f"Successfully submitted task: {task_id}.",
),
],
status=TaskStatus.SUBMITTED,
)
Expand Down Expand Up @@ -138,7 +134,9 @@ def update_associated_task_to_human_required_status(
except StopIteration:
raise ValueError("Cannot find task in list of tasks.")

def get_task_selection_handler(self, task_df: pd.DataFrame) -> Callable:
def get_task_selection_handler(
self, task_df: pd.DataFrame, display_chat_window: Callable
) -> Callable:
def task_selection_handler() -> None:
dataframe_selection_state = st.session_state.task_df["selection"][
"rows"
Expand Down Expand Up @@ -166,6 +164,7 @@ def task_selection_handler() -> None:
try:
task = next(t for t in task_list if t.task_id == task_id)
st.session_state.current_task = task
display_chat_window()
logger.info("Displaying selected tasks history.")
logger.info(f"messages: {st.session_state.messages}")
except StopIteration:
Expand Down
35 changes: 18 additions & 17 deletions snowflake_cybersyn_demo/apps/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async def start_consuming_finalized_tasks(
st.session_state.current_task = None


left, right = st.columns([1, 2], vertical_alignment="bottom")
left, right = st.columns([1, 2], vertical_alignment="top")

with left:
task_input = st.text_input(
Expand All @@ -144,21 +144,22 @@ async def start_consuming_finalized_tasks(
)


with right:
messages_container = st.container(height=300)
with messages_container:
if st.session_state.current_task:
messages = [
m.dict() for m in st.session_state.current_task.history
]
for message in messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
else:
st.empty()

if prompt := st.chat_input("What is up?"):
pass
def chat_window() -> None:
with st.sidebar:
messages_container = st.container(height=500)
with messages_container:
if st.session_state.current_task:
messages = [
m.dict() for m in st.session_state.current_task.history
]
for message in messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
else:
st.empty()

if _ := st.chat_input("What is up?"):
pass
# st.session_state.messages.append({"role": "user", "content": prompt})
# with st.chat_message("user"):
# st.markdown(prompt)
Expand Down Expand Up @@ -203,7 +204,7 @@ def task_df() -> None:
hide_index=True,
selection_mode="single-row",
use_container_width=True,
on_select=controller.get_task_selection_handler(df),
on_select=controller.get_task_selection_handler(df, chat_window),
key="task_df",
)

Expand Down

0 comments on commit cff3c3d

Please sign in to comment.