Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ from langchain.prompts.chat import ChatPromptTemplate
|
|
| 8 |
|
| 9 |
## Load Anthropic model and get response
|
| 10 |
|
| 11 |
-
def get_openai_response(question):
|
| 12 |
system_template = "You are a helpful coder assistant. When the user asks a question, your task is to write simple Python codes."
|
| 13 |
user_template = "{question}"
|
| 14 |
chat_prompt = ChatPromptTemplate.from_messages([
|
|
@@ -16,7 +16,7 @@ def get_openai_response(question):
|
|
| 16 |
("human", user_template)
|
| 17 |
])
|
| 18 |
|
| 19 |
-
chat_llm = ChatOpenAI(temperature=0.5)
|
| 20 |
|
| 21 |
chain = chat_prompt | chat_llm
|
| 22 |
|
|
@@ -28,8 +28,10 @@ def get_openai_response(question):
|
|
| 28 |
st.set_page_config(page_title="Simple Langchain App")
|
| 29 |
st.header("Coder Q&A Demo")
|
| 30 |
|
|
|
|
|
|
|
| 31 |
input = st.text_input("Input: ", key=input)
|
| 32 |
-
response = get_openai_response(input)
|
| 33 |
|
| 34 |
submit = st.button("Ask your question...")
|
| 35 |
if submit:
|
|
|
|
| 8 |
|
| 9 |
## Load Anthropic model and get response
|
| 10 |
|
| 11 |
+
def get_openai_response(question, api_key):
|
| 12 |
system_template = "You are a helpful coder assistant. When the user asks a question, your task is to write simple Python codes."
|
| 13 |
user_template = "{question}"
|
| 14 |
chat_prompt = ChatPromptTemplate.from_messages([
|
|
|
|
| 16 |
("human", user_template)
|
| 17 |
])
|
| 18 |
|
| 19 |
+
chat_llm = ChatOpenAI(temperature=0.5, openai_api_key=api_key)
|
| 20 |
|
| 21 |
chain = chat_prompt | chat_llm
|
| 22 |
|
|
|
|
| 28 |
st.set_page_config(page_title="Simple Langchain App")
|
| 29 |
st.header("Coder Q&A Demo")
|
| 30 |
|
| 31 |
+
OPENAI_API_KEY = st.text_input("OpenAI API Key: ", type="password")
|
| 32 |
+
|
| 33 |
input = st.text_input("Input: ", key=input)
|
| 34 |
+
response = get_openai_response(input, api_key=OPENAI_API_KEY)
|
| 35 |
|
| 36 |
submit = st.button("Ask your question...")
|
| 37 |
if submit:
|