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

Add qs parameters to streamlit app #58

Merged
merged 1 commit into from
Aug 4, 2023
Merged
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
26 changes: 26 additions & 0 deletions prompttools/playground/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,29 @@
"Google PaLM": GooglePaLMCompletionExperiment,
"HuggingFace Hub": HuggingFaceHubExperiment,
}

MODEL_TYPES = (
"OpenAI Chat",
"OpenAI Completion",
"Anthropic",
"Google PaLM",
"LlamaCpp Chat",
"LlamaCpp Completion",
"HuggingFace Hub",
)

OPENAI_CHAT_MODELS = (
"gpt-3.5-turbo",
"gpt-3.5-turbo-16k",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k-0613",
"gpt-3.5-turbo-0301",
"gpt-4",
"gpt-4-0613",
"gpt-4-32k",
"gpt-4-32k-0613",
"gpt-4-0314",
"gpt-4-32k-0314",
)

OPENAI_COMPLETION_MODELS = ("text-davinci-003", "text-davinci-002", "code-davinci-002")
49 changes: 22 additions & 27 deletions prompttools/playground/playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@
except Exception:
pass

from prompttools.playground.constants import MODEL_TYPES, OPENAI_CHAT_MODELS, OPENAI_COMPLETION_MODELS
from prompttools.playground.data_loader import render_prompts, load_data, run_multiple


params = st.experimental_get_query_params()

st.header("PromptTools Playground")
st.write("Give us a \U00002B50 on [GitHub](https://github.com/hegelai/prompttools)")

Expand All @@ -29,16 +33,7 @@

if mode != "Model Comparison":
model_type = st.selectbox(
"Model Type",
(
"OpenAI Chat",
"OpenAI Completion",
"Anthropic",
"Google PaLM",
"LlamaCpp Chat",
"LlamaCpp Completion",
"HuggingFace Hub",
),
"Model Type", MODEL_TYPES, index=MODEL_TYPES.index(params["model_type"][0]) if "model_type" in params else 0
)
model, api_key = None, None
if model_type in {"LlamaCpp Chat", "LlamaCpp Completion"}:
Expand All @@ -55,23 +50,16 @@
elif model_type == "OpenAI Chat":
model = st.selectbox(
"Model",
(
"gpt-3.5-turbo",
"gpt-3.5-turbo-16k",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k-0613",
"gpt-3.5-turbo-0301",
"gpt-4",
"gpt-4-0613",
"gpt-4-32k",
"gpt-4-32k-0613",
"gpt-4-0314",
"gpt-4-32k-0314",
),
OPENAI_CHAT_MODELS,
index=OPENAI_CHAT_MODELS.index(params["model"][0]) if "model" in params else 0,
)
api_key = st.text_input("OpenAI API Key")
elif model_type == "OpenAI g":
model = st.selectbox("Model", ("text-davinci-003", "text-davinci-002", "code-davinci-002"))
elif model_type == "OpenAI Completion":
model = st.selectbox(
"Model",
OPENAI_COMPLETION_MODELS,
index=OPENAI_COMPLETION_MODELS.index(params["model"][0]) if "model" in params else 0,
)
api_key = st.text_input("OpenAI API Key")

variable_count = 0
Expand Down Expand Up @@ -111,6 +99,7 @@
google_api_key = st.text_input("Google PaLM Key")
hf_api_key = st.text_input("HuggingFace Hub Key")


if mode == "Instruction":
placeholders = [[st.empty() for _ in range(instruction_count + 1)] for _ in range(prompt_count)]

Expand All @@ -124,7 +113,7 @@
instructions.append(
st.text_area(
"System Message" if model_type == "OpenAI Chat" else "Instruction",
value="You are a helpful AI assistant.",
value=params["instruction"][0] if "instruction" in params else "You are a helpful AI assistant.",
key=f"col_{j}",
)
)
Expand All @@ -133,7 +122,13 @@
for i in range(prompt_count):
cols = st.columns(instruction_count + 1)
with cols[0]:
prompts.append(st.text_area("User Message" if model_type == "OpenAI Chat" else "Prompt", key=f"row_{i}"))
prompts.append(
st.text_area(
"User Message" if model_type == "OpenAI Chat" else "Prompt",
key=f"row_{i}",
value=params["prompt"][0] if "prompt" in params else "",
)
)
for j in range(1, instruction_count + 1):
with cols[j]:
placeholders[i][j] = st.empty() # placeholders for the future output
Expand Down