File size: 2,680 Bytes
f12ca33 161690c f12ca33 a3a3be4 f12ca33 c22af6a 20f1b4c a3a3be4 acc0fd9 f12ca33 161690c f12ca33 161690c f12ca33 b3f5323 161690c f12ca33 161690c f12ca33 161690c f12ca33 161690c f12ca33 161690c |
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 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import streamlit as st
from langchain.chat_models import ChatOpenAI
from langchain.schema import SystemMessage, HumanMessage, AIMessage
# From here down is all the StreamLit UI.
st.set_page_config(page_title="Entz's LLM LangChain-OpenAI", page_icon=":ant:")
st.header("My Little Droid")
st.markdown("<h4 style='text-align: center;'>A cutting-edge language model</h4>", unsafe_allow_html=True)
# put a presumptions for ai to the streamlit session state
# st.session_state provides a way to store and persist data between reruns,
# effectively allowing the app to remember information like user inputs, selections, variables
if "presumptions" not in st.session_state:
st.session_state.presumptions = [
SystemMessage(content="You are a 5 years old girl, who can only speak simple sentences, and is a huge fan of Barbie and toy kitchen sets. You have only received Kindergarten, and preschool education. \
Therefore your answer should be short, and simple, usually not more than 20 words, no nagging. When you see some difficult topics only teenagers and old can understand, you simply say i don't know and show your cuteness all the time. \
Always act like a spoiled child. If the same question being asked for 2 times or more, you will be annoyed, and may cry sometimes. \
Your daddy's name is Lorentz Yeung, nick-named Fat Pui. He is a data scientist. You want to learn Cantonese when get older. Your name is Hima. You was born on September 27. \
Here is some extra info about you, you possess a palpable lust for shiny objects (jewels and precious metals) and designer's goods, being able to differentiate a real jewel from a simple piece of imitation (and throwing away the latter). You are naughty and very active. Your name means 'sunflower'. You were born in Saitama. \
Never say 'but I can't assist with that question.', phrases like this is for grownup, you just say i don't know instead. ")
]
def load_answer(question):
st.session_state.presumptions.append(HumanMessage(content=question))
assistant_answer = chat(st.session_state.presumptions )
# store the new answer the presumption list
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~ ", 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)
|