MCPcopy Create free account
hub / github.com/OpenBMB/ToolBench / to_json

Method to_json

toolbench/inference/Algorithms/single_chain.py:29–60  ·  view source on GitHub ↗
(self, answer=False,process=True)

Source from the content-addressed store, hash-verified

27 self.success_count = 0
28
29 def to_json(self, answer=False,process=True):
30 if process:
31 json_obj = {
32 "win": self.status == 1,
33 "try_count": len(self.try_list),
34 "trys": self.try_list,
35 "compare_candidates": [],
36 "forward_args":self.forward_args,
37 }
38 for node in self.terminal_node:
39 if node.pruned == False: # has final answer
40 json_obj["compare_candidates"].append(node.get_chain_result_from_this_node(use_messages=False))
41 else:
42 json_obj = {}
43
44 if answer:
45 json_obj["answer_generation"] = {
46 "valid_data": False,
47 "final_answer": "",
48 "function": self.io_func.functions,
49 "query_count": self.query_count,
50 "total_tokens": self.total_tokens,
51 "train_messages": [],
52 "chain": [],
53 }
54 for node in self.terminal_node:
55 if node.pruned == False:
56 json_obj["answer_generation"]["valid_data"] = True
57 json_obj["answer_generation"]["final_answer"] = node.description
58 json_obj["answer_generation"]["train_messages"] = node.get_train_messages_from_this_node()
59 break
60 return json_obj
61
62 def to_json_single(self):
63 """parse the last try

Callers

nothing calls this directly

Tested by

no test coverage detected