Spaces:
Runtime error
Runtime error
Nullzero
commited on
Commit
·
2ab7bbf
1
Parent(s):
36a6d5f
need to fix prompts
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ from streamlit_chat import message
|
|
| 4 |
import os
|
| 5 |
import openai
|
| 6 |
|
| 7 |
-
|
| 8 |
#Import LLM wrapper
|
| 9 |
from langchain.llms import OpenAI
|
| 10 |
#Import Prompt Template
|
|
@@ -16,37 +15,40 @@ from langchain.chains import SimpleSequentialChain
|
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
-
def load_chain():
|
| 20 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 21 |
llm = OpenAI(temperature=0.3)
|
| 22 |
#user_in = input("Please describe your Python project in one to two sentences: ")
|
| 23 |
|
| 24 |
first_prompt = PromptTemplate(
|
| 25 |
input_variables=["user_in"],
|
| 26 |
-
template= "You are a senior Python Engineer. List five steps required to develop the software project specified.
|
| 27 |
)
|
| 28 |
#First chain
|
| 29 |
chain = LLMChain(llm=llm, prompt=first_prompt)
|
| 30 |
|
| 31 |
second_prompt = PromptTemplate(
|
| 32 |
input_variables=["project"],
|
| 33 |
-
template= "Produce the python3 code for each step of the software {project} described. Use appropriate style, classes and variables. Be verbose
|
| 34 |
)
|
| 35 |
|
| 36 |
chain_two = LLMChain(llm=llm, prompt=second_prompt)
|
| 37 |
|
| 38 |
overall_chain = SimpleSequentialChain(chains=[chain, chain_two], verbose=True)
|
| 39 |
|
| 40 |
-
code_output = overall_chain.run(user_in)
|
| 41 |
|
| 42 |
-
return
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
chain = load_chain()
|
| 45 |
|
| 46 |
# From here down is all the StreamLit UI.
|
| 47 |
st.set_page_config(page_title="Python Project Generator", page_icon=":robot:")
|
| 48 |
st.header("Python Project Generator")
|
| 49 |
|
|
|
|
|
|
|
|
|
|
| 50 |
if "generated" not in st.session_state:
|
| 51 |
st.session_state["generated"] = []
|
| 52 |
|
|
@@ -56,18 +58,14 @@ if "past" not in st.session_state:
|
|
| 56 |
|
| 57 |
def get_text():
|
| 58 |
user_input = st.text_input("Please describe your python project in 1-2 sentences", key="input")
|
| 59 |
-
return user_input
|
| 60 |
-
|
| 61 |
-
def get_key():
|
| 62 |
-
get_key = st.text_input("Please enter your OpenAPI API Key", key="input")
|
| 63 |
-
return get_key
|
| 64 |
|
| 65 |
|
| 66 |
-
api_key = get_key()
|
| 67 |
user_input = get_text()
|
| 68 |
|
| 69 |
|
| 70 |
if user_input:
|
|
|
|
| 71 |
output = chain.run(input=user_input)
|
| 72 |
|
| 73 |
st.session_state.past.append(user_input)
|
|
|
|
| 4 |
import os
|
| 5 |
import openai
|
| 6 |
|
|
|
|
| 7 |
#Import LLM wrapper
|
| 8 |
from langchain.llms import OpenAI
|
| 9 |
#Import Prompt Template
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
+
def load_chain(api_key):
|
| 19 |
os.environ["OPENAI_API_KEY"] = api_key
|
| 20 |
llm = OpenAI(temperature=0.3)
|
| 21 |
#user_in = input("Please describe your Python project in one to two sentences: ")
|
| 22 |
|
| 23 |
first_prompt = PromptTemplate(
|
| 24 |
input_variables=["user_in"],
|
| 25 |
+
template= "You are a senior Python Engineer. List five steps required to develop the software project specified. Only include the 5 steps as a high level outline. Explain that this is only a guide. \n\n {user_in}"
|
| 26 |
)
|
| 27 |
#First chain
|
| 28 |
chain = LLMChain(llm=llm, prompt=first_prompt)
|
| 29 |
|
| 30 |
second_prompt = PromptTemplate(
|
| 31 |
input_variables=["project"],
|
| 32 |
+
template= "As the senior engineer, Produce the python3 code for each step of the software {project} described. Use appropriate style, classes and variables. Be verbose in the code and opinionated about framework choice.:"
|
| 33 |
)
|
| 34 |
|
| 35 |
chain_two = LLMChain(llm=llm, prompt=second_prompt)
|
| 36 |
|
| 37 |
overall_chain = SimpleSequentialChain(chains=[chain, chain_two], verbose=True)
|
| 38 |
|
|
|
|
| 39 |
|
| 40 |
+
return overall_chain
|
| 41 |
+
|
| 42 |
+
|
| 43 |
|
|
|
|
| 44 |
|
| 45 |
# From here down is all the StreamLit UI.
|
| 46 |
st.set_page_config(page_title="Python Project Generator", page_icon=":robot:")
|
| 47 |
st.header("Python Project Generator")
|
| 48 |
|
| 49 |
+
st.write("Enter your API key below:")
|
| 50 |
+
openai_api_key = st.text_input("openai_api_key")
|
| 51 |
+
|
| 52 |
if "generated" not in st.session_state:
|
| 53 |
st.session_state["generated"] = []
|
| 54 |
|
|
|
|
| 58 |
|
| 59 |
def get_text():
|
| 60 |
user_input = st.text_input("Please describe your python project in 1-2 sentences", key="input")
|
| 61 |
+
return user_input
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
|
|
|
|
| 64 |
user_input = get_text()
|
| 65 |
|
| 66 |
|
| 67 |
if user_input:
|
| 68 |
+
chain = load_chain(openai_api_key)
|
| 69 |
output = chain.run(input=user_input)
|
| 70 |
|
| 71 |
st.session_state.past.append(user_input)
|