(self, session: Session, sample: Dict)
| 143 | return ret |
| 144 | |
| 145 | def predict_single(self, session: Session, sample: Dict): |
| 146 | if len(sample["pos_ids"]) == 0: |
| 147 | return {"final_prediction": ('', ''), "outputs": []} |
| 148 | pos_ids = sample["pos_ids"] |
| 149 | neg_candidates = sample["neg_candidates"] |
| 150 | neg_candidates = [c for c in neg_candidates if c["rank"] < self.top_k] |
| 151 | neg_ids = [c["backend_node_id"] for c in neg_candidates] |
| 152 | all_candidates = pos_ids + neg_ids |
| 153 | random.shuffle(all_candidates) |
| 154 | final_prediction = None |
| 155 | outputs = [] |
| 156 | while len(all_candidates) > 1: |
| 157 | candidate_ids = all_candidates[:self.candidates_num] # 5 |
| 158 | all_candidates = all_candidates[self.candidates_num:] |
| 159 | seq_context, seq_in, _, choices = format_input_multichoice( |
| 160 | sample, candidate_ids, -1, keep_html_brackets=True |
| 161 | ) |
| 162 | outputs.append( |
| 163 | [candidate_ids, [seq_context, seq_in, choices], None] |
| 164 | ) |
| 165 | self.prompt_template[-1][ |
| 166 | "content" |
| 167 | ] = f"'''\n{seq_context}\n'''\n\n{seq_in}" |
| 168 | |
| 169 | session.history = [] |
| 170 | output = fetch_data(session, self.prompt_template) |
| 171 | # print(session.history[-1]) |
| 172 | # output = "CLICK " |
| 173 | outputs[-1][-1] = output |
| 174 | pred_element, pred_action = self.postprocess_action_llm(output) |
| 175 | if pred_element != "A": |
| 176 | # convert B, C, D to 0, 1, 2 |
| 177 | pred_element = ord(pred_element) - ord("B") |
| 178 | try: |
| 179 | pred_element = choices[pred_element][0] |
| 180 | all_candidates.append(pred_element) |
| 181 | final_prediction = (pred_element, pred_action) |
| 182 | except IndexError: |
| 183 | print(f"IndexError: {output}") |
| 184 | if final_prediction == None or len(all_candidates) == 0: |
| 185 | final_prediction = ('', '') |
| 186 | return {"final_prediction": final_prediction, "outputs": outputs} |
| 187 | |
| 188 | def postprocess_action(self, text): |
| 189 | # C. |
nothing calls this directly
no test coverage detected