Fix diagram analysis for local LLMs by using base64 encoding instead of URLs#57
Open
androemeda wants to merge 1 commit intovirtualcell:mainfrom
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug in diagram analysis that caused failures when using local LLM deployments. Local LLMs cannot process remote image URLs and require base64-encoded image data instead. This change makes diagram analysis work correctly with both local and cloud-based LLM configurations.
Problem
The
analyse_diagramfunction was passing the diagram as a remote URL directly to the model:{"type": "image_url", "image_url": {"url": diagram_url}}Local LLMs (Ollama, LocalAI, etc.) do not support fetching remote URLs during inference and expect image data to be provided directly in base64 format. This caused the following error:
Fix
Replaced the remote URL approach with base64 encoding — the image bytes are fetched in Python and encoded before being passed to the model:
{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{diagram_base64}"}}This is fully backward compatible — OpenAI and Azure OpenAI continue to work correctly with the base64 format.
Changes
backend/app/services/llms_service.py— replacedget_diagram_url()withget_diagram_image()to fetch raw image bytes, added base64 encoding before passing image to the model.Testing
Endpoint:
GET http://localhost:8000/analyse/{biomodel_id}/diagramTest case:
http://localhost:8000/analyse/306747843/diagramPROVIDER=local)"image URLs are not currently supported, please use base64 encoded data instead"