Spaces:
Runtime error
Runtime error
Enhance check_format function to flatten nested lists and raise error for dict inputs
Browse files
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 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|