Skip to content

Commit

Permalink
settings and streamlit pills
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdai committed Jul 24, 2024
1 parent 6d8a207 commit 3ff04f5
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.testing.pytestArgs": ["tests"],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
20 changes: 17 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ llama-index-llms-openai = "^0.1.27"
llama-index-agent-openai = "^0.2.9"
streamlit = "^1.36.0"
llama-agents = {version = "^0.0.12", extras = ["kafka"]}
streamlit-pills = "^0.3.0"

[tool.poetry.group.dev.dependencies]
mypy = "^1.10.1"
Expand Down
42 changes: 41 additions & 1 deletion snowflake_cybersyn_demo/apps/streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import streamlit as st
from llama_index.core.llms import ChatMessage, ChatResponseGen
from llama_index.llms.openai import OpenAI
from streamlit_pills import pills


def _llama_index_stream_wrapper(
Expand All @@ -12,14 +13,30 @@ def _llama_index_stream_wrapper(
yield chunk.delta


def _handle_task_submission() -> None:
st.session_state.submitted_pills.append(st.session_state.task_input)


llm = OpenAI(model="gpt-4o-mini")
st.set_page_config(layout="wide")
st.title("Human In The Loop W/ LlamaAgents")

# state management
if "submitted_pills" not in st.session_state:
st.session_state["submitted_pills"] = []
st.session_state["human_required_pills"] = []
st.session_state["completed_pills"] = []


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.")
task_input = st.text_input(
"Task input",
placeholder="Enter a task input.",
key="task_input",
on_change=_handle_task_submission,
)

with middle:
if "messages" not in st.session_state:
Expand All @@ -45,3 +62,26 @@ def _llama_index_stream_wrapper(
st.session_state.messages.append(
{"role": "assistant", "content": response}
)

with right:
if st.session_state.submitted_pills:
submitted_pills = st.session_state.submitted_pills
submitted = pills(
"Submitted",
options=submitted_pills,
key="selected_submitted",
)

if st.session_state.human_required_pills:
human_required = pills(
"Human Required",
st.session_state.human_required_pills,
key="selected_human_required",
)

if st.session_state.completed_pills:
completed = pills(
"Completed",
st.session_state.completed_pills,
key="selected_completed",
)

0 comments on commit 3ff04f5

Please sign in to comment.