MCPcopy Create free account
hub / github.com/codefuse-ai/codefuse-devops-eval / calc

Method calc

src/evals/func_call_evalution.py:50–91  ·  view source on GitHub ↗

开始计算结果

(self)

Source from the content-addressed store, hash-verified

48 raise BaseException(f"must be ToolModel Class! not {model}")
49
50 def calc(self):
51 '''开始计算结果'''
52 self.predicts = []
53 func_call_train_datas = self.create_prompts(self.dataset)
54
55 for idx, data in enumerate(func_call_train_datas):
56 print(f"总共 {len(func_call_train_datas)} 条prompt,当前运行到第 {idx} 条prompt", end="\r")
57 prompt = data["instruction"]
58 history = data["history"]
59 answer = data["output"]
60 functions = data["functions"]
61 predict = self.generate(prompt, self.template, self.generate_configs, history)
62
63 if "arguments" in answer:
64 answer = {"content": answer["content"], "function_call": {"name": answer["name"], "arguments": answer["arguments"]}}
65
66 if "#function" in predict:
67 try:
68 predict_param = json.loads(predict.split("#function")[-1])
69 if "arguments" in predict_param:
70 predict_param = {
71 "content": predict_param["content"],
72 "function_call": {"name": predict_param["name"], "arguments": predict_param["arguments"]}
73 }
74 predict = {**predict_param, **{"role": "assistant"}}
75 except Exception as e:
76 logger.error("content: {content}")
77 predict = {**{"content": predict_param}, **{"role": "assistant"}}
78 else:
79 predict = {
80 "role": "assistant",
81 "content": predict
82 }
83
84 self.predicts.append({
85 "prompt": prompt, "history": history,
86 "predict": predict, "answer": answer,
87 "functions": functions
88 })
89
90 metric = self.eval_metric(self.predicts)
91 return metric
92
93 def calc_from_predicts(self, file_path):
94 if os.path.exists(file_path):

Callers 1

calc_from_predictsMethod · 0.95

Calls 3

create_promptsMethod · 0.95
generateMethod · 0.95
eval_metricMethod · 0.95

Tested by

no test coverage detected