Spaces:
Sleeping
Sleeping
[email protected]
commited on
Commit
·
3536eb7
1
Parent(s):
6d04ff3
feat: add document retrieval functionality and display in chatbot interface
Browse files- app.py +1 -0
- pages/chatbot.py +15 -0
- rag.py +3 -0
app.py
CHANGED
|
@@ -22,6 +22,7 @@ def init_app():
|
|
| 22 |
pinecone_connector = PineconeConnector()
|
| 23 |
vs_manager = VectoreStoreManager(pinecone_connector)
|
| 24 |
|
|
|
|
| 25 |
st.session_state["messages"] = []
|
| 26 |
st.session_state["assistant"] = Rag(vectore_store=vs_manager)
|
| 27 |
st.session_state["data_dict"] = config['variables']
|
|
|
|
| 22 |
pinecone_connector = PineconeConnector()
|
| 23 |
vs_manager = VectoreStoreManager(pinecone_connector)
|
| 24 |
|
| 25 |
+
st.session_state["retrived_documents"] = []
|
| 26 |
st.session_state["messages"] = []
|
| 27 |
st.session_state["assistant"] = Rag(vectore_store=vs_manager)
|
| 28 |
st.session_state["data_dict"] = config['variables']
|
pages/chatbot.py
CHANGED
|
@@ -14,11 +14,26 @@ def display_messages():
|
|
| 14 |
st.write(f"**Model :** {model}")
|
| 15 |
st.markdown(message.content)
|
| 16 |
st_copy_to_clipboard(message.content,key=f"message_{i}")
|
|
|
|
| 17 |
|
| 18 |
elif isinstance(message, HumanMessage):
|
| 19 |
with st.chat_message("Moi"):
|
| 20 |
st.write(message.content)
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def launchQuery(query: str = None):
|
| 24 |
|
|
|
|
| 14 |
st.write(f"**Model :** {model}")
|
| 15 |
st.markdown(message.content)
|
| 16 |
st_copy_to_clipboard(message.content,key=f"message_{i}")
|
| 17 |
+
show_retrieved_documents(st.session_state.chat_history[i-1].content)
|
| 18 |
|
| 19 |
elif isinstance(message, HumanMessage):
|
| 20 |
with st.chat_message("Moi"):
|
| 21 |
st.write(message.content)
|
| 22 |
|
| 23 |
+
def show_retrieved_documents(query: str = ''):
|
| 24 |
+
if query == '':
|
| 25 |
+
return
|
| 26 |
+
|
| 27 |
+
# Créer l'expander pour les documents trouvés
|
| 28 |
+
expander = st.expander("Documents trouvés")
|
| 29 |
+
|
| 30 |
+
# Boucler à travers les documents récupérés
|
| 31 |
+
for item in st.session_state.get("retrived_documents", []):
|
| 32 |
+
if 'query' in item:
|
| 33 |
+
if item["query"] == query:
|
| 34 |
+
for doc in item.get("documents", []):
|
| 35 |
+
expander.write(doc)
|
| 36 |
+
|
| 37 |
|
| 38 |
def launchQuery(query: str = None):
|
| 39 |
|
rag.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
|
|
|
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from langchain_community.vectorstores import FAISS
|
| 5 |
from langchain_mistralai.chat_models import ChatMistralAI
|
|
@@ -89,6 +90,8 @@ class Rag:
|
|
| 89 |
# Retrieve the VectoreStore
|
| 90 |
contextCommon = self.vector_store.retriever(query, self.embedding)
|
| 91 |
|
|
|
|
|
|
|
| 92 |
# Dictionnaire de base avec les variables principales
|
| 93 |
chain_input = {
|
| 94 |
"query": query,
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
+
import streamlit as st
|
| 4 |
from dotenv import load_dotenv
|
| 5 |
from langchain_community.vectorstores import FAISS
|
| 6 |
from langchain_mistralai.chat_models import ChatMistralAI
|
|
|
|
| 90 |
# Retrieve the VectoreStore
|
| 91 |
contextCommon = self.vector_store.retriever(query, self.embedding)
|
| 92 |
|
| 93 |
+
st.session_state["retrived_documents"].append({ "query": query, "documents": contextCommon })
|
| 94 |
+
|
| 95 |
# Dictionnaire de base avec les variables principales
|
| 96 |
chain_input = {
|
| 97 |
"query": query,
|