Skip to content

Commit

Permalink
add a page that only uses api (#14)
Browse files Browse the repository at this point in the history
* add a page that only uses api

* update demo page logic

* improve chat demo

* reimplement websocket demo

* rearrangement & model selection

* add docker image for frontend
  • Loading branch information
bugsz authored Dec 1, 2024
1 parent e64bd3a commit a3b7541
Show file tree
Hide file tree
Showing 10 changed files with 803 additions and 14 deletions.
52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM redis/redis-stack:latest

# Set working directory
WORKDIR /app

# Install git and other dependencies
RUN apt-get update && apt-get install -y \
python3.11 \
python3.11-venv \
python3-pip \
git \
curl \
&& rm -rf /var/lib/apt/lists/*

RUN ln -sf /usr/bin/python3 /usr/bin/python
# Clone repositories
RUN git clone https://github.com/sotopia-lab/sotopia.git && \
git clone https://github.com/sotopia-lab/sotopia-demo.git

# Setup sotopia
RUN cd /app/sotopia && git checkout feature/sotopia-ui-fastapi-websocket && pip install -e .

# Setup sotopia-demo
RUN cd /app/sotopia-demo && git checkout feature/sotopia-demo-with-api

# Install additional dependencies
RUN pip install streamlit redis-om fastapi uvicorn websockets

ENV REDIS_OM_URL="redis://localhost:6379"
ENV OPENAI_API_KEY=$OPENAI_API_KEY

# Only expose Streamlit port
EXPOSE 8501

RUN echo '#!/bin/bash\n\
# Wait for Redis to be ready\n\
while ! redis-cli ping; do\n\
echo "Waiting for Redis..."\n\
sleep 1\n\
done\n\
cd /app/sotopia && nohup python sotopia/ui/fastapi_server.py > /app/api.log 2>&1 &' > /app/run_api.sh && \
chmod +x /app/run_api.sh

# Final command to run all services
CMD redis-stack-server --dir /data --port 6379 & \
sleep 5 && \
/app/run_api.sh && \
cd /app/sotopia-demo && streamlit run app.py --server.port 8501 --server.address 0.0.0.0


# # Set the entry point
# ENTRYPOINT ["/app/start.sh"]
9 changes: 7 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import streamlit as st

from socialstream.chat import chat_demo_omniscient, chat_demo_simple
from socialstream.rendering import rendering_demo
from socialstream.rendering import chat_demo, rendering_demo
from socialstream.utils import initialize_session_state, reset_database


Expand Down Expand Up @@ -35,6 +35,7 @@ def update_database_callback() -> None:
) # set the sidebar width to be wider

DISPLAY_MODE = "Display Episodes"
DISPLAY_STREAM_MODE = "Display Live Chat Stream"
CHAT_SIMPLE_MODE = "Simple Chat"
CHAT_OMNISCIENT_MODE = "Omniscient Chat & Editable Scenario"

Expand Down Expand Up @@ -67,7 +68,8 @@ def update_database_callback() -> None:
# st.rerun()

option = st.sidebar.radio(
"Function", (DISPLAY_MODE, CHAT_SIMPLE_MODE, CHAT_OMNISCIENT_MODE)
"Function",
(DISPLAY_MODE, DISPLAY_STREAM_MODE, CHAT_SIMPLE_MODE, CHAT_OMNISCIENT_MODE),
)
if option != st.session_state.get("mode", None):
# when switching between modes, reset the active agent
Expand All @@ -84,3 +86,6 @@ def update_database_callback() -> None:
elif option == CHAT_OMNISCIENT_MODE:
st.session_state.mode = CHAT_OMNISCIENT_MODE
chat_demo_omniscient()
elif option == DISPLAY_STREAM_MODE:
st.session_state.mode = DISPLAY_STREAM_MODE
chat_demo()
1 change: 1 addition & 0 deletions socialstream/chat/chat_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
MODEL_LIST,
ActionState,
EnvAgentProfileCombo,
format_for_markdown,
initialize_session_state,
set_from_env_agent_profile_combo,
set_settings,
Expand Down
3 changes: 2 additions & 1 deletion socialstream/rendering/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .render_chat_websocket import chat_demo
from .render_episode import rendering_demo

__all__ = ["rendering_demo"]
__all__ = ["rendering_demo", "chat_demo"]
Loading

0 comments on commit a3b7541

Please sign in to comment.