Skip to content

Commit

Permalink
3 col layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdai committed Jul 24, 2024
1 parent f0981f1 commit 6d8a207
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions snowflake_cybersyn_demo/apps/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,36 @@ def _llama_index_stream_wrapper(
yield chunk.delta


st.title("ChatGPT-like clone")

llm = OpenAI(model="gpt-4o-mini")

if "messages" not in st.session_state:
st.session_state.messages = []

for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])

if prompt := st.chat_input("What is up?"):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)

with st.chat_message("assistant"):
stream = llm.stream_chat(
messages=[
ChatMessage(role=m["role"], content=m["content"])
for m in st.session_state.messages
]
st.set_page_config(layout="wide")
st.title("Human In The Loop W/ LlamaAgents")

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

with left:
task_input = st.text_input("Task input", placeholder="Enter a task input.")

with middle:
if "messages" not in st.session_state:
st.session_state.messages = []

for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])

if prompt := st.chat_input("What is up?"):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)

with st.chat_message("assistant"):
stream = llm.stream_chat(
messages=[
ChatMessage(role=m["role"], content=m["content"])
for m in st.session_state.messages
]
)
response = st.write_stream(_llama_index_stream_wrapper(stream))
st.session_state.messages.append(
{"role": "assistant", "content": response}
)
response = st.write_stream(_llama_index_stream_wrapper(stream))
st.session_state.messages.append(
{"role": "assistant", "content": response}
)

0 comments on commit 6d8a207

Please sign in to comment.