feat: Add support for custom LLM describers
This PR addresses issue #1129 by introducing a flexible and extensible way to use any multimodal Large Language Model for image descriptions, not just OpenAI models.
Instead of hardcoding support for specific LLM providers like Gemini or Claude, this PR introduces a new llm_describber callback function. This allows users to define their own logic for generating image descriptions, making the library compatible with any LLM provider.
Key Changes:
- The
MarkItDownclass now accepts anllm_describberfunction in its constructor. - The
llm_describberis propagated to all converters that handle image descriptions (ImageConverter,PptxConverter). - The implementation is backward-compatible. If
llm_describberis not provided, the library falls back to the existingllm_client/llm_modellogic for OpenAI models. - Added a new test to ensure the
llm_describberis called correctly. - Updated the
README.mdto document the new functionality.
Example Usage:
from markitdown import MarkItDown
def my_custom_describber(data_uri: str, prompt: str) -> str:
# Add logic to call any LLM API
return f"Custom description for prompt '{prompt}'"
md = MarkItDown(llm_describber=my_custom_describber)
result = md.convert("my_image.jpg")
print(result.markdown)
This approach provides maximum flexibility and avoids the need to add specific support for each new LLM provider in the future.
@microsoft-github-policy-service agree
@Jhonnyr97 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
@microsoft-github-policy-service agree [company="{your company}"]Options:
- (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
- (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"Contributor License Agreement
@microsoft-github-policy-service agree