Make HuggingFace models optional with graceful ImportError handling#99
Open
PositiveMike33 wants to merge 2 commits intokyegomez:mainfrom
Open
Make HuggingFace models optional with graceful ImportError handling#99PositiveMike33 wants to merge 2 commits intokyegomez:mainfrom
PositiveMike33 wants to merge 2 commits intokyegomez:mainfrom
Conversation
- Add PyTorch as optional dependency in setup.py with extras_require['huggingface'] - Add torch>=2.0.0 to requirements.txt - Wrap transformers imports in try/except block in huggingface_model.py - Add HUGGINGFACE_AVAILABLE flag to gracefully handle missing PyTorch - Add clear error messages when attempting to use HuggingFace models without PyTorch - Make HuggingFace model imports conditional in __init__.py to prevent import errors Users can now install with: pip install tree-of-thoughts[huggingface] to get PyTorch support for HuggingFace models. This fixes the issue where PyTorch was not declared as a dependency even though it was needed for HuggingFace model support, causing warnings from transformers.
…roq, DeepSeek, Ollama, LM Studio) - Implement AnthropicLanguageModel with claude-4.5-haiku as default model - Add GroqLanguageModel for Grok/Mixtral models via Groq API - Add DeepSeekLanguageModel for DeepSeek API integration - Add OllamaLanguageModel for local Ollama instances - Add LMStudioLanguageModel for LM Studio local deployment - All models implement AbstractLanguageModel interface - Support both 'value' and 'vote' evaluation strategies - Environment variable configuration for API keys and endpoints - Complete generate_thoughts() and evaluate_states() implementations
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 PR makes HuggingFace model dependencies optional by adding conditional imports and graceful error handling. Users can now install the package without PyTorch/transformers and only install these dependencies when needed via an optional extras group.
Key Changes
huggingface_model.py: Wrapped transformers imports in a try-except block with aHUGGINGFACE_AVAILABLEflag to detect if dependencies are installedHuggingLanguageModelandHFPipelineModelconstructors that provide helpful installation instructions when dependencies are missing__init__.py: Made HuggingFace model imports conditional, setting them toNoneif transformers is unavailable, allowing the package to load successfully without these dependenciesextras_requirewith ahuggingfacegroup that specifiestorch>=2.0.0as an optional dependencyImplementation Details
HUGGINGFACE_AVAILABLEflag is set at module import time, allowing early detection of missing dependenciespip install tree-of-thoughts[huggingface]for a better experience__init__.pyprevents the entire package from failing to import if transformers is unavailablehttps://claude.ai/code/session_01VYXewQoaCJ3yZaQtQWDVfq