mirror of
https://github.com/LearningCircuit/local-deep-research.git
synced 2026-06-15 19:46:56 +03:00
* fix: unify SettingsManagers, fix env var bugs, delete duplicate Two parallel SettingsManager implementations existed (settings/manager.py and web/services/settings_manager.py) that diverged accidentally, each with different bugs. This unifies them into a single implementation. Bug fixes in settings/manager.py: - get_setting() now checks env vars when setting is not in DB (was jumping straight to return default, ignoring env override) - get_all_settings() now type-converts env overrides through get_typed_setting_value() (was storing raw strings like "true" instead of True) - create_or_update_setting() now correctly checks db_setting.editable (was checking input dict's .editable which caused AttributeError) - Added missing ui_element types: textarea, multiselect Features added to settings/manager.py: - get_bool_setting() method (required by rag_routes.py) - default_settings now loads all 18 JSON files via rglob (was only loading 1 file with 370 settings, now loads 526) All production and test imports updated from web.services.settings_manager to settings.manager. Duplicate web/services/settings_manager.py deleted. 314 tests pass across 7 test files. 9 new tests cover bug fixes. * test: add 29 tests for unified SettingsManager coverage gaps (#2071) Cover create_or_update_setting (8 tests), default_settings property (4), _ensure_settings_initialized (2), new UI element types textarea/multiselect/ range (4), _emit_settings_changed error resilience (3), plus edge cases for get_setting check_env=False, get_all_settings with locked settings, get_bool_setting with integers, parse_boolean edge cases, and env override type conversion for text settings. * fix: add missing abstract methods, env var defaults override, and type bug (#2074) - Add get_bool_setting() and get_settings_snapshot() abstract methods to ISettingsManager base class so the interface contract is complete - Fix create_or_update_setting: use setting_obj.type directly instead of SettingType[setting_obj.type.upper()] which fails when type is already a SettingType enum from the Pydantic model - Add env var override in get_all_settings() defaults loop so settings not yet in DB can still be overridden via LDR_* environment variables - Fix test_get_all_settings_db_error to expect defaults on DB failure (graceful degradation after unification) * refactor: deduplicate provider availability checks and settings wrapper (#2054) (#2068) - Delegate 5 provider availability functions in llm_config.py to their existing provider class is_available() methods (OpenAI, Anthropic, CustomOpenAIEndpoint, Ollama, LMStudio) - Extract _get_or_create_status() helper in queue_service.py to eliminate duplicated QueueStatus lookup-or-create pattern - Centralize get_llm_setting_from_snapshot() in thread_settings.py, replacing 6 identical copy-pasted wrappers across provider files - Update test mock targets to reflect new delegation pattern * fix: add missing abstract method implementations to InMemorySettingsManager InMemorySettingsManager was missing get_bool_setting() and get_settings_snapshot() implementations required by the ISettingsManager ABC, causing TypeError on instantiation and cascading failures in LLM unit tests, REST API tests, and Puppeteer auth tests. * fix: convert web SettingType to database SettingType in create_or_update_setting The PR changed `type=SettingType[setting_obj.type.upper()]` to `type=setting_obj.type`, but setting_obj.type is a web model SettingType (str, Enum) while Setting.type expects the database SettingType (enum.Enum). This causes a 500 error when creating new settings via PUT endpoint. Use `.name` for cleaner enum-to-enum conversion instead of `.upper()`. * fix: add multiselect type conversion and warn on untyped env overrides (#2080) Address review feedback from @djpetti on PR #2070: 1. Replace multiselect `lambda x: x` with `_parse_multiselect()` that properly handles env var strings — parses JSON arrays (e.g. '["markdown","latex"]') and comma-separated values (e.g. 'markdown,latex') while passing through lists from SQLAlchemy unchanged. 2. Log a warning when get_setting() encounters an env var override for a setting not in defaults, returning the raw string without type conversion. This surfaces settings that should be added to a defaults JSON file to get proper type information. Tests: 14 new tests (111 total in test_settings_manager.py, 0 failures) * test: add tests for consolidated UI element-to-type mapping Verifies single canonical _UI_ELEMENT_TO_SETTING_TYPE is reused by both InMemorySettingsManager and SettingsManager.
66 lines
2.3 KiB
Markdown
66 lines
2.3 KiB
Markdown
# Important: Examples Updated for LDR v1.0
|
|
|
|
## Authentication Required
|
|
|
|
Starting with LDR v1.0, all API access requires authentication due to the new per-user encrypted database architecture.
|
|
|
|
## Updated Examples
|
|
|
|
The following examples have been updated for v1.0:
|
|
|
|
### ✅ Updated Examples:
|
|
- `http/simple_http_example.py` - Basic HTTP API usage with authentication
|
|
- `http/http_api_examples.py` - Comprehensive HTTP API examples with LDRClient class
|
|
- `programmatic/retriever_usage_example.py` - LangChain retriever integration with auth
|
|
- `programmatic/programmatic_access_v1.py` - NEW: Complete programmatic API examples
|
|
|
|
### ⚠️ Needs Manual Update:
|
|
- `programmatic/programmatic_access.ipynb` - Jupyter notebook (see programmatic_access_v1.py for reference)
|
|
|
|
## Quick Migration Guide
|
|
|
|
### Old Code (pre-v1.0):
|
|
```python
|
|
from local_deep_research.api import quick_summary
|
|
result = quick_summary("query")
|
|
```
|
|
|
|
### New Code (v1.0+):
|
|
```python
|
|
from local_deep_research.api import quick_summary
|
|
from local_deep_research.settings import SettingsManager
|
|
from local_deep_research.database.session_context import get_user_db_session
|
|
|
|
with get_user_db_session(username="user", password="pass") as session:
|
|
settings_manager = SettingsManager(session)
|
|
settings_snapshot = settings_manager.get_all_settings()
|
|
result = quick_summary("query", settings_snapshot=settings_snapshot)
|
|
```
|
|
|
|
## Before Running Examples
|
|
|
|
1. **Create an account**:
|
|
```bash
|
|
python -m local_deep_research.web.app
|
|
# Open http://localhost:5000 and register
|
|
```
|
|
|
|
2. **Configure LLM provider** in Settings (e.g., OpenAI, Anthropic, Ollama)
|
|
|
|
3. **Update credentials** in the example files:
|
|
- Change `USERNAME = "your_username"` to your actual username
|
|
- Change `PASSWORD = "your_password"` to your actual password
|
|
|
|
## Common Issues
|
|
|
|
- **"No settings context available"**: Pass `settings_snapshot` to API functions
|
|
- **"Encrypted database requires password"**: Use `get_user_db_session()` with credentials
|
|
- **"CSRF token missing"**: Get CSRF token before POST/PUT/DELETE requests
|
|
- **404 errors**: Check new endpoint paths (e.g., `/api/start_research`)
|
|
|
|
## Need Help?
|
|
|
|
- See [Migration Guide](../../docs/MIGRATION_GUIDE_v1.md) for detailed changes
|
|
- Check [API Quick Start](../../docs/api-quickstart.md) for authentication details
|
|
- Join our [Discord](https://discord.gg/ttcqQeFcJ3) for support
|