Update rag_service.py
Browse files- rag_service.py +24 -11
rag_service.py
CHANGED
|
@@ -114,18 +114,31 @@ class RAGService:
|
|
| 114 |
for text_element in docs_by_type["texts"]:
|
| 115 |
context_text += str(text_element)
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
# Add images only if context exists
|
| 131 |
if len(docs_by_type["images"]) > 0:
|
|
|
|
| 114 |
for text_element in docs_by_type["texts"]:
|
| 115 |
context_text += str(text_element)
|
| 116 |
|
| 117 |
+
# Always use this flexible prompt
|
| 118 |
+
prompt_template = f"""
|
| 119 |
+
You are a helpful AI assistant.
|
| 120 |
+
|
| 121 |
+
Context from documents (use if relevant): {context_text}
|
| 122 |
+
|
| 123 |
+
Question: {user_question}
|
| 124 |
+
|
| 125 |
+
Instructions: Answer the question. If the provided context is relevant to the question, use it. If not, answer using your general knowledge.
|
| 126 |
+
"""
|
| 127 |
|
| 128 |
+
prompt_content = [{"type": "text", "text": prompt_template}]
|
| 129 |
+
|
| 130 |
+
else:
|
| 131 |
+
# No context found - use direct LLM prompt
|
| 132 |
+
prompt_template = f"""
|
| 133 |
+
You are a helpful AI assistant. Answer the following question using your general knowledge:
|
| 134 |
+
|
| 135 |
+
Question: {user_question}
|
| 136 |
+
"""
|
| 137 |
+
|
| 138 |
+
prompt_content = [{"type": "text", "text": prompt_template}]
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
|
| 142 |
|
| 143 |
# Add images only if context exists
|
| 144 |
if len(docs_by_type["images"]) > 0:
|