~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix: Fix LLM factory function validation in get_llm
LearningCircuit318a5d881ecf
diff --git a/src/local_deep_research/config/llm_config.py b/src/local_deep_research/config/llm_config.pyindex d85c7c9779..29e536a5cc 100644--- a/src/local_deep_research/config/llm_config.py+++ b/src/local_deep_research/config/llm_config.py@@ -1,6 +1,5 @@import osfrom functools import cache-from typing import Union, Callablefrom langchain_anthropic import ChatAnthropicfrom langchain_community.llms import VLLM@@ -8,7 +7,6 @@ from langchain_core.language_models import BaseChatModel, FakeListChatModelfrom langchain_ollama import ChatOllamafrom langchain_openai import ChatOpenAIfrom loguru import logger-from pydantic import TypeAdapter, ValidationErrorfrom ..llm import get_llm_from_registry, is_llm_registeredfrom ..utilities.search_utilities import remove_think_tags@@ -260,37 +258,32 @@ def get_llm(logger.info(f"Using registered custom LLM: {provider}")custom_llm = get_llm_from_registry(provider)- # Use Pydantic to validate the type- llm_validator = TypeAdapter(Union[BaseChatModel, Callable])-- try:- # Validate that it's either a BaseChatModel or a Callable- llm_validator.validate_python(custom_llm)+ # Check if it's a callable (factory function) or a BaseChatModel instance+ if callable(custom_llm) and not isinstance(custom_llm, BaseChatModel):+ # It's a callable (factory function), call it with parameters+ try:+ llm_instance = custom_llm(+ model_name=model_name,+ temperature=temperature,+ )+ except TypeError as e:+ # This happens when passing a class instead of instance or factory+ raise ValueError(+ f"Registered LLM {provider} appears to be a class. "+ f"Please register either an instance or a factory function, not a class. "+ f"Error: {e}"+ )- if isinstance(custom_llm, BaseChatModel):- # It's already a proper LLM instance, use it directly- llm_instance = custom_llm- else:- # It's a callable (factory function), call it with parameters- try:- llm_instance = custom_llm(- model_name=model_name,- temperature=temperature,- )- # Validate the result is a BaseChatModel- if not isinstance(llm_instance, BaseChatModel):- raise ValueError(- f"Factory function for {provider} must return a BaseChatModel instance, "- f"got {type(llm_instance).__name__}"- )- except TypeError as e:- # This happens when passing a class instead of instance or factory- raise ValueError(- f"Registered LLM {provider} appears to be a class. "- f"Please register either an instance or a factory function, not a class. "- f"Error: {e}"- )- except ValidationError:+ # Validate the result is a BaseChatModel+ if not isinstance(llm_instance, BaseChatModel):+ raise ValueError(+ f"Factory function for {provider} must return a BaseChatModel instance, "+ f"got {type(llm_instance).__name__}"+ )+ elif isinstance(custom_llm, BaseChatModel):+ # It's already a proper LLM instance, use it directly+ llm_instance = custom_llm+ else:raise ValueError(f"Registered LLM {provider} must be either a BaseChatModel instance "f"or a callable factory function. Got: {type(custom_llm).__name__}"