chore: import upstream snapshot with attribution
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
This commit is contained in:
Executable
+202
@@ -0,0 +1,202 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Update LLM configuration in the database for benchmarks.
|
||||
|
||||
This script updates the LLM configuration in the database to ensure
|
||||
consistent behavior when running benchmarks with different LLM models.
|
||||
|
||||
Usage:
|
||||
# Install dependencies with PDM
|
||||
cd /path/to/local-deep-research
|
||||
pdm install
|
||||
|
||||
# Run the script with PDM
|
||||
pdm run python examples/optimization/update_llm_config.py --model "google/gemini-2.0-flash" --provider "openai_endpoint" --endpoint "https://openrouter.ai/api/v1" --api-key "your-api-key"
|
||||
|
||||
# Or to reset to default configuration
|
||||
pdm run python examples/optimization/update_llm_config.py --reset
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from loguru import logger
|
||||
|
||||
# Add the src directory to the Python path
|
||||
project_root = str(Path(__file__).parent.parent.parent.resolve())
|
||||
sys.path.insert(0, str(Path(project_root) / "src"))
|
||||
|
||||
|
||||
def update_llm_configuration(
|
||||
model_name: Optional[str] = None,
|
||||
provider: Optional[str] = None,
|
||||
endpoint_url: Optional[str] = None,
|
||||
api_key: Optional[str] = None,
|
||||
temperature: Optional[float] = None,
|
||||
reset: bool = False,
|
||||
) -> bool:
|
||||
"""
|
||||
Update LLM configuration in the database.
|
||||
|
||||
Args:
|
||||
model_name: LLM model name to set
|
||||
provider: LLM provider to set
|
||||
endpoint_url: Endpoint URL for OpenRouter or similar services
|
||||
api_key: API key for the provider
|
||||
temperature: Temperature setting for the LLM
|
||||
reset: If True, reset to default configuration
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
# Import database utility functions
|
||||
try:
|
||||
from local_deep_research.utilities.db_utils import (
|
||||
get_db_setting,
|
||||
update_db_setting,
|
||||
)
|
||||
except ImportError:
|
||||
logger.exception(
|
||||
"Could not import database utilities. Make sure you're in the correct directory."
|
||||
)
|
||||
return False
|
||||
|
||||
# Default configuration
|
||||
default_config = {
|
||||
"llm.model": "gemma3:12b",
|
||||
"llm.provider": "ollama",
|
||||
"llm.temperature": 0.7,
|
||||
"llm.max_tokens": 30000,
|
||||
}
|
||||
|
||||
try:
|
||||
if reset:
|
||||
# Reset to default configuration
|
||||
logger.info("Resetting LLM configuration to defaults")
|
||||
|
||||
for key, value in default_config.items():
|
||||
update_db_setting(key, value)
|
||||
logger.info(f"Reset {key} to {value}")
|
||||
|
||||
# Clear API keys
|
||||
update_db_setting("llm.openai_endpoint.api_key", "")
|
||||
update_db_setting("llm.openai_endpoint.url", "")
|
||||
|
||||
logger.info("LLM configuration reset to defaults")
|
||||
return True
|
||||
|
||||
# Update model and provider if provided
|
||||
if model_name:
|
||||
update_db_setting("llm.model", model_name)
|
||||
logger.info(f"Updated llm.model to {model_name}")
|
||||
|
||||
if provider:
|
||||
update_db_setting("llm.provider", provider)
|
||||
logger.info(f"Updated llm.provider to {provider}")
|
||||
|
||||
if temperature is not None:
|
||||
update_db_setting("llm.temperature", temperature)
|
||||
logger.info(f"Updated llm.temperature to {temperature}")
|
||||
|
||||
# Handle provider-specific settings
|
||||
if provider == "openai_endpoint":
|
||||
if endpoint_url:
|
||||
update_db_setting("llm.openai_endpoint.url", endpoint_url)
|
||||
logger.info(
|
||||
f"Updated llm.openai_endpoint.url to {endpoint_url}"
|
||||
)
|
||||
|
||||
if api_key:
|
||||
update_db_setting("llm.openai_endpoint.api_key", api_key)
|
||||
logger.info(
|
||||
"Updated llm.openai_endpoint.api_key (value hidden)"
|
||||
)
|
||||
|
||||
elif provider == "openai":
|
||||
if api_key:
|
||||
update_db_setting("llm.openai.api_key", api_key)
|
||||
logger.info("Updated llm.openai.api_key (value hidden)")
|
||||
|
||||
elif provider == "anthropic":
|
||||
if api_key:
|
||||
update_db_setting("llm.anthropic.api_key", api_key)
|
||||
logger.info("Updated llm.anthropic.api_key (value hidden)")
|
||||
|
||||
# Verify settings were updated
|
||||
current_model = get_db_setting("llm.model")
|
||||
current_provider = get_db_setting("llm.provider")
|
||||
|
||||
logger.info(
|
||||
f"Current LLM configuration: model={current_model}, provider={current_provider}"
|
||||
)
|
||||
|
||||
if provider == "openai_endpoint":
|
||||
endpoint = get_db_setting("llm.openai_endpoint.url")
|
||||
has_key = bool(get_db_setting("llm.openai_endpoint.api_key"))
|
||||
logger.info(f"OpenAI Endpoint URL: {endpoint}")
|
||||
logger.info(f"Has API key: {has_key}")
|
||||
|
||||
return True
|
||||
|
||||
except Exception:
|
||||
logger.exception("Error updating LLM configuration")
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Update LLM configuration in the database"
|
||||
)
|
||||
|
||||
# Configuration options
|
||||
parser.add_argument("--model", help="LLM model name")
|
||||
parser.add_argument(
|
||||
"--provider",
|
||||
help="LLM provider (e.g., 'anthropic', 'openai', 'openai_endpoint')",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--endpoint", help="Endpoint URL for OpenRouter or similar services"
|
||||
)
|
||||
parser.add_argument("--api-key", help="API key for the provider")
|
||||
parser.add_argument(
|
||||
"--temperature", type=float, help="Temperature setting for the LLM"
|
||||
)
|
||||
|
||||
# Reset option
|
||||
parser.add_argument(
|
||||
"--reset", action="store_true", help="Reset to default configuration"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Check if any argument is provided
|
||||
if not any(
|
||||
[
|
||||
args.model,
|
||||
args.provider,
|
||||
args.endpoint,
|
||||
args.api_key,
|
||||
args.temperature,
|
||||
args.reset,
|
||||
]
|
||||
):
|
||||
parser.print_help()
|
||||
return 1
|
||||
|
||||
# Update LLM configuration
|
||||
success = update_llm_configuration(
|
||||
model_name=args.model,
|
||||
provider=args.provider,
|
||||
endpoint_url=args.endpoint,
|
||||
api_key=args.api_key,
|
||||
temperature=args.temperature,
|
||||
reset=args.reset,
|
||||
)
|
||||
|
||||
return 0 if success else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user