MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / findBase64ImagePayload

Function findBase64ImagePayload

plugins/wasi_nn/GGML/utils.cpp:29–51  ·  view source on GitHub ↗

Get base64 image position if found in prompt.

Source from the content-addressed store, hash-verified

27
28// Get base64 image position if found in prompt.
29std::optional<std::tuple<size_t, size_t, size_t>>
30findBase64ImagePayload(std::string_view Prompt, bool IsDebugLog) noexcept {
31 // Find `<img src="data:image/`
32 auto BeginTagPos = Prompt.find(Base64ImageTagPrefix);
33 if (BeginTagPos == std::string::npos) {
34 // Not print debug log here because not expect image must occur in every
35 // prompt.
36 return std::nullopt;
37 }
38 // Find `;base64,` (skip the image type part)
39 auto PayloadPos = Prompt.find(Base64ImageBytesPrefix, BeginTagPos);
40 if (PayloadPos == std::string::npos) {
41 LOG_DEBUG(IsDebugLog, "base64: Cannot locate the payload."sv)
42 return std::nullopt;
43 }
44 // Find `">`
45 auto EndTagPos = Prompt.find(Base64ImageTagSuffix, PayloadPos);
46 if (EndTagPos == std::string::npos) {
47 LOG_DEBUG(IsDebugLog, "base64: image tag unclosed."sv)
48 return std::nullopt;
49 }
50 return std::make_tuple(BeginTagPos, PayloadPos, EndTagPos);
51}
52
53// Extract base64 image payload and image type. Replace it with placeholder.
54std::optional<std::pair<std::vector<uint8_t>, std::string>>

Callers 1

setInputFunction · 0.85

Calls 1

findMethod · 0.45

Tested by

no test coverage detected