I’m building a chatbot using the openai api library and thought it would be easier if I use the streamlit library to code some basic front end.
My code has its variables in Portuguese but I need some help to make my chat work.
That’s the code method:
# laço da conversa
while True:
user_message = st.chat_input(key=f"user_{i}")
if user_message.lower() == "sair":
print("conversa encerrada")
break
st.chat_message(f"Você: {user_message}")
# cria as mensagens para enviar a API
historico.append({"role": "user", "content": user_message})
# gera resposta
resposta = get_completion([msg['content'] for msg in historico])
historico.append({"role": "assistant", "content": resposta})
st.text(f"AI: {resposta}", key=f"assistant_{i}")
i += 1
if __name__ == '__main__':
main()
I just need the code to be like a chat bot but in a basic way.