MCPcopy Create free account
hub / github.com/grapeot/devin.cursorrules / encode_image_file

Function encode_image_file

tools/llm_api.py:49–66  ·  view source on GitHub ↗

Encode an image file to base64 and determine its MIME type. Args: image_path (str): Path to the image file Returns: tuple: (base64_encoded_string, mime_type)

(image_path: str)

Source from the content-addressed store, hash-verified

47load_environment()
48
49def encode_image_file(image_path: str) -> tuple[str, str]:
50 """
51 Encode an image file to base64 and determine its MIME type.
52
53 Args:
54 image_path (str): Path to the image file
55
56 Returns:
57 tuple: (base64_encoded_string, mime_type)
58 """
59 mime_type, _ = mimetypes.guess_type(image_path)
60 if not mime_type:
61 mime_type = 'image/png' # Default to PNG if type cannot be determined
62
63 with open(image_path, "rb") as image_file:
64 encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
65
66 return encoded_string, mime_type
67
68def create_llm_client(provider="openai"):
69 if provider == "openai":

Callers 1

query_llmFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected