(self, doc: Any)
| 1091 | raise TypeError |
| 1092 | |
| 1093 | def doc_to_choice(self, doc: Any) -> List[str]: |
| 1094 | if self.prompt is not None: |
| 1095 | doc_to_choice = self.prompt |
| 1096 | elif self.config.doc_to_choice is None: |
| 1097 | eval_logger.error("doc_to_choice was called but not set in config") |
| 1098 | else: |
| 1099 | doc_to_choice = self.config.doc_to_choice |
| 1100 | |
| 1101 | if isinstance(doc_to_choice, str): |
| 1102 | if doc_to_choice in self.features: |
| 1103 | return doc[doc_to_choice] |
| 1104 | else: |
| 1105 | return ast.literal_eval(utils.apply_template(doc_to_choice, doc)) |
| 1106 | elif isinstance(doc_to_choice, list): |
| 1107 | return doc_to_choice |
| 1108 | elif isinstance(doc_to_choice, dict): |
| 1109 | return list(doc_to_choice.values()) |
| 1110 | elif callable(doc_to_choice): |
| 1111 | return doc_to_choice(doc) |
| 1112 | elif hasattr(doc_to_choice, "get_answer_choices_list"): |
| 1113 | return doc_to_choice.get_answer_choices_list(doc) |
| 1114 | else: |
| 1115 | raise TypeError |
| 1116 | |
| 1117 | def construct_requests( |
| 1118 | self, doc: dict, ctx: str, **kwargs |
no test coverage detected