Skip to content

Conversation

@tanreinama
Copy link
Contributor

in _get_llm_description function, base64 and mimetypes used, but not imported.

client = OpenAI()
md = MarkItDown(llm_client=client, llm_model="gpt-4o")
result = md.convert("example.jpg")
>>> NameError: name 'mimetypes' is not defined

in packages/markitdown/src/markitdown/converters/_image_converter.py line #65;

    def _get_llm_description(self, local_path, extension, client, model, prompt=None):                                          if prompt is None or prompt.strip() == "":
            prompt = "Write a detailed caption for this image."

        data_uri = ""
        with open(local_path, "rb") as image_file:
>>>            content_type, encoding = mimetypes.guess_type("_dummy" + extension)
            if content_type is None:
                content_type = "image/jpeg"
>>>            image_base64 = base64.b64encode(image_file.read()).decode("utf-8")
            data_uri = f"data:{content_type};base64,{image_base64}"

@afourney
Copy link
Member

Oooof, I was overly aggressive when refactoring it seems. Thanks for the fix.

@afourney afourney merged commit a87fbf0 into microsoft:main Feb 28, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants