Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,7 @@ folder = snapshot_download(repo_id="umaiku/faiss_index", repo_type="dataset", lo
|
|
17 |
embeddings = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-small")
|
18 |
|
19 |
vector_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
|
20 |
-
retriever = vector_db.as_retriever(search_kwargs={"
|
21 |
|
22 |
def respond(
|
23 |
message,
|
@@ -29,11 +29,14 @@ def respond(
|
|
29 |
):
|
30 |
messages = [{"role": "system", "content": system_message}]
|
31 |
|
32 |
-
document = retriever.invoke(message)
|
33 |
|
34 |
-
|
|
|
|
|
|
|
35 |
|
36 |
-
message
|
37 |
|
38 |
for val in history:
|
39 |
if val[0]:
|
|
|
17 |
embeddings = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-small")
|
18 |
|
19 |
vector_db = FAISS.load_local("faiss_index", embeddings, allow_dangerous_deserialization=True)
|
20 |
+
retriever = vector_db.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": 0.75})
|
21 |
|
22 |
def respond(
|
23 |
message,
|
|
|
29 |
):
|
30 |
messages = [{"role": "system", "content": system_message}]
|
31 |
|
32 |
+
document = retriever.invoke(message)
|
33 |
|
34 |
+
if document == []:
|
35 |
+
message = message + "\nNo cases were found about this subject"
|
36 |
+
else:
|
37 |
+
message = message + "\nUse the following jurisprudence case to answer " + document[0].page_content + "\n Give the following url " + document[0].metadata["case_url"]
|
38 |
|
39 |
+
print(message)
|
40 |
|
41 |
for val in history:
|
42 |
if val[0]:
|