(self, mistakes: List[Tuple[str, str, str, str]])
| 131 | return mistakes |
| 132 | |
| 133 | def generate_low_level_principles(self, mistakes: List[Tuple[str, str, str, str]]) -> List[str]: |
| 134 | logger.info("Generating low-level principles from mistakes") |
| 135 | for question, generated_reasoning, generated_answer, correct_answer in mistakes: |
| 136 | # Prepare request for logging |
| 137 | provider_request = { |
| 138 | "model": self.model, |
| 139 | "max_tokens": self.max_tokens, |
| 140 | "messages": [ |
| 141 | {"role": "system", "content": self.system_prompt}, |
| 142 | {"role": "user", "content": f""" |
| 143 | Question: {question} |
| 144 | Generated Reasoning: {generated_reasoning} |
| 145 | Generated Answer: {generated_answer} |
| 146 | Correct Answer: {correct_answer} |
| 147 | Instruction: Conduct a thorough analysis of the generated answer in comparison to the |
| 148 | correct answer. Also observe how the generated reasoning differs from the correct |
| 149 | reasoning. Identify any discrepancies, misunderstandings, or errors. Provide clear |
| 150 | insights, principles, or guidelines that can be derived from this analysis to improve |
| 151 | future responses. We are not focused on this one data point, but rather on the general |
| 152 | principle. |
| 153 | Reasoning: <discuss why the generated answer is wrong> |
| 154 | Insights: Enclose ONLY the principles or insights within <output></output> tags. |
| 155 | """} |
| 156 | ] |
| 157 | } |
| 158 | |
| 159 | response = self.client.chat.completions.create(**provider_request) |
| 160 | |
| 161 | # Log provider call if conversation logging is enabled |
| 162 | if hasattr(optillm, 'conversation_logger') and optillm.conversation_logger and self.request_id: |
| 163 | response_dict = response.model_dump() if hasattr(response, 'model_dump') else response |
| 164 | optillm.conversation_logger.log_provider_call(self.request_id, provider_request, response_dict) |
| 165 | self.leap_completion_tokens += response.usage.completion_tokens |
| 166 | self.low_level_principles.append(self.extract_output(self._extract_content(response, "generating low-level principles"))) |
| 167 | return self.low_level_principles |
| 168 | |
| 169 | def generate_high_level_principles(self) -> List[str]: |
| 170 | logger.info("Generating high-level principles from low-level principles") |
no test coverage detected