Validate and preprocess raw input messages into API-ready format. Args: msg: Raw input message (str, dict, or list). Returns: list: Preprocessed message list in OpenAI format. Raises: AssertionError: If input type is unsupported.
(self, msg)
| 396 | return self.fail_msg |
| 397 | |
| 398 | def pre_process(self, msg): |
| 399 | """Validate and preprocess raw input messages into API-ready format. |
| 400 | |
| 401 | Args: |
| 402 | msg: Raw input message (str, dict, or list). |
| 403 | |
| 404 | Returns: |
| 405 | list: Preprocessed message list in OpenAI format. |
| 406 | |
| 407 | Raises: |
| 408 | AssertionError: If input type is unsupported. |
| 409 | """ |
| 410 | assert self.check_content(msg) in [ |
| 411 | "str", |
| 412 | "dict", |
| 413 | "liststr", |
| 414 | "listdict", |
| 415 | ], f"Unsupported input type: {msg}" |
| 416 | |
| 417 | msg = self.preproc_content(msg) |
| 418 | assert msg is not None and self.check_content(msg) == "listdict" |
| 419 | |
| 420 | for item in msg: |
| 421 | assert ( |
| 422 | item["type"] in self.allowed_types |
| 423 | ), f'Unsupported input type: {item["type"]}' |
| 424 | |
| 425 | # Prepare input messages |
| 426 | processed_msg, _ = self.prepare_inputs(msg) |
| 427 | return processed_msg |
| 428 | |
| 429 | def _pre_encode_images(self, messages): |
| 430 | """Pre-encode all PIL images to base64 strings in parallel. |