Amna2024 commited on
Commit
a1e8f8b
·
verified ·
1 Parent(s): cb4587b

Update rag_service.py

Browse files
Files changed (1) hide show
  1. rag_service.py +20 -11
rag_service.py CHANGED
@@ -113,19 +113,28 @@ class RAGService:
113
  for text_element in docs_by_type["texts"]:
114
  context_text += str(text_element)
115
 
116
- prompt_template = f"""
117
- You are a helpful AI assistant. You have access to the following context from uploaded documents:
118
- Context: {context_text}
119
- Question: {user_question}
120
-
121
- Instructions:
122
- - If the question is related to the provided context, use that information to answer
123
- - If the question is not related to the context or is a general query, answer based on your general knowledge
124
- - Be clear about whether you're using the provided context or general knowledge in your response
125
- """
 
 
 
 
 
 
 
 
 
126
 
127
  prompt_content = [{"type": "text", "text": prompt_template}]
128
-
129
  if len(docs_by_type["images"]) > 0:
130
  for image in docs_by_type["images"]:
131
  prompt_content.append(
 
113
  for text_element in docs_by_type["texts"]:
114
  context_text += str(text_element)
115
 
116
+ # If no relevant context found, make it fully general
117
+ if not context_text.strip():
118
+ prompt_template = f"""
119
+ You are a helpful AI assistant. Answer the following question:
120
+ Question: {user_question}
121
+ """
122
+ else:
123
+ prompt_template = f"""
124
+ You are a helpful AI assistant. You have access to the following context from uploaded documents:
125
+
126
+ Context: {context_text}
127
+
128
+ Question: {user_question}
129
+
130
+ Instructions:
131
+ - If the question is related to the provided context, use that information to answer
132
+ - If the question is not related to the context or is a general query, answer based on your general knowledge
133
+ - Be clear about whether you're using the provided context or general knowledge in your response
134
+ """
135
 
136
  prompt_content = [{"type": "text", "text": prompt_template}]
137
+
138
  if len(docs_by_type["images"]) > 0:
139
  for image in docs_by_type["images"]:
140
  prompt_content.append(