Add Support for Multiple OCR/LLM Models Beyond OpenAI (Anthropic, Hugging Face, Local LLMs) #14
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.
Overview
This PR implements support for multiple OCR/LLM models beyond OpenAI, addressing issue #4. The implementation allows users to choose between different model providers (OpenAI, Anthropic, Hugging Face, and local LLMs via llama.cpp) for document processing and semantic chunking.
Changes Made
1.Model Provider Infrastructure:
Added a new models package with provider implementations:
base.py: Abstract base classes and factory for model providers
openai_provider.py: OpenAI implementation
anthropic_provider.py: Anthropic Claude implementation
huggingface_provider.py: Hugging Face models implementation
local_provider.py: Local LLM implementation using llama.cpp
Added config.py for centralized configuration management
2.Model-Agnostic Utilities:
Added model_utils.py with model-agnostic implementations of:
Semantic chunking
Document text extraction
Image processing
Main Process Updates:
Updated the main process function in Unsiloed/init.py to support different model providers and their credentials
Added a new modelProvider parameter to specify which model to use
Enhanced credential handling to support different API keys for different providers
Chunking Service Updates:
Modified Unsiloed/services/chunking.py to use model-agnostic functions
Added a provider_name parameter to pass the selected model provider
Updated result metadata to include information about the model provider used
Chunking Utilities:
Updated Unsiloed/utils/chunking.py to use model-agnostic semantic chunking
Modified the semantic chunking function to support multiple model providers
Dependency Management:
Updated setup.py to add optional dependencies for different model providers:
anthropic for Claude models
huggingface_hub for Hugging Face models
llama-cpp-python for local LLM models
Documentation:
Updated README.md with comprehensive documentation for using different model providers
Added examples showing how to use each model provider
Added information about environment variables for different providers
Updated installation instructions to include optional dependencies
##How to Use
Users can now specify which model provider to use:
Environment Variables
Added support for the following environment variables:
OPENAI_API_KEY: OpenAI API key
ANTHROPIC_API_KEY: Anthropic API key
HUGGINGFACE_API_KEY: Hugging Face API key
LOCAL_MODEL_PATH: Path to local LLM model
UNSILOED_MODEL_PROVIDER: Default model provider
Installation Options
Users can now install with specific model providers:
Testing
The implementation has been tested with:
OpenAI GPT-4o for semantic chunking
Different chunking strategies (fixed, semantic, paragraph, heading, page)
Various document types (PDF, DOCX, PPTX)
Closes #4
/claim #4