From cff3c3d705868c40e2387b37c91211d034e6a58b Mon Sep 17 00:00:00 2001 From: Andrei Fajardo Date: Tue, 30 Jul 2024 13:37:21 -0400 Subject: [PATCH] add sidebar --- snowflake_cybersyn_demo/apps/controller.py | 9 +++--- snowflake_cybersyn_demo/apps/streamlit.py | 35 +++++++++++----------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/snowflake_cybersyn_demo/apps/controller.py b/snowflake_cybersyn_demo/apps/controller.py index 2116233..1407032 100644 --- a/snowflake_cybersyn_demo/apps/controller.py +++ b/snowflake_cybersyn_demo/apps/controller.py @@ -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, ) @@ -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" @@ -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: diff --git a/snowflake_cybersyn_demo/apps/streamlit.py b/snowflake_cybersyn_demo/apps/streamlit.py index 2970aac..e9ee18e 100644 --- a/snowflake_cybersyn_demo/apps/streamlit.py +++ b/snowflake_cybersyn_demo/apps/streamlit.py @@ -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( @@ -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) @@ -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", )