Update main.py
Browse files
main.py
CHANGED
@@ -59,7 +59,10 @@ vectorstore = PineconeVectorStore(
|
|
59 |
index_name=index_name, embedding=embeddings
|
60 |
)
|
61 |
retriever = vectorstore.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": .7, "k": 150,"filter": {'categorie': {'$eq': 'bibliographie-OPP-DGDIN'}}})
|
62 |
-
|
|
|
|
|
|
|
63 |
@cl.on_chat_start
|
64 |
async def on_chat_start():
|
65 |
await cl.Message(f"> REVIEWSTREAM").send()
|
@@ -163,7 +166,6 @@ async def on_message(message: cl.Message):
|
|
163 |
self.sources.add(source_page_pair) # Add unique pairs to the set
|
164 |
|
165 |
def on_llm_end(self, response, *, run_id, parent_run_id, **kwargs):
|
166 |
-
if len(self.sources):
|
167 |
sources_text = "\n".join([f"{source}#page={page}" for source, page in self.sources])
|
168 |
self.msg.elements.append(
|
169 |
cl.Text(name="Sources", content=sources_text, display="inline")
|
@@ -182,6 +184,25 @@ async def on_message(message: cl.Message):
|
|
182 |
answer = results["answer"]
|
183 |
|
184 |
await cl.Message(content=answer).send()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
#await msg.send()
|
186 |
#memory.chat_memory.add_user_message(message.content)
|
187 |
#memory.chat_memory.add_ai_message(msg.content)
|
|
|
59 |
index_name=index_name, embedding=embeddings
|
60 |
)
|
61 |
retriever = vectorstore.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": .7, "k": 150,"filter": {'categorie': {'$eq': 'bibliographie-OPP-DGDIN'}}})
|
62 |
+
#search = vectorstore.similarity_search(query,k=50, filter={"categorie": {"$eq": "bibliographie-OPP-DGDIN"}, 'Source': {'$eq': 'Source : Persée'}})
|
63 |
+
search = vectorstore.similarity_search(query,k=50, filter={"categorie": {"$eq": "bibliographie-OPP-DGDIN"}})
|
64 |
+
cl.user_session.set("search", search)
|
65 |
+
|
66 |
@cl.on_chat_start
|
67 |
async def on_chat_start():
|
68 |
await cl.Message(f"> REVIEWSTREAM").send()
|
|
|
166 |
self.sources.add(source_page_pair) # Add unique pairs to the set
|
167 |
|
168 |
def on_llm_end(self, response, *, run_id, parent_run_id, **kwargs):
|
|
|
169 |
sources_text = "\n".join([f"{source}#page={page}" for source, page in self.sources])
|
170 |
self.msg.elements.append(
|
171 |
cl.Text(name="Sources", content=sources_text, display="inline")
|
|
|
184 |
answer = results["answer"]
|
185 |
|
186 |
await cl.Message(content=answer).send()
|
187 |
+
if cl.user_session.get("search"):
|
188 |
+
test = []
|
189 |
+
sources_text = ""
|
190 |
+
count = 0
|
191 |
+
search = cl.user_session.get("search")
|
192 |
+
for i in range(0,len(search)):
|
193 |
+
if search[i].metadata['Lien'] not in test:
|
194 |
+
if count <= 15:
|
195 |
+
count = count + 1
|
196 |
+
test.append(search[i].metadata['Lien'])
|
197 |
+
sources_text = sources_text + "<a href='" + search[i].metadata['Lien'] + "'>" + search[i].metadata['Titre'] + '</a>, ' + search[i].metadata['Auteurs'] + ', ' + search[i].metadata['Lien'] + "\n"
|
198 |
+
elements = [
|
199 |
+
cl.Text(name="Sources", content=sources_text, display="inline")
|
200 |
+
]
|
201 |
+
|
202 |
+
await cl.Message(
|
203 |
+
content="Sources : ",
|
204 |
+
elements=elements,
|
205 |
+
).send()
|
206 |
#await msg.send()
|
207 |
#memory.chat_memory.add_user_message(message.content)
|
208 |
#memory.chat_memory.add_ai_message(msg.content)
|