Spaces:
Runtime error
Runtime error
jonathanjordan21
commited on
Commit
•
7c83c27
1
Parent(s):
a47a178
Update app.py
Browse files
app.py
CHANGED
@@ -23,8 +23,8 @@ if 'memory' not in st.session_state:
|
|
23 |
st.session_state['memory'] = ConversationBufferMemory(return_messages=True)
|
24 |
|
25 |
if 'chain' not in st.session_state:
|
26 |
-
st.session_state['chain'] = custom_chain_with_history(llm=CustomLLM(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1", model_type='text-generation', api_token=API_TOKEN, stop=["\n<|","<|"]), memory=st.session_state.memory)
|
27 |
-
|
28 |
st.title("LMD Chatbot V2 Sample")
|
29 |
st.subheader("Knowledge-base from web scrapping and FAQ")
|
30 |
|
@@ -44,12 +44,19 @@ if prompt := st.chat_input("Ask me anything.."):
|
|
44 |
# Add user message to chat history
|
45 |
st.session_state.messages.append({"role": "User", "content": prompt})
|
46 |
|
47 |
-
|
48 |
|
49 |
# Display assistant response in chat message container
|
50 |
with st.chat_message("assistant"):
|
51 |
-
st.
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
st.session_state.memory.chat_memory.messages = st.session_state.memory.chat_memory.messages[-15:]
|
54 |
# Add assistant response to chat history
|
55 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
23 |
st.session_state['memory'] = ConversationBufferMemory(return_messages=True)
|
24 |
|
25 |
if 'chain' not in st.session_state:
|
26 |
+
# st.session_state['chain'] = custom_chain_with_history(llm=CustomLLM(repo_id="mistralai/Mixtral-8x7B-Instruct-v0.1", model_type='text-generation', api_token=API_TOKEN, stop=["\n<|","<|"]), memory=st.session_state.memory)
|
27 |
+
st.session_state['chain'] = custom_chain_with_history(llm=InferenceClient("https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1", headers = {"Authorization": f"Bearer {API_TOKEN}"}, stream=True, max_new_tokens=512, temperature=0.01), memory=st.session_state.memory)
|
28 |
st.title("LMD Chatbot V2 Sample")
|
29 |
st.subheader("Knowledge-base from web scrapping and FAQ")
|
30 |
|
|
|
44 |
# Add user message to chat history
|
45 |
st.session_state.messages.append({"role": "User", "content": prompt})
|
46 |
|
47 |
+
# full_response = st.session_state.chain.invoke(prompt).split("\n<|")[0]
|
48 |
|
49 |
# Display assistant response in chat message container
|
50 |
with st.chat_message("assistant"):
|
51 |
+
message_placeholder = st.empty()
|
52 |
+
full_response = ""
|
53 |
+
for chunk in st.session_state.chain.stream(prompt):
|
54 |
+
full_response += chunk + " "
|
55 |
+
message_placeholder.markdown(full_response + " ")
|
56 |
+
if full_response[-4:] == "\n<|":
|
57 |
+
break
|
58 |
+
# st.markdown(full_response)
|
59 |
+
st.session_state.memory.save_context({"question":prompt}, {"output":full_response})
|
60 |
st.session_state.memory.chat_memory.messages = st.session_state.memory.chat_memory.messages[-15:]
|
61 |
# Add assistant response to chat history
|
62 |
st.session_state.messages.append({"role": "assistant", "content": response})
|