Update tools.py
Browse files
tools.py
CHANGED
|
@@ -14,6 +14,51 @@ import numpy as np
|
|
| 14 |
from scipy.io import wavfile
|
| 15 |
import pandas as pd
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
class Web_research(Tool):
|
| 18 |
name="web_search"
|
| 19 |
description = "Web search on a specific topic."
|
|
|
|
| 14 |
from scipy.io import wavfile
|
| 15 |
import pandas as pd
|
| 16 |
|
| 17 |
+
import numpy as np
|
| 18 |
+
import pandas as pd
|
| 19 |
+
from smolagent.tools import Tool # à adapter selon ton vrai import
|
| 20 |
+
|
| 21 |
+
class is_commutative(Tool):
|
| 22 |
+
name = "commutative"
|
| 23 |
+
description = "Performs a study on a table set to see if it is commutative."
|
| 24 |
+
inputs = {
|
| 25 |
+
"set": {
|
| 26 |
+
"type": "array",
|
| 27 |
+
"items": {"type": "string"},
|
| 28 |
+
"description": "The set defined, for example : {'a','b','c'}."
|
| 29 |
+
},
|
| 30 |
+
"table": {
|
| 31 |
+
"type": "string",
|
| 32 |
+
"description": "The table in markdown format with rows separated by '\n'. Give only the table after the '|---|---|---|---|---|---|' symbol, starting with the '\n', ending with '\n\n', as a string."
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
output_type = "string"
|
| 36 |
+
|
| 37 |
+
def forward(self, set, table):
|
| 38 |
+
set_0=list(sorted(set))
|
| 39 |
+
table_0=np.empty((len(set_0)+1,len(set_0)+1),dtype='<U5')
|
| 40 |
+
|
| 41 |
+
for i in range(len(set_0)):
|
| 42 |
+
table_0[0,i+1]=set_0[i]
|
| 43 |
+
|
| 44 |
+
k=1
|
| 45 |
+
l=0
|
| 46 |
+
for item in table:
|
| 47 |
+
if item=='\n' or item=='|':
|
| 48 |
+
table_0=table_0
|
| 49 |
+
else:
|
| 50 |
+
table_0[k,l]=item
|
| 51 |
+
l=l+1
|
| 52 |
+
if(l==6):
|
| 53 |
+
l=0
|
| 54 |
+
k=k+1
|
| 55 |
+
|
| 56 |
+
for i in range(1,len(set_0)+1):
|
| 57 |
+
for j in range(1,len(set_0)+1):
|
| 58 |
+
if (table_0[i,j]!=table_0[j,i]):
|
| 59 |
+
return f"Not commutative, because of the elements: {set_0[i-1]} and {set_0[j-1]}"
|
| 60 |
+
return "It is commutative"
|
| 61 |
+
|
| 62 |
class Web_research(Tool):
|
| 63 |
name="web_search"
|
| 64 |
description = "Web search on a specific topic."
|