MCPcopy Create free account
hub / github.com/SalesforceAIResearch/perfcodegen / get_correctness_testcase_feedback

Method get_correctness_testcase_feedback

src/prompt.py:108–138  ·  view source on GitHub ↗
(self, history, testcases = None)

Source from the content-addressed store, hash-verified

106
107
108 def get_correctness_testcase_feedback(self, history, testcases = None):
109 if testcases == None:
110 raise ValueError("Missing testcases.")
111 prompts = {}
112 for prompt in testcases:
113 prompts[prompt] = []
114 for i, testcase in enumerate(testcases[prompt]):
115 if testcase == None:
116 prompts[prompt].append(None)
117 elif testcase in ["PARSE_ERROR", "TIMEOUT"]:
118 message = self.apply_template("correctness_testcase_feedback", 0, {}, condition = "parse_error")
119 prompts[prompt].append(self.build_chat_message(message, history[prompt][i]))
120 elif "model_output" in testcase[0]:
121 if testcase[0]["global"]:
122 testcase_str = "Input: {}\nYour Outputs: {}\nExpected Outputs: {}\n".format(testcase[0]["input"], testcase[0]["model_output"], testcase[0]["output"])
123 else:
124 inputs = [str(i) for i in testcase[0]["input"]]
125 testcase_str = "Input: {}\nYour Outputs: {}\nExpected Outputs: {}\n".format(",".join(inputs), testcase[0]["model_output"], testcase[0]["output"])
126 message = self.apply_template("correctness_testcase_feedback", 0, {"testcase": testcase_str}, condition = "failed_testcase")
127 prompts[prompt].append(self.build_chat_message(message, history[prompt][i]))
128 else:
129 if testcase[0]["global"]:
130 testcase_str = "Input: {}\nExpected Outputs: {}\n".format(testcase[0]["input"], testcase[0]["output"])
131 else:
132 inputs = [str(i) for i in testcase[0]["input"]]
133 testcase_str = "Input: {}\nExpected Outputs: {}\n".format(",".join(inputs), testcase[0]["output"])
134 error = testcase[0]["status_reason"]
135 message = self.apply_template("correctness_testcase_feedback", 0, {"error": error, "testcase": testcase_str}, condition = "runtime_error")
136 prompts[prompt].append(self.build_chat_message(message, history[prompt][i]))
137
138 return prompts
139
140 def get_correctness_reflection_and_feedback(self, rd, history, testcases = None, indicators = None):
141 if testcases == None:

Callers 1

get_chat_promptsMethod · 0.95

Calls 2

apply_templateMethod · 0.95
build_chat_messageMethod · 0.95

Tested by

no test coverage detected