fix(litellm): defer import until model usage#2462
Closed
OiPunk wants to merge 2 commits intoopenai:mainfrom
Closed
fix(litellm): defer import until model usage#2462OiPunk wants to merge 2 commits intoopenai:mainfrom
OiPunk wants to merge 2 commits intoopenai:mainfrom
Conversation
Contributor
Author
|
Follow-up fix pushed for CI typecheck failure (new commit: Root cause:
What I changed:
Local re-validation:
|
Member
|
We'd like to hold off having this change just to avoid UnicodeDecodeError on Windows OS. Indeed, UnicodeDecodeError is confusing but changing the timing to check the module existence later on does not make sense here. |
Contributor
Author
|
Thanks for the clear guidance. Agreed on holding this change for now. I am closing this PR to avoid churn; if priorities change later, I can reopen with a narrower proposal aligned with this direction. |
Contributor
Author
|
Closed per maintainer direction in this thread. |
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
This defers
litellmimport inlitellm_model.pyso importingagents.extensions.models.litellm_modeldoes not eagerly import LiteLLM.This targets issue #610, where Windows users hit
UnicodeDecodeErrorat module import time.What changed
import litellmwith a lazy loader (_import_litellm) and a module proxy.Why this helps
litellm_modelno longer fails immediately due to LiteLLM import-time issues.Testing
uv run --with ruff ruff check src/agents/extensions/models/litellm_model.py tests/models/test_litellm_deferred_import.py tests/models/test_litellm_user_agent.py tests/models/test_map.pyuv run --with pytest pytest -q tests/models/test_litellm_deferred_import.py tests/models/test_litellm_user_agent.py tests/models/test_map.pyuv run --with litellm --with pytest pytest -q tests/models/test_kwargs_functionality.py tests/models/test_litellm_extra_body.pyuv run --with pytest python -m trace --count --coverdir /tmp/openai_agents_610_trace_1770722012 --module pytest tests/models/test_litellm_deferred_import.py -qTrace output confirms all newly added lazy-import branches were executed.