mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
refactor: use SQL filtering and pagination in VerifiedModelStore (#13068)
Co-authored-by: bittoby <brianwhitedev1996@gmail.com> Co-authored-by: statxc <statxc@user.noreply.github.com> Co-authored-by: bittoby <bittoby@users.noreply.github.com> Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -6,9 +6,10 @@
|
||||
# Unless you are working on deprecation, please avoid extending this legacy file and consult the V1 codepaths above.
|
||||
# Tag: Legacy-V0
|
||||
# This module belongs to the old V0 web server. The V1 application server lives under openhands/app_server/.
|
||||
|
||||
from typing import Any
|
||||
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
|
||||
from openhands.controller.agent import Agent
|
||||
from openhands.security.options import SecurityAnalyzers
|
||||
@@ -19,45 +20,21 @@ from openhands.utils.llm import get_supported_llm_models
|
||||
app = APIRouter(prefix='/api/options', dependencies=get_dependencies())
|
||||
|
||||
|
||||
@app.get('/models', response_model=list[str])
|
||||
async def get_litellm_models() -> list[str]:
|
||||
"""Get all models supported by LiteLLM.
|
||||
async def get_llm_models_dependency(request: Request) -> list[str]:
|
||||
"""Returns a callable that provides the LLM models implementation.
|
||||
|
||||
This function combines models from litellm and Bedrock, removing any
|
||||
error-prone Bedrock models. In SaaS mode, it uses database-backed
|
||||
verified models for dynamic updates without code deployments.
|
||||
|
||||
To get the models:
|
||||
```sh
|
||||
curl http://localhost:3000/api/litellm-models
|
||||
```
|
||||
|
||||
Returns:
|
||||
list[str]: A sorted list of unique model names.
|
||||
Returns a factory that produces the actual implementation function.
|
||||
Override this in enterprise/saas mode via app.dependency_overrides.
|
||||
"""
|
||||
verified_models = _load_verified_models_from_db()
|
||||
return get_supported_llm_models(config, verified_models)
|
||||
|
||||
return get_supported_llm_models(config, [])
|
||||
|
||||
|
||||
def _load_verified_models_from_db() -> list[str] | None:
|
||||
"""Try to load verified models from the database (SaaS mode only).
|
||||
|
||||
Returns:
|
||||
List of model strings like 'provider/model_name' if available, None otherwise.
|
||||
"""
|
||||
try:
|
||||
from storage.verified_model_store import VerifiedModelStore
|
||||
except ImportError:
|
||||
return None
|
||||
|
||||
try:
|
||||
db_models = VerifiedModelStore.get_enabled_models()
|
||||
return [f'{m.provider}/{m.model_name}' for m in db_models]
|
||||
except Exception:
|
||||
from openhands.core.logger import openhands_logger as logger
|
||||
|
||||
logger.exception('Failed to load verified models from database')
|
||||
return None
|
||||
@app.get('/models')
|
||||
async def get_litellm_models(
|
||||
models: list[str] = Depends(get_llm_models_dependency),
|
||||
) -> list[str]:
|
||||
return models
|
||||
|
||||
|
||||
@app.get('/agents', response_model=list[str])
|
||||
|
||||
Reference in New Issue
Block a user