Zeggai Abdellah commited on
Commit
cfc25dc
·
1 Parent(s): 85a458e

update the rag pipeline

Browse files
Files changed (1) hide show
  1. rag_pipeline.py +4 -55
rag_pipeline.py CHANGED
@@ -169,58 +169,6 @@ Answer the doctor's question accurately and concisely using only the provided in
169
  3. Present information concisely but ensure clinical accuracy is never compromised.
170
  """
171
 
172
- # Create the modified prompt template by combining your instructions with the default structure
173
- # IMPORTANT: Fix the curly brace escaping for JSON examples
174
- modified_template = f"""{custom_instructions}
175
-
176
- ## Tools
177
-
178
- You have access to a wide variety of tools. You are responsible for using the tools in any sequence you deem appropriate to complete the task at hand.
179
- This may require breaking the task into subtasks and using different tools to complete each subtask.
180
-
181
- You have access to the following tools:
182
- {{tool_desc}}
183
-
184
- ## Output Format
185
-
186
- Please answer in the same language as the question and use the following format:
187
-
188
- ```
189
- Thought: The current language of the user is: (user's language). I need to use a tool to help me answer the question.
190
- Action: tool name (one of {{tool_names}}) if using a tool.
191
- Action Input: the input to the tool, in a JSON format representing the kwargs (e.g. {{"input": "hello world", "num_beams": 5}})
192
- ```
193
-
194
- Please ALWAYS start with a Thought.
195
-
196
- NEVER surround your response with markdown code markers. You may use code markers within your response if you need to.
197
-
198
- Please use a valid JSON format for the Action Input. Do NOT do this {{"input": "hello world", "num_beams": 5}}.
199
-
200
- If this format is used, the tool will respond in the following format:
201
-
202
- ```
203
- Observation: tool response
204
- ```
205
-
206
- You should keep repeating the above format till you have enough information to answer the question without using any more tools. At that point, you MUST respond in one of the following two formats:
207
-
208
- ```
209
- Thought: I can answer without using any more tools. I'll use the user's language to answer. Remember to include proper citations
210
- Answer: [your answer here with proper citations (In the same language as the user's question)]
211
- ```
212
-
213
- ```
214
- Thought: I cannot answer the question with the provided tools.
215
- Answer: [your answer here (In the same language as the user's question)]
216
- ```
217
-
218
- ## Current Conversation
219
-
220
- Below is the current conversation consisting of interleaving human and assistant messages.
221
- """
222
-
223
- # SAFER APPROACH: Let's use the original template and just prepend instructions
224
  # Get the exact original template first
225
  temp_agent = ReActAgent.from_tools(tools, llm=llm, verbose=False)
226
  original_prompts = temp_agent.get_prompts()
@@ -248,7 +196,8 @@ Below is the current conversation consisting of interleaving human and assistant
248
  # Even safer fallback - just use PromptTemplate with template only
249
  print(f"[LOG] ⚠️ Using fallback prompt template for {'fallback' if is_fallback else 'standard'} agent")
250
  return PromptTemplate(template=safe_template)
251
-
 
252
  def create_agent(tools, llm, is_fallback=False):
253
  """Create the ReAct agent with custom prompt"""
254
 
@@ -265,11 +214,11 @@ def create_agent(tools, llm, is_fallback=False):
265
  max_iterations=max_iter, # Reduced iterations for fallback agent
266
  )
267
 
268
- # Create and apply appropriate custom prompt
269
  try:
270
  safe_custom_prompt = create_safe_custom_prompt(tools, llm, is_fallback=is_fallback)
271
  agent.update_prompts({"agent_worker:system_prompt": safe_custom_prompt})
272
- print(f"✅ Successfully updated {agent_type} agent with custom prompt")
273
  except Exception as e:
274
  print(f"❌ {agent_type} agent prompt update failed: {e}")
275
  print(f"⚠️ Using original {agent_type} agent without modifications")
 
169
  3. Present information concisely but ensure clinical accuracy is never compromised.
170
  """
171
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  # Get the exact original template first
173
  temp_agent = ReActAgent.from_tools(tools, llm=llm, verbose=False)
174
  original_prompts = temp_agent.get_prompts()
 
196
  # Even safer fallback - just use PromptTemplate with template only
197
  print(f"[LOG] ⚠️ Using fallback prompt template for {'fallback' if is_fallback else 'standard'} agent")
198
  return PromptTemplate(template=safe_template)
199
+
200
+
201
  def create_agent(tools, llm, is_fallback=False):
202
  """Create the ReAct agent with custom prompt"""
203
 
 
214
  max_iterations=max_iter, # Reduced iterations for fallback agent
215
  )
216
 
217
+ # Create and apply safe custom prompt
218
  try:
219
  safe_custom_prompt = create_safe_custom_prompt(tools, llm, is_fallback=is_fallback)
220
  agent.update_prompts({"agent_worker:system_prompt": safe_custom_prompt})
221
+ print(f"✅ Successfully updated {agent_type} agent with safe custom prompt")
222
  except Exception as e:
223
  print(f"❌ {agent_type} agent prompt update failed: {e}")
224
  print(f"⚠️ Using original {agent_type} agent without modifications")