Kackle commited on
Commit
eba7504
·
verified ·
1 Parent(s): 006dac3

post processing

Browse files
Files changed (1) hide show
  1. gemini_agent.py +11 -6
gemini_agent.py CHANGED
@@ -272,12 +272,17 @@ Provide only the direct answer. If it's a quote, give just the quoted text. If i
272
  if move_match:
273
  answer = move_match.group(1)
274
 
275
- # Post-processing for strict list extraction
276
- if any(kw in question.lower() for kw in ["alphabetize", "comma separated", "list", "ingredients", "page numbers", "vegetables"]):
277
- # Extract only a comma-separated list of words (allowing spaces)
278
- list_match = re.findall(r'[A-Za-z][A-Za-z ]*', answer)
279
- if list_match:
280
- answer = ', '.join([item.strip() for item in list_match if item.strip()])
 
 
 
 
 
281
 
282
  return answer
283
 
 
272
  if move_match:
273
  answer = move_match.group(1)
274
 
275
+ # Post-processing for sorted, deduplicated lists
276
+ if 'page numbers' in question.lower() or 'comma-delimited list' in question.lower():
277
+ # Extract numbers, deduplicate, sort, and join
278
+ nums = re.findall(r'\d+', answer)
279
+ nums = sorted(set(int(n) for n in nums))
280
+ answer = ', '.join(str(n) for n in nums)
281
+ elif 'alphabetize' in question.lower() or 'alphabetized' in question.lower() or 'ingredients' in question.lower() or 'vegetables' in question.lower():
282
+ # Extract words/phrases, deduplicate, sort, and join
283
+ items = [item.strip() for item in answer.split(',') if item.strip()]
284
+ items = sorted(set(items), key=lambda x: x.lower())
285
+ answer = ', '.join(items)
286
 
287
  return answer
288