Spaces:
Sleeping
Sleeping
Delete pages/1_💬_basic_chatbot.py
Browse files- pages/1_💬_basic_chatbot.py +0 -39
pages/1_💬_basic_chatbot.py
DELETED
|
@@ -1,39 +0,0 @@
|
|
| 1 |
-
import utils
|
| 2 |
-
import streamlit as st
|
| 3 |
-
from streaming import StreamHandler
|
| 4 |
-
|
| 5 |
-
from langchain_openai import ChatOpenAI
|
| 6 |
-
from langchain.chains.conversation.base import ConversationChain
|
| 7 |
-
|
| 8 |
-
st.set_page_config(page_title="Chatbot", page_icon="💬")
|
| 9 |
-
st.header('Basic Chatbot')
|
| 10 |
-
st.write('Allows users to interact with a Language Model')
|
| 11 |
-
|
| 12 |
-
class BasicChatbot:
|
| 13 |
-
|
| 14 |
-
def __init__(self):
|
| 15 |
-
self.openai_model = utils.configure_openai()
|
| 16 |
-
|
| 17 |
-
def setup_chain(self):
|
| 18 |
-
llm = ChatOpenAI(model_name=self.openai_model, temperature=0, streaming=True)
|
| 19 |
-
chain = ConversationChain(llm=llm, verbose=True)
|
| 20 |
-
return chain
|
| 21 |
-
|
| 22 |
-
@utils.enable_chat_history
|
| 23 |
-
def main(self):
|
| 24 |
-
chain = self.setup_chain()
|
| 25 |
-
user_query = st.chat_input(placeholder="Ask me anything!")
|
| 26 |
-
if user_query:
|
| 27 |
-
utils.display_msg(user_query, 'user')
|
| 28 |
-
with st.chat_message("assistant"):
|
| 29 |
-
st_cb = StreamHandler(st.empty())
|
| 30 |
-
result = chain.invoke(
|
| 31 |
-
{"input":user_query},
|
| 32 |
-
{"callbacks": [st_cb]}
|
| 33 |
-
)
|
| 34 |
-
response = result["response"]
|
| 35 |
-
st.session_state.messages.append({"role": "assistant", "content": response})
|
| 36 |
-
|
| 37 |
-
if __name__ == "__main__":
|
| 38 |
-
obj = BasicChatbot()
|
| 39 |
-
obj.main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|