-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# ActasGPT | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import streamlit as st | ||
from streamlit_ace import st_ace | ||
import openai | ||
from utils import input_prompts, get_completion, get_ideal_prompt | ||
|
||
# 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 | ||
|
||
st.title('Act as GPT') | ||
|
||
psw_col, sel_col = st.columns([2, 1]) | ||
|
||
OPENAI_API_KEY = psw_col.text_input("OpenAI API key", type='password') | ||
|
||
model = sel_col.selectbox( | ||
'Model', | ||
('gpt-3.5-turbo', 'gpt-4')) | ||
|
||
st.write('\n') | ||
st.write('\n') | ||
|
||
# initilizing the selectbox with an empty element | ||
input_prompts = [''] + input_prompts.tolist() | ||
|
||
user_input = st.selectbox('Select an input prompt', input_prompts) | ||
st.write('Act as:', user_input) | ||
print(user_input) | ||
|
||
if user_input != "": | ||
last_sentence = None | ||
sentences_counter = -1 | ||
openai.api_key = OPENAI_API_KEY | ||
|
||
# Receiving input from the df | ||
modified_input = get_ideal_prompt(user_input) | ||
sentences = modified_input.split(".") | ||
|
||
# TODO: Debug all the dataset (gpt prompt generator) | ||
|
||
# Find the last sentence containing the word "first" | ||
for sentence in reversed(sentences): | ||
if "first" in sentence.lower().split(): | ||
last_sentence = sentence.strip() | ||
break | ||
else: | ||
sentences_counter -= 1 | ||
|
||
if last_sentence: | ||
input_first_half = ". ".join(sentences[:sentences_counter]) + "." | ||
st.write(input_first_half) | ||
# Create a reactive text area with live update | ||
input_second_half = st.text_area("modified_input", value=last_sentence + ".", key="text_area") | ||
input_text = input_first_half + input_second_half | ||
|
||
if st.button("Run"): | ||
write_col1, write_col2, write_col3 = st.columns([1, 1, 1]) | ||
output = get_completion(input_text, model) | ||
write_col1.write(output) | ||
output = get_completion(input_text, model) | ||
write_col2.write(output) | ||
output = get_completion(input_text, model) | ||
write_col3.write(output) |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pandas as pd | ||
import openai | ||
|
||
prompts_df = pd.read_csv("prompts.csv") | ||
input_prompts = prompts_df["act"] # used in streamlit interface | ||
|
||
|
||
|
||
def get_ideal_prompt(user_prompt): | ||
print(user_prompt) | ||
filtered_rows = prompts_df[prompts_df['act'].isin([user_prompt])] | ||
if not filtered_rows.empty: | ||
ideal_prompt = filtered_rows['prompt'].iloc[0] | ||
return ideal_prompt | ||
|
||
|
||
get_ideal_prompt("Travel Guide") | ||
|
||
|
||
def get_completion(prompt, model="gpt-3.5-turbo"): | ||
if not prompt: | ||
return prompt # Return an empty string if the prompt is invalid | ||
# you will be provided with a prompt to act as someone or something, try to give the most ideal output for an unexpierienced user and epxlain everything from scratch | ||
messages = [ | ||
{"role": "system", | ||
"content": "You will act as an advanced language model. The user wants you to simulate the experience of interacting with the provided prompt."}, | ||
{"role": "user", "content": prompt} | ||
] | ||
response = openai.ChatCompletion.create( | ||
model=model, | ||
messages=messages, | ||
temperature=0.3, | ||
) | ||
return response.choices[0].message["content"] |