mirror of
https://github.com/LearningCircuit/local-deep-research.git
synced 2026-06-15 19:46:56 +03:00
* 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.
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
- Install Local Deep Research:
pip install local-deep-research
- 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
llmsparameter in API functions - Provider Selection: Use the registered name as the
providerparameter
Common Use Cases
- Fine-tuned Models: Use models trained on your specific domain
- Custom Wrappers: Add logging, retry logic, or preprocessing
- Mock Testing: Test research flows without real LLM calls
- Rate Limiting: Manage API quotas effectively
- Multi-Model Pipelines: Use different models for different research phases