Skip to content

fix(chat): identify remote image requests with a user agent - #2411

Open
hakarrr wants to merge 4 commits into
abetlen:mainfrom
hakarrr:image-user-agent-1229
Open

hakarrr wants to merge 4 commits into
abetlen:mainfrom
hakarrr:image-user-agent-1229

Conversation

@hakarrr

@hakarrr hakarrr commented Nov 10, 2026

Copy link
Copy Markdown

Fixes #1229.

Send User-Agent: llama-cpp-python when fetching remote images in Llava15ChatHandler and the independent MTMDChatHandler loader. The Llava-derived handlers inherit the same change. This identifies the package instead of relying on urllib's default Python-urllib/... user agent; it does not impersonate a browser or claim to fix every server's HTTP 403 policy.

The change only wraps the URL in urllib.request.Request before opening it. Data-URI decoding is unchanged. File URLs, response bytes and HTTP errors retain their existing behavior. Redirect handling stays with urllib; the added regression checks HTTP 302, not every redirect status.

Validation

  • New tests use a loopback HTTP server that rejects requests without the expected package user agent, including a redirect to the image endpoint. No external image service is called.
  • Both independent loaders are checked for exact returned bytes, user agent across redirects, HTTP 404 propagation, unchanged data-URI decoding without network access, and file-URL loading.
  • New tests against the unmodified source: 4 failed, 6 passed. The failures are the direct HTTP and redirected fetches for each loader.
  • Full patched python -m pytest tests -q: 36 passed, no skips (26 existing tests plus 10 new cases), including the existing native/model-backed suite.
  • Fetched all three published files byte-for-byte, confirmed the exact reviewed patch, then reran the full 36-test suite and lint/format from that branch.
  • ruff check llama_cpp tests, ruff format --check llama_cpp tests, and git diff --check: passed.

Environment: Python 3.11.17, Linux x86_64 CPU, GCC 11.4, CMake 3.22.1; pinned llama.cpp 7d7f0287530bc8981690f361d8c1627dbae1c99a, built with GGML_NATIVE=OFF, GGML_OPENMP=OFF, GGML_BLAS=OFF. No new dependency or native-code change. The added tests exercise image fetching, not multimodal image decoding or vision inference.

hakarrr and others added 4 commits November 11, 2026 05:04
Set an honest package User-Agent in the independent Llava15 and MTMD image loaders. Preserve data/file handling and HTTP errors. Fixes abetlen#1229.

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Use a local HTTP server to test direct and redirected package identity, exact payloads and HTTP errors for both loaders. Preserve data and file URLs without native vision fixtures.

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Record the user-visible image request compatibility change under Unreleased.

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>
Complete the contribution guide's changelog format with abetlen#2411.

Co-authored-by: GeneralTony007 <144252170+GeneralTony007@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

Set User Agent for Llava15ChatHandler load_image()

1 participant