Fix: Handle missing tiktoken dependency in LazyLiteLLM#4850
Fix: Handle missing tiktoken dependency in LazyLiteLLM#4850paipeline wants to merge 1 commit intoAider-AI:mainfrom
Conversation
Adds proper error handling in LazyLiteLLM._load_litellm() to gracefully handle ModuleNotFoundError when litellm's dependencies (like tiktoken) are missing. Provides clear error messages with installation instructions. Fixes issue Aider-AI#4848 where users encountered uncaught ModuleNotFoundError for 'tiktoken' when aider tried to load litellm during model sanity checks. The fix: - Catches ImportError and ModuleNotFoundError during litellm import - Provides specific error message for tiktoken missing case - Gives generic helpful message for other missing dependencies - Suggests reinstallation command to resolve the issue This prevents the cryptic stack trace and gives users actionable guidance.
My two cents:
The I propose that this PR not be merged. |
Problem
Users encounter uncaught ModuleNotFoundError for 'tiktoken' when aider tries to load litellm during model sanity checks (issue #4848). This results in a cryptic stack trace that doesn't provide actionable guidance.
Root Cause
The LazyLiteLLM._load_litellm() method imports litellm without error handling. When litellm's dependencies (like tiktoken) are missing, the import fails with an unhelpful stack trace.
Solution
Added proper error handling in _load_litellm() to:
Changes
Testing
Verified the fix handles both tiktoken-specific errors and general import errors gracefully, providing actionable error messages instead of stack traces.
Fixes #4848