(self)
| 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") |
| 171 | principles_text = "\n".join(self.low_level_principles) |
| 172 | # Prepare request for logging |
| 173 | provider_request = { |
| 174 | "model": self.model, |
| 175 | "max_tokens": self.max_tokens, |
| 176 | "messages": [ |
| 177 | {"role": "system", "content": self.system_prompt}, |
| 178 | {"role": "user", "content": f""" |
| 179 | Low-level principles: {principles_text} |
| 180 | Create a list of *unique* and insightful principles to improve future responses based |
| 181 | on the analysis above. |
| 182 | Focus on capturing the essence of the feedback while eliminating redundancies. |
| 183 | Ensure that each point is clear, concise, and directly derived from the introspection |
| 184 | results. |
| 185 | Create a numbered list of principles. Leave specific details in place. |
| 186 | Limit to at most 8 principles. |
| 187 | Enclose your list of principles within <output></output> tags. |
| 188 | """} |
| 189 | ] |
| 190 | } |
| 191 | |
| 192 | response = self.client.chat.completions.create(**provider_request) |
| 193 | |
| 194 | # Log provider call if conversation logging is enabled |
| 195 | if hasattr(optillm, 'conversation_logger') and optillm.conversation_logger and self.request_id: |
| 196 | response_dict = response.model_dump() if hasattr(response, 'model_dump') else response |
| 197 | optillm.conversation_logger.log_provider_call(self.request_id, provider_request, response_dict) |
| 198 | self.leap_completion_tokens += response.usage.completion_tokens |
| 199 | self.high_level_principles = self.extract_output(self._extract_content(response, "generating high-level principles")).split("\n") |
| 200 | return self.high_level_principles |
| 201 | |
| 202 | def apply_principles(self, query: str) -> str: |
| 203 | logger.info("Applying learned principles to query") |
no test coverage detected