import streamlit as st #As Langchain team has been working aggresively on improving the tool, we can see a lot of changes happening every weeek, #As a part of it, the below import has been depreciated #from langchain.chat_models import ChatOpenAI #New import from langchain, which replaces the above from langchain_openai import ChatOpenAI #import os #os.environ["OPENAI_API_KEY"] = "sk-PLfFw23dd932dfg34446dftyvvdfgdfgmvXr2dL8hVowXdt" from langchain.schema import ( AIMessage, HumanMessage, SystemMessage ) # From here down is all the StreamLit UI st.set_page_config(page_title="LangChain Demo", page_icon=":robot:") st.header("Hey, I'm your PERSONAL GPT") if "sessionMessages" not in st.session_state: st.session_state.sessionMessages = [ SystemMessage(content="You are a helpful assistant.") ] def load_answer(question): st.session_state.sessionMessages.append(HumanMessage(content=question)) assistant_answer = chat.invoke(st.session_state.sessionMessages ) st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content)) return assistant_answer.content def get_text(): input_text = st.text_input("You: ") return input_text chat = ChatOpenAI(temperature=0) user_input=get_text() submit = st.button('Generate') if submit: response = load_answer(user_input) st.subheader("Answer:") st.write(response)