Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is an attempt to give loopGPT a UI using streamlit. #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions runui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import streamlit as st
from loopgpt.agent import Agent

def custom_agent_cli(agent, continuous=False, user_input=None):
agent_cmd = agent.cli(continuous=continuous)
while agent_cmd["status"] == "awaiting_input":
if user_input is not None:
agent_cmd = agent.continue_cli(user_input)
user_input = None
else:
break
return agent_cmd

st.title("LoopGPT Agent")

# Create an instance of the LoopGPT Agent
model = st.selectbox(
"Select the GPT model to use:",
("gpt-3.5-turbo", "gpt-4")
)
agent = Agent(model=model)

# Set the attributes of the Agent
name = st.text_input("Agent name", "DevGPT")
description = st.text_area("Agent description", "an AI assistant that write complete programs in any coding languages")
goals = st.text_area("Agent goals", "- A Windows app/widget is being developed to display an overlay of clocks for sleep cycles. The average sleep cycle lasts about 90 minutes, and it is recommended to have four to six cycles of sleep every 24 hours for optimal rest and rejuvenation. The sleep cycle app/widget for Windows will provide users with an easy-to-use tool to track and visualize their sleep cycles, helping them achieve better sleep and overall well-being. The user will input their desired wakeup time, and the clock will show optimal times to go to bed, with the nearest bed time to the current time is highlighted in red. Write the necessary code in C# and also provide a clean a modern design in xaml format so I can just paste both in Micorsoft Visual Studio 2022")

response_key = st.empty()

# Execute the Agent's CLI step by step
execute_steps = False
if st.button("Step through Agent CLI"):
execute_steps = True
# You can exit the CLI by typing "exit".
if st.button("Stop execution"):
execute_steps = False
st.write("Agent CLI execution stopped.")


continuous_execution = st.checkbox("Run continuously")

if execute_steps:
# Update the agent's attributes
agent.name = name
agent.description = description
agent.goals = goals.splitlines()

st.write("Starting Agent CLI...")
agent_cmd = custom_agent_cli(agent, continuous=continuous_execution, user_input=None)
while agent_cmd["status"] == "awaiting_input":
st.write(agent_cmd["prompt"])

if "Execute? (Y/N/Y:n to execute n steps continuously):" in agent_cmd["prompt"]:
user_input = response_key.text_input("Enter your response (Y, N, or Y:n):")
else:
user_input = response_key.text_input("Enter your response:")

agent_cmd = agent.continue_cli(user_input)

if agent_cmd["status"] == "success":
st.write("Agent CLI successfully executed!")
break
elif agent_cmd["status"] == "error":
st.error(agent_cmd["message"])
break
response_key.empty()
else:
st.write("Click the 'Step through Agent CLI' button to execute the Agent's CLI step by step.")
53 changes: 53 additions & 0 deletions runui_old.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
import streamlit as st
from loopgpt.agent import Agent

st.set_page_config(page_title="LoopGPT UI", page_icon=":robot_face:", layout="wide")

st.title("LoopGPT UI")

st.write("Welcome to the LoopGPT UI! Your AI assistant is here to help you research and find the best tech products.")

# Sidebar inputs
st.sidebar.title("Agent Configuration")
model_choice = st.sidebar.selectbox("Select the model:", ["gpt-3.5-turbo", "gpt-4"])
agent_name = st.sidebar.text_input("Agent Name:", value="ResearchGPT")
agent_description = st.sidebar.text_input("Agent Description:", value="an AI assistant that researches and finds the best tech products")
goal_input = st.sidebar.text_area("Agent Goals (one per line):", value="Search for the best headphones on Google\nAnalyze specs, prices and reviews to find the top 5 best headphones\nWrite the list of the top 5 best headphones and their prices to a file\nSummarize the pros and cons of each headphone and write it to a different file called 'summary.txt'")

# Set up the LoopGPT Agent
agent = Agent(model=model_choice)
agent.name = agent_name
agent.description = agent_description
agent.goals = [goal.strip() for goal in goal_input.split("\n")]

# Display agent information
st.sidebar.write("**Current Agent Information**")
st.sidebar.write(f"**Name:** {agent.name}")
st.sidebar.write(f"**Description:** {agent.description}")
st.sidebar.write("**Goals:**")
for goal in agent.goals:
st.sidebar.write(f"- {goal}")

# Main input and interaction loop
conversation_history = []
user_input = st.text_input("Type your question or command here:")

if user_input:
conversation_history.append(("User", user_input))

start_agent_button = st.button("Start Agent")

def simulate_agent_cli(agent, user_input):
response = agent.ask(user_input)
return response

if start_agent_button and conversation_history:
user_input = conversation_history[-1][1]
response = simulate_agent_cli(agent, user_input)
conversation_history.append((agent.name, response))
st.write(f"{agent.name}: {response}")

st.write("### Conversation History")
for speaker, message in conversation_history:
st.write(f"{speaker}: {message}")