I am building a chatbot
by using chatgpt3.5
and streamlit
app.
I am able to put Input text (text_input)
at bottom of screen. But as text queries grows my input text area
also goes down.
Frontend code for streamlit_chat
st-chat/stChat.tsx at main · AI-Yash/st-chat · GitHub
Here is the code:
import openai
import streamlit as st
from streamlit_chat import message
openai.api_key='API_KEY'
def generate_response(prompt):
completion=openai.Completion.create(
engine='text-davinci-003',
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.6,
)
message=completion.choices[0].text
return message
st.title("ChatGPT3.5 BOT")
if 'generated' not in st.session_state:
st.session_state['generated'] = []
if 'past' not in st.session_state:
st.session_state['past'] = []
def inputchange():
inp={
"inputs": {
"past_user_inputs": st.session_state.past,
"generated_responses": st.session_state.generated,
"text": st.session_state.input,
},
}
output=generate_response(inp['inputs']['text'])
# append user_input and output to state
st.session_state['past'].append(st.session_state.input)
st.session_state['generated'].append(output)
# If responses have been generated by the model
if st.session_state['generated']:
# Reverse iteration through the list
for i in range(len(st.session_state['generated']) - 1, -1, -1):
# message from streamlit_chat
# message(st.session_state['past'][::-1][i], is_user=True, key=str(i) + '_user', )
message(st.session_state['past'][::-1][i], is_user=True, key=str(i) + '_user', )
message(st.session_state['generated'][::-1][i], key=str(i),avatar_style="adventurer",seed=123,)
user_input = st.text_input("Input Message: ", "", key="input", on_change=inputchange)
How to add scroll for messages
just like ChatGPT3.5 does the messages can be scrolled up instead of scrolling the whole page.
Secondly, If I type same message in user_input
then it doesn’t take this into account.