Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/llama_stack_client/lib/inference/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the terms described in the LICENSE file in
# the root directory of this source tree.

import pathlib
import base64


class MessageAttachment:
# https://developer.mozilla.org/en-US/docs/Glossary/Base64
@classmethod
def base64(cls, file_path: str) -> str:
path = pathlib.Path(file_path)
return base64.b64encode(path.read_bytes()).decode("utf-8")

# https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data
@classmethod
def data_url(cls, media_type: str, file_path: str) -> str:
return f"data:{media_type};base64,{cls.base64(file_path)}"