MCPcopy Create free account
hub / github.com/abetlen/llama-cpp-python / _create_loaded_media

Method _create_loaded_media

examples/server/server.py:10727–10767  ·  view source on GitHub ↗
(
        self,
        media: MediaInput,
        media_bytes: bytes,
    )

Source from the content-addressed store, hash-verified

10725 return data
10726
10727 def _create_loaded_media(
10728 self,
10729 media: MediaInput,
10730 media_bytes: bytes,
10731 ) -> MTMDLoadedMedia:
10732 key = (
10733 self.embedding_cache.key_for_media(media.kind, media_bytes)
10734 if self.embedding_cache is not None
10735 else MTMDEmbeddingCache._build_key(
10736 model_fingerprint=self.model_fingerprint,
10737 mmproj_fingerprint=self.mmproj_fingerprint,
10738 kind=media.kind,
10739 media_bytes=media_bytes,
10740 )
10741 )
10742 if media.kind == "video":
10743 return self._create_loaded_video_media(media, media_bytes, key)
10744 buffer = (ctypes.c_uint8 * len(media_bytes)).from_buffer_copy(media_bytes)
10745 wrapper = mtmd_cpp.mtmd_helper_bitmap_init_from_buf_wrapper(
10746 self.ctx,
10747 buffer,
10748 len(media_bytes),
10749 False,
10750 )
10751 bitmap = wrapper.bitmap
10752 if bitmap is None:
10753 raise CompletionRequestValidationError(f"failed to create MTMD {media.kind} bitmap")
10754 mtmd_cpp.mtmd_bitmap_set_id(bitmap, key.encode("utf-8"))
10755 video_frame_count = 0
10756 video_ctx = wrapper.video_ctx
10757 if video_ctx:
10758 video_info = mtmd_cpp.mtmd_helper_video_get_info(video_ctx)
10759 video_frame_count = max(0, int(video_info.n_frames))
10760 return MTMDLoadedMedia(
10761 media=media,
10762 media_bytes=media_bytes,
10763 key=key,
10764 bitmap=bitmap,
10765 video_ctx=video_ctx,
10766 video_frame_count=video_frame_count,
10767 )
10768
10769 @staticmethod
10770 def _video_temp_suffix(media: MediaInput) -> str:

Callers 1

Calls 6

MTMDLoadedMediaClass · 0.85
key_for_mediaMethod · 0.80
_build_keyMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected