Spaces:
Runtime error
Runtime error
Update tools.py
Browse files
tools.py
CHANGED
|
@@ -121,6 +121,35 @@ def fetch_video_metadata(video_id: str) -> str:
|
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
return f"❌ Error fetching metadata: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
|
| 126 |
# List of all tools
|
|
@@ -128,4 +157,5 @@ all_tools = [
|
|
| 128 |
extract_number_from_text,
|
| 129 |
search_wikipedia,
|
| 130 |
analyze_youtube_video,
|
|
|
|
| 131 |
]
|
|
|
|
| 121 |
|
| 122 |
except Exception as e:
|
| 123 |
return f"❌ Error fetching metadata: {e}"
|
| 124 |
+
|
| 125 |
+
@tool
|
| 126 |
+
def check_commutativity_table(table_text: str) -> str:
|
| 127 |
+
"""
|
| 128 |
+
Parse a multiplication table from markdown-like text and return the set of elements involved in counter-examples to commutativity.
|
| 129 |
+
"""
|
| 130 |
+
try:
|
| 131 |
+
lines = [line.strip() for line in table_text.strip().splitlines() if '|' in line]
|
| 132 |
+
header = [e.strip() for e in lines[0].split('|')[1:] if e.strip()] # skip first column label
|
| 133 |
+
elements = header
|
| 134 |
+
|
| 135 |
+
table = {}
|
| 136 |
+
for row in lines[2:]: # skip header and separator
|
| 137 |
+
cells = [c.strip() for c in row.split('|')[1:] if c.strip()]
|
| 138 |
+
row_label = cells[0]
|
| 139 |
+
values = cells[1:]
|
| 140 |
+
table[row_label] = dict(zip(elements, values))
|
| 141 |
+
|
| 142 |
+
involved = set()
|
| 143 |
+
for x in elements:
|
| 144 |
+
for y in elements:
|
| 145 |
+
if table[x][y] != table[y][x]:
|
| 146 |
+
involved.add(x)
|
| 147 |
+
involved.add(y)
|
| 148 |
+
|
| 149 |
+
return ",".join(sorted(involved))
|
| 150 |
+
|
| 151 |
+
except Exception as e:
|
| 152 |
+
return f"❌ Error parsing table: {e}"
|
| 153 |
|
| 154 |
|
| 155 |
# List of all tools
|
|
|
|
| 157 |
extract_number_from_text,
|
| 158 |
search_wikipedia,
|
| 159 |
analyze_youtube_video,
|
| 160 |
+
check_commutativity_table
|
| 161 |
]
|