zypchn commited on
Commit
93e434c
·
verified ·
1 Parent(s): 7ccf27f

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +4 -3
src/streamlit_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, 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,7 +16,7 @@ def get_openai_response(question, api_key):
16
  ("human", user_template)
17
  ])
18
 
19
- chat_llm = ChatOpenAI(temperature=0.5, api_key=api_key)
20
 
21
  chain = chat_prompt | chat_llm
22
 
@@ -29,11 +29,12 @@ 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
 
35
  submit = st.button("Ask your question...")
36
  if submit:
37
- response = get_openai_response(input, api_key=OPENAI_API_KEY)
38
  st.subheader("The response is:")
39
  st.write(response)
 
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
  ("human", user_template)
17
  ])
18
 
19
+ chat_llm = ChatOpenAI(temperature=0.5)
20
 
21
  chain = chat_prompt | chat_llm
22
 
 
29
  st.header("Coder Q&A Demo")
30
 
31
  OPENAI_API_KEY = st.text_input("OpenAI API Key: ", type="password")
32
+ os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
33
 
34
  input = st.text_input("Input: ", key=input)
35
 
36
  submit = st.button("Ask your question...")
37
  if submit:
38
+ response = get_openai_response(input)
39
  st.subheader("The response is:")
40
  st.write(response)