MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / acc

Method acc

AgentBench.old/src/tasks/dbbench/__init__.py:178–212  ·  view source on GitHub ↗
(inp: List[Dict[str, Any]], tar: List[str])

Source from the content-addressed store, hash-verified

176 def metrics(self) -> Dict[str, Callable[[List[Dict[str, Any]], List[str]], float]]:
177 def factory(typ):
178 def acc(inp: List[Dict[str, Any]], tar: List[str]) -> float:
179 correct = 0
180 total = 0
181 for entry, cor in zip(inp, tar):
182 if not entry:
183 continue
184 ans, t = entry["answer"], entry["type"]
185 if t != typ and not (typ == "SELECT" and t not in ("INSERT", "UPDATE")):
186 continue
187 if t in ("INSERT", "DELETE", "UPDATE"):
188 correct += ans == cor
189 else:
190 try:
191 ans = list(eval(ans))
192 except:
193 ans = [ans]
194 if len(ans) == 1 and len(cor) == 1:
195 try:
196 correct += float(ans[0]) == float(cor[0])
197 except (ValueError, TypeError):
198 correct += ans[0] == cor[0]
199 else:
200 print(ans, cor)
201 else:
202 try:
203 cor = set(cor)
204 ans = set(ans)
205 correct += ans == cor
206 except:
207 pass
208 total += 1
209 if total == 0:
210 print(f"WARNING: {typ} does not exist!")
211 return 0
212 return correct / total
213
214 return acc
215

Callers

nothing calls this directly

Calls 1

evalFunction · 0.85

Tested by

no test coverage detected