Update app.py
Browse files
app.py
CHANGED
@@ -27,13 +27,6 @@ vector_db = FAISS.load_local("faiss_index_8k", embeddings, allow_dangerous_deser
|
|
27 |
|
28 |
df = pd.read_csv("faiss_index/bger_cedh_db 1954-2024.csv")
|
29 |
|
30 |
-
system_prompt = """ You are an assistant in Swiss Jurisprudence law.
|
31 |
-
Please answer the user in the same language that he used in his question using the following given context, not prior or other knowledge.
|
32 |
-
If no relevant cases were retrieved or the issue has not been addressed within the context, just say "I can't find enough relevant information".
|
33 |
-
Don't make up an answer or give irrelevant information not requested by the user and do not give any links that are not provided in the context.
|
34 |
-
Otherwise, if relevant cases were found, start by summarizing these cases in the user's question's language and reference the sources, including the source, urls and dates.
|
35 |
-
"""
|
36 |
-
|
37 |
def respond(
|
38 |
message,
|
39 |
history: list[tuple[str, str]],
|
@@ -43,6 +36,10 @@ def respond(
|
|
43 |
top_p,
|
44 |
score,
|
45 |
):
|
|
|
|
|
|
|
|
|
46 |
retriever = vector_db.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": score})
|
47 |
documents = retriever.invoke(message)
|
48 |
|
@@ -59,27 +56,24 @@ def respond(
|
|
59 |
context += "Case url: " + doc.metadata["case_url"] + spacer
|
60 |
context += "Case text: " + doc.page_content + spacer
|
61 |
#context += "Case text: " + case_text[:8000] + spacer
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
64 |
The following case extracts have been found in either Swiss Federal Court or European Court of Human Rights cases and could fit the question:
|
65 |
{context}
|
66 |
-
|
67 |
-
""
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
# message = f"""
|
75 |
-
#The user is asking you the following question: {message}
|
76 |
-
#The following case extracts have been found in either Swiss Federal Court or European Court of Human Rights cases and could fit the question:
|
77 |
-
#{context}
|
78 |
-
#Task: Always answer the user using the language used in his question: {message}
|
79 |
-
# """
|
80 |
-
|
81 |
-
# print(message)
|
82 |
|
|
|
|
|
83 |
# for val in history:
|
84 |
# if val[0]:
|
85 |
# messages.append({"role": "user", "content": val[0]})
|
@@ -109,7 +103,7 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
109 |
demo = gr.ChatInterface(
|
110 |
respond,
|
111 |
additional_inputs=[
|
112 |
-
gr.Textbox(value=
|
113 |
gr.Slider(minimum=1, maximum=24000, value=5000, step=1, label="Max new tokens"),
|
114 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
115 |
gr.Slider(
|
|
|
27 |
|
28 |
df = pd.read_csv("faiss_index/bger_cedh_db 1954-2024.csv")
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
def respond(
|
31 |
message,
|
32 |
history: list[tuple[str, str]],
|
|
|
36 |
top_p,
|
37 |
score,
|
38 |
):
|
39 |
+
messages = [{"role": "system", "content": system_message}]
|
40 |
+
|
41 |
+
print(system_message)
|
42 |
+
|
43 |
retriever = vector_db.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": score})
|
44 |
documents = retriever.invoke(message)
|
45 |
|
|
|
56 |
context += "Case url: " + doc.metadata["case_url"] + spacer
|
57 |
context += "Case text: " + doc.page_content + spacer
|
58 |
#context += "Case text: " + case_text[:8000] + spacer
|
59 |
+
|
60 |
+
|
61 |
+
message = f"""
|
62 |
+
A user is asking you the following question: {message}
|
63 |
+
Please answer the user in the same language that he used in his question using the following given context not prior knowledge.
|
64 |
+
Context:
|
65 |
The following case extracts have been found in either Swiss Federal Court or European Court of Human Rights cases and could fit the question:
|
66 |
{context}
|
67 |
+
Task:
|
68 |
+
If the retrieved context is not relevant cases or the issue has not been addressed within the context, just say "I can't find enough relevant information".
|
69 |
+
Don't make up an answer or give irrelevant information not requested by the user.
|
70 |
+
Otherwise, if relevant cases were found, start by summarizing these cases in the user's question's language and reference the sources, including the urls and dates.
|
71 |
+
Instructions:
|
72 |
+
Always answer the user using the language used in his question: {message}
|
73 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
+
print(message)
|
76 |
+
|
77 |
# for val in history:
|
78 |
# if val[0]:
|
79 |
# messages.append({"role": "user", "content": val[0]})
|
|
|
103 |
demo = gr.ChatInterface(
|
104 |
respond,
|
105 |
additional_inputs=[
|
106 |
+
gr.Textbox(value="You are an assistant in Swiss Jurisprudence cases.", label="System message"),
|
107 |
gr.Slider(minimum=1, maximum=24000, value=5000, step=1, label="Max new tokens"),
|
108 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
109 |
gr.Slider(
|