Commit graph

14 commits

Author SHA1 Message Date
yuneng-jiang
6a0d03914c
test: drop the cwd-relative sys.path.insert calls from the test suite (#37802)
* test: drop the cwd-relative sys.path.insert calls from the test suite

TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.

Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.

Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.

* test: drop the duplicate imports the sys.path sweep exposed to F811

* test(pre-call-utils): restore the os import the new bedrock tests need
2026-08-22 09:25:58 -07:00
yuneng-jiang
693797420d
test: unwind environment writes in tests/test_litellm with monkeypatch (#37806)
* test: use monkeypatch.setenv for env writes in tests/test_litellm

`os.environ["X"] = v` inside a test leaks the value into every test that runs
after it in the same worker, so ordering decides the result. 262 of those
writes across 40 files now go through pytest's `monkeypatch` fixture, which
restores the previous value at teardown.

The rewrite skips any test that a mock.patch-family decorator wraps, any test
with defaulted positional parameters, any test whose own name is called
directly elsewhere, and rebinds nothing inside nested defs, because in each of
those cases appending a fixture parameter changes what pytest or mock binds.

Ratchets the TQ004 ceiling from 768 to 506.

* fix(test): delete the key through monkeypatch instead of popping it first

Five tests popped a key straight out of `os.environ`, ran, then restored it with
`monkeypatch.setenv`. By the time monkeypatch saw the name it was already gone,
so it recorded "absent" as the value to go back to and deleted the key at
teardown. On a worker that inherited a real `RESEND_API_KEY`, `SENDGRID_API_KEY`,
`UI_PASSWORD`, `LITELLM_SALT_KEY` or `OPENAI_API_KEY`, every test after the first
one ran without it.

`monkeypatch.delenv(..., raising=False)` removes the key and restores whatever
was there, so the try/finally the manual restore needed goes with it.

* chore(test): leave the two cost-calc files to the PR that rewrites them fully

Both files are also in #37815, which converts the module-global writes as well
as the env writes and folds them into one fixture. Two PRs rewriting the same
lines differently is a conflict nobody benefits from resolving, so this one
drops back to staging on those two and keeps the other 39.

TQ004 clears 200 here instead of 275; the rest moves with #37815.
2026-08-21 20:28:37 -07:00
Sameer Kankute
a2a951a1e9
feat(vertex_ai): pass full imageConfig dict for Gemini image generation (#31811)
* feat(vertex_ai): pass full imageConfig dict for Gemini image generation

Support all ImageConfig fields (aspectRatio, imageSize, personGeneration,
imageOutputOptions) when calling Vertex AI Gemini image generation endpoints.
Previously only aspectRatio and imageSize were extracted; other fields were
silently dropped.

Co-authored-by: Cursor <cursoragent@cursor.com>

* style: ruff format vertex_gemini_transformation

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(vertex_ai): warn on non-dict imageConfig instead of silently dropping

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-01 23:29:59 -07:00
Sameer Kankute
87cf67ec30
feat(gemini): forward web search tools in image generation (#30119)
* feat(gemini): forward web search tools in image generation

Map tools and web_search_options to googleSearch on Gemini image
generateContent requests for Google AI Studio and Vertex AI.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(gemini): dedupe image search tools and return mapped params

Skip web_search_options when tools already include search, dedupe search
tool entries, and assign the return value from map_gemini_image_tools_params.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(gemini): preserve toolConfig side-effects in image tool mapping

* fix(gemini): forward toolConfig in image generation request body

* fix(gemini): track web search grounding cost on image generation

Forwarding Google Search grounding to Gemini and Vertex image
generation previously incurred billable grounding charges that never
reached LiteLLM spend tracking, because the image cost path returns
through the Gemini/Vertex image calculators before built-in tool spend
is added. Carry the grounding request count from the response onto the
image usage object and bill it with the same per-request web search
accounting used for chat completions.

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-06-12 07:24:36 -07:00
Sameer Kankute
2b028a62d8
Merge branch 'litellm_internal_staging' into litellm_vertex_request_metadata_labels
Some checks failed
Unit Tests: Proxy DB Operations / proxy-db (key-generation, tests/proxy_unit_tests/test_key_generate_prisma.py, 30, 0) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (auth-checks, tests/proxy_unit_tests/test_auth_checks.py tests/proxy_unit_tests/test_user_api_key_auth.py, 20, 8) (push) Has been cancelled
Unit Tests: Proxy DB Operations / proxy-db (remaining, tests/proxy_unit_tests --ignore=tests/proxy_unit_tests/test_key_generate_prisma.py --ignore=tests/proxy_unit_tests/test_auth_checks.py --ignore=tests/proxy_unit_tests/test_user_api_key_auth.py, 30, 8) (push) Has been cancelled
Unit Tests: Security / security (push) Has been cancelled
2026-04-21 09:10:51 +05:30
Ishaan Jaffer
e8461b5b97
style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
Sameer Kankute
ec004a54e9
feat(vertex_ai): propagate metadata labels to embedding, Imagen, rerank
- Add pop_vertex_request_labels / vertex_request_labels_from_litellm_params in common_utils
- Vertex embeddings: pass litellm_params, set predict body labels; Gemini uses shared helper
- Imagen: top-level labels from metadata; rerank: userLabels for Discovery Engine Rank API
- Thread litellm_params through rerank handler and all BaseRerankConfig implementations

Made-with: Cursor
2026-04-02 09:56:56 +05:30
Chesars
155bed57e8 fix(vertex_ai): pass through native Gemini imageConfig params for image generation
aspectRatio and imageSize were silently dropped because they weren't
listed in get_supported_openai_params(), so the validation layer filtered
them out before they could reach transform_image_generation_request().

Fixes #21070
2026-02-19 15:39:27 -03:00
Chesars
11fd92c21b refactor(image-gen): move thought_signature to provider_specific_fields
Per review feedback, thought_signature should not be a root-level
param on ImageObject as it's not OpenAI compatible. Moved to
provider_specific_fields dict to match the pattern used in chat
completions (Message, Delta, Choices, etc).
2026-02-02 18:12:41 +05:30
Chesars
b2463291c7 fix(image-gen): add thought_signature to ImageObject for Gemini 3 Pro
Fixes #17184 - Gemini 3 Pro image preview model returns a thoughtSignature
field required for interactive image editing. This change:

- Adds thought_signature field to ImageObject class
- Updates Gemini and Vertex AI transformations to extract thoughtSignature
- Adds test for thought_signature in response transformation
2026-02-02 18:12:28 +05:30
Dmitrii Komarov
df9d3abf49
Propagate token usage when generating images with Gemini (#17987) 2025-12-16 08:20:09 +05:30
Ishaan Jaffer
ce60453855 test_gemini_get_complete_url 2025-11-26 14:35:03 -08:00
Ishaan Jaffer
44e3133827 test_imagen_get_complete_url 2025-11-26 12:26:49 -08:00
Sameer Kankute
883cfaeeaf Add tests 2025-11-25 13:32:13 +05:30