Sahil Garg commited on
Commit
2ccfaa5
Β·
1 Parent(s): 2f9711c

added specific boq to iterative prompt handling

Browse files
prompts/templates.yaml CHANGED
@@ -79,15 +79,17 @@ boq_improvement_template: |
79
  1. Look for BOQ items in the raw text that are NOT in the previous extraction
80
  2. For items already extracted, check if quantities/units show "NA" but actual values exist in text
81
  3. DO NOT duplicate items that are already correctly extracted
 
82
 
83
  **When to extract:**
84
- βœ“ Found a NEW item (different item code/description) not in previous BOQ
85
  βœ“ Found an item where previous shows "NA" but text has actual quantity/unit/rate
86
 
87
  **When to skip (return NO_BOQ_ITEMS):**
88
  βœ— Item is already in previous BOQ with complete data
89
  βœ— This batch has no BOQ content
90
  βœ— Items mentioned are already correctly extracted
 
91
 
92
  **Return format (pipe-separated):**
93
  ITEM_CODE|ITEM_NAME|DESCRIPTION|QUANTITY|UNIT|RATE|AMOUNT|CONFIDENCE
 
79
  1. Look for BOQ items in the raw text that are NOT in the previous extraction
80
  2. For items already extracted, check if quantities/units show "NA" but actual values exist in text
81
  3. DO NOT duplicate items that are already correctly extracted
82
+ 4. RESPECT any extraction constraints specified above - only extract items within the specified scope
83
 
84
  **When to extract:**
85
+ βœ“ Found a NEW item (different item code/description) not in previous BOQ AND within allowed scope
86
  βœ“ Found an item where previous shows "NA" but text has actual quantity/unit/rate
87
 
88
  **When to skip (return NO_BOQ_ITEMS):**
89
  βœ— Item is already in previous BOQ with complete data
90
  βœ— This batch has no BOQ content
91
  βœ— Items mentioned are already correctly extracted
92
+ βœ— Item is outside the specified extraction scope/constraint
93
 
94
  **Return format (pipe-separated):**
95
  ITEM_CODE|ITEM_NAME|DESCRIPTION|QUANTITY|UNIT|RATE|AMOUNT|CONFIDENCE
services/boq_extractor.py CHANGED
@@ -132,15 +132,20 @@ class BOQExtractor:
132
  prompt_text = batch_text[:self.max_prompt_length]
133
 
134
  # Determine extraction instruction based on mode
135
- if boq_mode == ["specific BOQ"] and specific_boq:
 
 
136
  extraction_instruction = f"Extract only BOQ items that are related to or match the following: {specific_boq}. If no matching items are found, return NO_BOQ_ITEMS."
 
137
  else:
138
  extraction_instruction = "Extract all BOQ items present in the text."
 
139
 
140
  if previous_boq:
141
  base_prompt = BOQ_IMPROVEMENT_TEMPLATE
142
- # Insert instruction before "Now, analyze this text"
143
- base_prompt = base_prompt.replace("Now, analyze this text and extract improved BOQ line items.", f"{extraction_instruction}\n\nNow, analyze this text and extract improved BOQ line items.")
 
144
  prompt = base_prompt.format(previous_boq=previous_boq, batch_text=prompt_text)
145
  else:
146
  base_prompt = BOQ_EXTRACTION_TEMPLATE
 
132
  prompt_text = batch_text[:self.max_prompt_length]
133
 
134
  # Determine extraction instruction based on mode
135
+ # If both default and specific BOQ are selected, extract all
136
+ # If only specific BOQ is selected, apply constraint
137
+ if boq_mode and "specific BOQ" in boq_mode and "default" not in boq_mode and specific_boq:
138
  extraction_instruction = f"Extract only BOQ items that are related to or match the following: {specific_boq}. If no matching items are found, return NO_BOQ_ITEMS."
139
+ specific_constraint = f"\n**IMPORTANT CONSTRAINT:** Only extract items related to: {specific_boq}. Ignore all other items."
140
  else:
141
  extraction_instruction = "Extract all BOQ items present in the text."
142
+ specific_constraint = ""
143
 
144
  if previous_boq:
145
  base_prompt = BOQ_IMPROVEMENT_TEMPLATE
146
+ # For specific BOQ mode, add constraint to improvement template
147
+ if specific_constraint:
148
+ base_prompt = base_prompt.replace("**Your task:**", f"{specific_constraint}\n\n**Your task:**")
149
  prompt = base_prompt.format(previous_boq=previous_boq, batch_text=prompt_text)
150
  else:
151
  base_prompt = BOQ_EXTRACTION_TEMPLATE