|
|
|
import streamlit as st |
|
from langchain.chat_models import ChatOpenAI |
|
from langchain.schema import SystemMessage, HumanMessage, AIMessage |
|
import instruct |
|
|
|
|
|
st.set_page_config(page_title="Entz's LLM LangChain-OpenAI", page_icon=":robot_face:") |
|
st.markdown("<h1 style='text-align: center; color: navy;'>My Kidbot</h1>", unsafe_allow_html=True) |
|
st.markdown("<h4 style='text-align: center;'>Chat with my 5-Year-Old droid</h4>", unsafe_allow_html=True) |
|
st.markdown("<p style='text-align: right'>By <a href='https://entzyeung.github.io/portfolio/index.html'>Lorentz Yeung</a></p>", unsafe_allow_html=True) |
|
|
|
|
|
|
|
|
|
if "presumptions" not in st.session_state: |
|
st.session_state.presumptions = [ |
|
SystemMessage(content=instruct.instruct) |
|
] |
|
|
|
def load_answer(question): |
|
|
|
st.session_state.presumptions.append(HumanMessage(content=question)) |
|
assistant_answer = chat(st.session_state.presumptions ) |
|
|
|
st.session_state.presumptions.append(AIMessage(content=assistant_answer.content)) |
|
return assistant_answer.content |
|
|
|
|
|
def get_text(): |
|
input_text = st.text_input("Ask me question please~ ", "How old are you little one?", key= input) |
|
return input_text |
|
|
|
chat = ChatOpenAI(temperature=0) |
|
|
|
user_input=get_text() |
|
submit = st.button('Little girl answers: ') |
|
|
|
if submit: |
|
|
|
response = load_answer(user_input) |
|
st.subheader("Answer:") |
|
|
|
st.write(response,key= 1) |
|
|
|
|