mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-06 22:12:12 +02:00
refactor(models): remove manual model registration backend
This commit is contained in:
parent
31ec939da9
commit
0df51c60f3
4 changed files with 0 additions and 65 deletions
|
|
@ -21,7 +21,6 @@ from app.schemas import (
|
|||
ConnectionCreate,
|
||||
ConnectionRead,
|
||||
ConnectionUpdate,
|
||||
ModelCreate,
|
||||
ModelPreviewRead,
|
||||
ModelProviderRead,
|
||||
ModelRead,
|
||||
|
|
@ -618,49 +617,6 @@ async def discover_connection_models(
|
|||
return [_model_read(model) for model in conn.models]
|
||||
|
||||
|
||||
@router.post("/model-connections/{connection_id}/models", response_model=ModelRead)
|
||||
async def add_manual_model(
|
||||
connection_id: int,
|
||||
data: ModelCreate,
|
||||
session: AsyncSession = Depends(get_async_session),
|
||||
auth: AuthContext = Depends(get_auth_context),
|
||||
):
|
||||
conn = await _load_connection(session, connection_id)
|
||||
await _assert_connection_access(
|
||||
session, auth, conn, Permission.LLM_CONFIGS_UPDATE.value
|
||||
)
|
||||
|
||||
model_id = data.model_id.strip()
|
||||
if not model_id:
|
||||
raise HTTPException(status_code=400, detail="model_id is required")
|
||||
if any(existing.model_id == model_id for existing in conn.models):
|
||||
raise HTTPException(
|
||||
status_code=400, detail="Model already exists on this connection"
|
||||
)
|
||||
|
||||
capabilities = derive_capabilities(conn, model_id)
|
||||
model = Model(
|
||||
connection_id=conn.id,
|
||||
model_id=model_id,
|
||||
display_name=data.display_name or None,
|
||||
source=ModelSource.MANUAL,
|
||||
capabilities_override={},
|
||||
enabled=True,
|
||||
catalog={},
|
||||
)
|
||||
_apply_model_facts(model, capabilities)
|
||||
session.add(model)
|
||||
await session.commit()
|
||||
await session.refresh(model)
|
||||
conn = await _load_connection(session, connection_id)
|
||||
await _default_unset_roles(session, conn, list(conn.models))
|
||||
if conn.search_space_id is not None:
|
||||
await _clear_invalid_roles(session, conn.search_space_id)
|
||||
await session.commit()
|
||||
await session.refresh(model)
|
||||
return _model_read(model)
|
||||
|
||||
|
||||
@router.patch(
|
||||
"/model-connections/{connection_id}/models", response_model=list[ModelRead]
|
||||
)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ from .model_connections import (
|
|||
ConnectionCreate,
|
||||
ConnectionRead,
|
||||
ConnectionUpdate,
|
||||
ModelCreate,
|
||||
ModelPreviewRead,
|
||||
ModelProviderRead,
|
||||
ModelRead,
|
||||
|
|
@ -203,7 +202,6 @@ __all__ = [
|
|||
"MembershipRead",
|
||||
"MembershipReadWithUser",
|
||||
"MembershipUpdate",
|
||||
"ModelCreate",
|
||||
"ModelPreviewRead",
|
||||
"ModelProviderRead",
|
||||
"ModelRead",
|
||||
|
|
|
|||
|
|
@ -93,17 +93,6 @@ class ConnectionUpdate(BaseModel):
|
|||
enabled: bool | None = None
|
||||
|
||||
|
||||
class ModelCreate(BaseModel):
|
||||
"""Manually register a model id on a connection.
|
||||
|
||||
For providers without a usable ``/models`` endpoint (Perplexity, MiniMax,
|
||||
Azure deployments, etc.) or to pin a single model from a noisy provider.
|
||||
"""
|
||||
|
||||
model_id: str = Field(..., max_length=255)
|
||||
display_name: str | None = Field(None, max_length=255)
|
||||
|
||||
|
||||
class ModelUpdate(BaseModel):
|
||||
display_name: str | None = Field(None, max_length=255)
|
||||
enabled: bool | None = None
|
||||
|
|
|
|||
|
|
@ -202,11 +202,6 @@ def _discovery_error_message(conn: Connection, exc: httpx.HTTPError) -> str:
|
|||
return _docker_hint(base_url, exc)
|
||||
|
||||
|
||||
def _allowlist(conn: Connection) -> set[str]:
|
||||
raw = (conn.extra or {}).get("model_ids") or []
|
||||
return {str(item).strip() for item in raw if str(item).strip()}
|
||||
|
||||
|
||||
def _litellm_info(model_string: str, model_id: str) -> dict[str, Any]:
|
||||
with contextlib.suppress(Exception):
|
||||
info = litellm.get_model_info(model=model_string)
|
||||
|
|
@ -438,7 +433,6 @@ async def _discover_bedrock_models(conn: Connection) -> list[dict[str, Any]]:
|
|||
|
||||
|
||||
async def discover_models(conn: Connection) -> list[dict[str, Any]]:
|
||||
allowlist = _allowlist(conn)
|
||||
spec = spec_for(conn.provider)
|
||||
|
||||
try:
|
||||
|
|
@ -459,8 +453,6 @@ async def discover_models(conn: Connection) -> list[dict[str, Any]]:
|
|||
except httpx.HTTPError as exc:
|
||||
raise ModelDiscoveryError(_discovery_error_message(conn, exc)) from exc
|
||||
|
||||
if allowlist:
|
||||
results = [item for item in results if item["model_id"] in allowlist]
|
||||
return results
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue