luke9705 commited on
Commit
b5fc7aa
·
1 Parent(s): 8b72ba7

Enhance check_format function to flatten nested lists and raise error for dict inputs

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -51,10 +51,22 @@ def check_format(answer: str | list, *args, **kwargs ) -> list:
51
  """ Check if the answer is a list. """
52
 
53
  print("Checking format of the answer:", answer)
54
- if isinstance(answer, list):
55
- return answer
56
- else:
57
- return [answer]
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
 
60
  ## tools definition
 
51
  """ Check if the answer is a list. """
52
 
53
  print("Checking format of the answer:", answer)
54
+ def flatten(lst):
55
+ for item in lst:
56
+ if isinstance(item, list):
57
+ yield from flatten(item)
58
+ else:
59
+ yield item
60
+ try:
61
+ if isinstance(answer, list):
62
+ flat = list(flatten(answer))
63
+ return flat
64
+ except Exception as e:
65
+ if isinstance(answer, dict):
66
+ raise TypeError(f"Final answer must be a list, not a dict. Please check the answer format. Error: {e}")
67
+
68
+
69
+
70
 
71
 
72
  ## tools definition