| 10532 | |
| 10533 | |
| 10534 | class MTMDProcessor: |
| 10535 | @dataclass |
| 10536 | class MediaChunk: |
| 10537 | kind: Literal["image", "audio", "video"] |
| 10538 | key: str |
| 10539 | chunk: Any |
| 10540 | n_tokens: int |
| 10541 | decode_n_pos: int |
| 10542 | non_causal: bool |
| 10543 | embeddings: Optional[np.ndarray] = None |
| 10544 | |
| 10545 | @dataclass |
| 10546 | class ParsedChunk: |
| 10547 | text_tokens: Optional[List[int]] = None |
| 10548 | media: Optional["MTMDProcessor.MediaChunk"] = None |
| 10549 | |
| 10550 | def __init__( |
| 10551 | self, |
| 10552 | *, |
| 10553 | model_path: str, |
| 10554 | llama_model: Any, |
| 10555 | chat_formatter: Jinja2ChatFormatter, |
| 10556 | tokenize: Callable[..., List[int]], |
| 10557 | n_embd_inp: int, |
| 10558 | n_batch: int, |
| 10559 | n_ubatch: int, |
| 10560 | n_threads_batch: int, |
| 10561 | mmproj_path: str, |
| 10562 | batch_max_tokens: int, |
| 10563 | embedding_cache: Optional[MTMDEmbeddingCache], |
| 10564 | allowed_media_domains: Optional[List[str]], |
| 10565 | allowed_local_media_path: Optional[str], |
| 10566 | image_max_bytes: int, |
| 10567 | audio_max_bytes: int, |
| 10568 | video_max_bytes: int, |
| 10569 | image_timeout_seconds: float, |
| 10570 | ) -> None: |
| 10571 | self.chat_formatter = chat_formatter |
| 10572 | self.tokenize = tokenize |
| 10573 | self.n_embd_inp = n_embd_inp |
| 10574 | self.n_batch = n_batch |
| 10575 | self.n_ubatch = n_ubatch |
| 10576 | self.mmproj_path = mmproj_path |
| 10577 | self.embedding_cache = embedding_cache |
| 10578 | self.batch_max_tokens = batch_max_tokens |
| 10579 | self.model_fingerprint = MTMDEmbeddingCache.fingerprint_file(model_path) |
| 10580 | self.mmproj_fingerprint = MTMDEmbeddingCache.fingerprint_file(mmproj_path) |
| 10581 | self.allowed_media_domains = ( |
| 10582 | {domain.lower() for domain in allowed_media_domains} |
| 10583 | if allowed_media_domains is not None |
| 10584 | else set() |
| 10585 | ) |
| 10586 | self.allowed_local_media_path = ( |
| 10587 | Path(allowed_local_media_path).expanduser().resolve() |
| 10588 | if allowed_local_media_path is not None |
| 10589 | else None |
| 10590 | ) |
| 10591 | self.image_max_bytes = image_max_bytes |
no outgoing calls
no test coverage detected
searching dependent graphs…