| 75 | return segments |
| 76 | |
| 77 | def wrap_inference(self, inference_function: Callable[[List[dict]], str]) -> Callable[[List[dict]], str]: |
| 78 | def _func(history: List[dict]) -> str: |
| 79 | if self.exception_raised: |
| 80 | return "" |
| 81 | messages = self.filter_messages(history) |
| 82 | try: |
| 83 | result = inference_function(messages) |
| 84 | except Exception as e: |
| 85 | print(e) |
| 86 | import traceback |
| 87 | traceback.print_exc() |
| 88 | print("Warning: Exception raised during inference.") |
| 89 | self.exception_raised = True |
| 90 | result = "" |
| 91 | return result |
| 92 | return _func |
| 93 | |
| 94 | def filter_messages(self, messages: List[Dict]) -> List[Dict]: |
| 95 | try: |