(
self,
*,
model_path: str,
llama_model: Any,
chat_formatter: Jinja2ChatFormatter,
tokenize: Callable[..., List[int]],
n_embd_inp: int,
n_batch: int,
n_ubatch: int,
n_threads_batch: int,
mmproj_path: str,
batch_max_tokens: int,
embedding_cache: Optional[MTMDEmbeddingCache],
allowed_media_domains: Optional[List[str]],
allowed_local_media_path: Optional[str],
image_max_bytes: int,
audio_max_bytes: int,
video_max_bytes: int,
image_timeout_seconds: float,
)
| 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 |
| 10592 | self.audio_max_bytes = audio_max_bytes |
| 10593 | self.video_max_bytes = video_max_bytes |
| 10594 | self.image_timeout_seconds = image_timeout_seconds |
| 10595 | self.lock = threading.Lock() |
| 10596 | params = mtmd_cpp.mtmd_context_params_default() |
| 10597 | params.n_threads = max(1, n_threads_batch) |
| 10598 | params.batch_max_tokens = batch_max_tokens |
| 10599 | self.ctx = mtmd_cpp.mtmd_init_from_file( |
| 10600 | mmproj_path.encode("utf-8"), |
| 10601 | llama_model, |
| 10602 | params, |
| 10603 | ) |
| 10604 | if self.ctx is None: |
| 10605 | raise RuntimeError(f"failed to load MTMD context: {mmproj_path}") |
| 10606 | self.supports_vision = bool(mtmd_cpp.mtmd_support_vision(self.ctx)) |
| 10607 | self.supports_audio = bool(mtmd_cpp.mtmd_support_audio(self.ctx)) |
nothing calls this directly
no test coverage detected