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