from langchain_openai.chat_models import ChatOpenAI from langchain.schema import HumanMessage, SystemMessage, AIMessage import streamlit as st from dotenv import load_dotenv load_dotenv() st.set_page_config( page_title="My Chat GPT", page_icon="🧊", layout="wide", initial_sidebar_state="expanded", menu_items={ 'Get Help': 'https://www.extremelycoolapp.com/help', 'Report a bug': "https://www.extremelycoolapp.com/bug", 'About': "# This is a header. This is an *extremely* cool app!" } ) st.header('This is a header') chatModel = ChatOpenAI(temperature=.8,model="gpt-3.5-turbo", max_tokens=30) if "sessionMessages" not in st.session_state: print("No Session message") st.session_state.sessionMessages = [ SystemMessage("You are a comedian who answers to query in comedy") ] def load_answers(input): st.session_state.sessionMessages.append(HumanMessage(content=input)) result =chatModel(st.session_state.sessionMessages) st.session_state.sessionMessages.append(AIMessage(content=result.content)) return result.content def get_text(): i= st.text_input("You: ", key="input") return i user_input = get_text() submit=st.button("submit") if submit: response = load_answers(user_input) st.subheader("Answer: ") st.write(response)