Files
local-deep-research/examples/llm_integration
LearningCircuit 901d0db8d9 fix(examples): make mock LLM example truly offline + reject search.tool='none' (#3520)
* ci: skip live-network LLM examples, keep compile-checked

The basic_custom_llm.py and advanced_custom_llm.py examples execute a
real research pipeline that hits Wikipedia and PubMed. Under the job's
60s timeout they flake whenever those services are slow (seen on #3467
and elsewhere).

Drop the two exec steps from llm-example-tests, add both files to the
compile-check block so syntax/import regressions are still caught, and
leave mock_llm_example.py running since it exercises the same
integration path offline.

* fix(examples): make mock LLM example truly offline + reject search.tool='none'

The mock example claimed to run "offline" with `search.tool: "none"`, but
the factory silently fell back to the `auto` engine and dispatched real
searches to PubMed/Wikipedia — which is why the `LLM Example Tests` CI
job still timed out at 60s after #3478 removed the other two examples.

- `MockRetriever` is now a proper `langchain_core.retrievers.BaseRetriever`
  at module scope, so `RetrieverSearchEngine.run`'s `.invoke(query)` call
  actually works (previously the inner class was only discovered via the
  broad `except Exception` path and returned no results).
- The three `main()` tests that used `search.tool: "none"` now register
  the mock retriever and use `search.tool: "mock_retriever"`.
- `create_search_engine` rejects the literal string `"none"` with a
  `ValueError` so this silent-fallback class of bug cannot recur.

End-to-end run of the example in the project venv completes in ~13s with
no network traffic; previously this timed out at 60s hitting NCBI and
en.wikipedia.org.

* test(factory): regression coverage for search.tool='none' guard

Asserts that create_search_engine('none', ...) raises ValueError rather
than silently falling through to the 'auto' engine — the exact failure
mode that broke the mock LLM example in CI.
2026-04-18 15:45:27 +02:00
..

LLM Integration Examples

This directory contains examples of integrating custom LangChain LLMs with Local Deep Research.

Examples

1. Basic Custom LLM (basic_custom_llm.py)

Shows the simplest way to create and use a custom LLM with LDR.

2. Advanced Custom LLM (advanced_custom_llm.py)

Demonstrates advanced features like:

  • Factory functions with configuration
  • Multiple LLM registration
  • Combining with custom retrievers
  • Error handling and retry logic

3. Fine-tuned Model Integration (finetuned_model_example.py)

Example of using a fine-tuned model for domain-specific research.

4. Mock LLM for Testing (mock_llm_example.py)

Shows how to create mock LLMs for testing your research pipelines without API costs.

5. Rate-Limited Wrapper (rate_limited_llm.py)

Demonstrates wrapping any LLM with rate limiting to avoid API limits.

Running the Examples

  1. Install Local Deep Research:
pip install local-deep-research
  1. Run an example:
python examples/llm_integration/basic_custom_llm.py

Key Concepts

  • BaseChatModel: All custom LLMs must inherit from langchain_core.language_models.BaseChatModel
  • Factory Functions: Can be used to create LLMs with dynamic configuration
  • Registration: LLMs are registered via the llms parameter in API functions
  • Provider Selection: Use the registered name as the provider parameter

Common Use Cases

  1. Fine-tuned Models: Use models trained on your specific domain
  2. Custom Wrappers: Add logging, retry logic, or preprocessing
  3. Mock Testing: Test research flows without real LLM calls
  4. Rate Limiting: Manage API quotas effectively
  5. Multi-Model Pipelines: Use different models for different research phases