filipsedivy commited on
Commit
ac6cd22
·
1 Parent(s): 67ea2a7

Update prompt

Browse files
Files changed (1) hide show
  1. app.py +26 -17
app.py CHANGED
@@ -15,23 +15,32 @@ def respond(
15
  ):
16
  matching_docs = db.similarity_search(message)
17
 
18
- context = ""
19
- current_length = 0
20
- for i, doc in enumerate(matching_docs):
21
- doc_text = f"Document {i + 1}:\n{doc.page_content}\n\n"
22
- doc_length = len(doc_text.split())
23
- context += doc_text
24
- current_length += doc_length
25
-
26
- prompt = (
27
- f"You are an expert in summarizing and answering questions based on given documents. "
28
- f"You're an expert in English grammar at the same time. "
29
- f"This means that your texts are flawless, correct and grammatically correct."
30
- f"Please provide a detailed and well-explained answer to the following query in 4-6 sentences:\n\n"
31
- f"Query: {message}\n\n"
32
- f"Based on the following documents:\n{context}\n\n"
33
- f"Answer:"
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,