alisamak commited on
Commit
d68fdb3
·
verified ·
1 Parent(s): fd4610a

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +10 -13
tools.py CHANGED
@@ -67,7 +67,6 @@ def search_featured_articles_by_date_range(start_date: str, end_date: str) -> li
67
  return sorted(set(result_titles))
68
  except Exception as e:
69
  return [f"Error: {str(e)}"]
70
-
71
  @tool
72
  def detect_non_commutative_subset(table_text: str) -> str:
73
  """
@@ -82,24 +81,23 @@ def detect_non_commutative_subset(table_text: str) -> str:
82
  """
83
  print("🛠️ detect_non_commutative_subset called")
84
  try:
85
- lines = [line.strip() for line in table_text.strip().splitlines() if "|" in line]
86
  if len(lines) < 3:
87
  return "Error: Table format invalid or incomplete."
88
 
89
- # Parse headers (set elements)
90
- headers = [h.strip() for h in lines[0].split('|') if h.strip()]
91
 
92
  operation = {}
93
- for line in lines[2:]: # skip header and separator
94
- cells = [c.strip() for c in line.split('|') if c.strip()]
95
- if len(cells) != len(headers) + 1:
96
- continue # skip malformed rows
97
- row_label = cells[0]
98
- for col_idx, result in enumerate(cells[1:]):
99
- col_label = headers[col_idx]
100
  operation[(row_label, col_label)] = result
101
 
102
- # Find mismatches: x*y ≠ y*x
103
  involved = set()
104
  for a in headers:
105
  for b in headers:
@@ -107,7 +105,6 @@ def detect_non_commutative_subset(table_text: str) -> str:
107
  involved.update([a, b])
108
 
109
  return ", ".join(sorted(involved)) if involved else "The operation is commutative."
110
-
111
  except Exception as e:
112
  return f"Error analyzing table: {str(e)}"
113
 
 
67
  return sorted(set(result_titles))
68
  except Exception as e:
69
  return [f"Error: {str(e)}"]
 
70
  @tool
71
  def detect_non_commutative_subset(table_text: str) -> str:
72
  """
 
81
  """
82
  print("🛠️ detect_non_commutative_subset called")
83
  try:
84
+ lines = [line for line in table_text.strip().splitlines() if "|" in line]
85
  if len(lines) < 3:
86
  return "Error: Table format invalid or incomplete."
87
 
88
+ # Parse headers
89
+ headers = [h.strip() for h in lines[0].split('|')[1:-1]]
90
 
91
  operation = {}
92
+ for line in lines[2:]:
93
+ parts = [c.strip() for c in line.split('|')[1:-1]] # keep strict column alignment
94
+ if len(parts) != len(headers) + 1:
95
+ continue
96
+ row_label = parts[0]
97
+ for i, result in enumerate(parts[1:]):
98
+ col_label = headers[i]
99
  operation[(row_label, col_label)] = result
100
 
 
101
  involved = set()
102
  for a in headers:
103
  for b in headers:
 
105
  involved.update([a, b])
106
 
107
  return ", ".join(sorted(involved)) if involved else "The operation is commutative."
 
108
  except Exception as e:
109
  return f"Error analyzing table: {str(e)}"
110