Spaces:
Runtime error
Runtime error
Update app.py
#1
by
nicoladisabato
- opened
app.py
CHANGED
@@ -3,4 +3,34 @@ from langchain.chat_models import ChatOpenAI
|
|
3 |
from langchain.schema import (AIMessage, HumanMessage, SystemMessage)
|
4 |
|
5 |
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
6 |
-
st.header("Hey, I'm your Chat GPT")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from langchain.schema import (AIMessage, HumanMessage, SystemMessage)
|
4 |
|
5 |
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
6 |
+
st.header("Hey, I'm your Chat GPT")
|
7 |
+
|
8 |
+
if "sessionMessages" not in st.session_state:
|
9 |
+
st.session_state.sessionMessages = [SystemMessage(content="You are an helpful assistant.")]
|
10 |
+
|
11 |
+
chat = ChatOpenAI(temperature=0)
|
12 |
+
|
13 |
+
def load_answer(question):
|
14 |
+
|
15 |
+
|
16 |
+
st.session_state.sessionMessages.append(HumanMessage(content=question))
|
17 |
+
|
18 |
+
assistant_answer = chat(st.session_state.sessionMessages)
|
19 |
+
|
20 |
+
st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
|
21 |
+
|
22 |
+
return assistant_answer
|
23 |
+
|
24 |
+
|
25 |
+
def get_text():
|
26 |
+
input_text = st.text_input("You: ", key=input)
|
27 |
+
return input_text
|
28 |
+
|
29 |
+
user_input = get_text()
|
30 |
+
|
31 |
+
submit = st.button("Generate")
|
32 |
+
|
33 |
+
if submit:
|
34 |
+
response = load_answer(user_input)
|
35 |
+
st.subheader("Answer:")
|
36 |
+
st.write(response, key=1)
|