Spaces:
Sleeping
Sleeping
Commit
·
ac6cd22
1
Parent(s):
67ea2a7
Update prompt
Browse files
app.py
CHANGED
@@ -15,23 +15,32 @@ def respond(
|
|
15 |
):
|
16 |
matching_docs = db.similarity_search(message)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
response = client.text_generation(
|
37 |
prompt,
|
|
|
15 |
):
|
16 |
matching_docs = db.similarity_search(message)
|
17 |
|
18 |
+
if not matching_docs:
|
19 |
+
prompt = (
|
20 |
+
f"You are an expert in generating responses when there is no information available. "
|
21 |
+
f"Unfortunately, there are no relevant documents available to answer the following query:\n\n"
|
22 |
+
f"Query: {message}\n\n"
|
23 |
+
f"Please provide a polite and original response to inform the user that the requested information is not "
|
24 |
+
f"available."
|
25 |
+
)
|
26 |
+
else:
|
27 |
+
context = ""
|
28 |
+
current_length = 0
|
29 |
+
for i, doc in enumerate(matching_docs):
|
30 |
+
doc_text = f"Document {i + 1}:\n{doc.page_content}\n\n"
|
31 |
+
doc_length = len(doc_text.split())
|
32 |
+
context += doc_text
|
33 |
+
current_length += doc_length
|
34 |
+
|
35 |
+
prompt = (
|
36 |
+
f"You are an expert in summarizing and answering questions based on given documents. "
|
37 |
+
f"You're an expert in English grammar at the same time. "
|
38 |
+
f"This means that your texts are flawless, correct and grammatically correct."
|
39 |
+
f"Please provide a detailed and well-explained answer to the following query in 4-6 sentences:\n\n"
|
40 |
+
f"Query: {message}\n\n"
|
41 |
+
f"Based on the following documents:\n{context}\n\n"
|
42 |
+
f"Answer:"
|
43 |
+
)
|
44 |
|
45 |
response = client.text_generation(
|
46 |
prompt,
|