mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-14 20:55:15 +02:00
refactor(model-connections): remove unused fields and update verification logic
This commit is contained in:
parent
3ba92dca13
commit
7926814070
7 changed files with 2 additions and 35 deletions
|
|
@ -153,9 +153,6 @@ def upgrade() -> None:
|
|||
),
|
||||
sa.Column("search_space_id", sa.Integer(), nullable=True),
|
||||
sa.Column("user_id", sa.UUID(), nullable=True),
|
||||
sa.Column("last_verified_at", sa.TIMESTAMP(timezone=True), nullable=True),
|
||||
sa.Column("last_status", sa.String(length=50), nullable=True),
|
||||
sa.Column("last_error", sa.Text(), nullable=True),
|
||||
sa.CheckConstraint(
|
||||
"(scope = 'GLOBAL' AND search_space_id IS NULL AND user_id IS NULL) OR "
|
||||
"(scope = 'SEARCH_SPACE' AND search_space_id IS NOT NULL AND user_id IS NOT NULL) OR "
|
||||
|
|
@ -210,7 +207,6 @@ def upgrade() -> None:
|
|||
server_default=sa.text("'{}'::jsonb"),
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("embedding_dimension", sa.Integer(), nullable=True),
|
||||
sa.Column(
|
||||
"enabled", sa.Boolean(), server_default=sa.text("true"), nullable=False
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1554,10 +1554,6 @@ class Connection(BaseModel, TimestampMixin):
|
|||
UUID(as_uuid=True), ForeignKey("user.id", ondelete="CASCADE"), nullable=True
|
||||
)
|
||||
|
||||
last_verified_at = Column(TIMESTAMP(timezone=True), nullable=True)
|
||||
last_status = Column(String(50), nullable=True)
|
||||
last_error = Column(Text, nullable=True)
|
||||
|
||||
search_space = relationship("SearchSpace", back_populates="connections")
|
||||
user = relationship("User", back_populates="connections")
|
||||
models = relationship(
|
||||
|
|
@ -1603,7 +1599,6 @@ class Model(BaseModel, TimestampMixin):
|
|||
capabilities_override = Column(
|
||||
JSONB, nullable=False, default=dict, server_default="{}"
|
||||
)
|
||||
embedding_dimension = Column(Integer, nullable=True)
|
||||
enabled = Column(Boolean, nullable=False, default=True, server_default="true")
|
||||
billing_tier = Column(String(50), nullable=True, index=True)
|
||||
catalog = Column(JSONB, nullable=False, default=dict, server_default="{}")
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ from app.services.model_connection_service import (
|
|||
ModelDiscoveryError,
|
||||
derive_capabilities,
|
||||
discover_models,
|
||||
persist_verification,
|
||||
test_model,
|
||||
verify_connection,
|
||||
)
|
||||
from app.services.provider_registry import REGISTRY
|
||||
from app.users import current_active_user
|
||||
|
|
@ -92,9 +92,6 @@ def _connection_read(
|
|||
user_id=conn.user_id,
|
||||
enabled=conn.enabled,
|
||||
has_api_key=bool(conn.api_key),
|
||||
last_verified_at=conn.last_verified_at,
|
||||
last_status=conn.last_status,
|
||||
last_error=conn.last_error,
|
||||
models=[_model_read(model) for model in (models or [])],
|
||||
created_at=conn.created_at,
|
||||
)
|
||||
|
|
@ -536,8 +533,7 @@ async def verify_model_connection(
|
|||
await _assert_connection_access(
|
||||
session, user, conn, Permission.LLM_CONFIGS_CREATE.value
|
||||
)
|
||||
result = await persist_verification(conn)
|
||||
await session.commit()
|
||||
result = await verify_connection(conn)
|
||||
return VerifyConnectionResponse(
|
||||
status=result.status, ok=result.ok, message=result.message
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ class ModelRead(BaseModel):
|
|||
supports_tools: bool | None = None
|
||||
supports_image_generation: bool | None = None
|
||||
capabilities_override: dict[str, Any] = Field(default_factory=dict)
|
||||
embedding_dimension: int | None = None
|
||||
enabled: bool
|
||||
billing_tier: str | None = None
|
||||
catalog: dict[str, Any] = Field(default_factory=dict)
|
||||
|
|
@ -39,9 +38,6 @@ class ConnectionRead(BaseModel):
|
|||
user_id: uuid.UUID | None = None
|
||||
enabled: bool
|
||||
has_api_key: bool
|
||||
last_verified_at: datetime | None = None
|
||||
last_status: str | None = None
|
||||
last_error: str | None = None
|
||||
models: list[ModelRead] = Field(default_factory=list)
|
||||
created_at: datetime | None = None
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ def materialize_global_model_catalog(
|
|||
conn = native_connection_from_config(config)
|
||||
conn["scope"] = "GLOBAL"
|
||||
conn["enabled"] = True
|
||||
conn["last_status"] = "OK"
|
||||
key = _connection_key(conn)
|
||||
connection_id = connection_id_by_key.get(key)
|
||||
if connection_id is None:
|
||||
|
|
@ -105,7 +104,6 @@ def materialize_global_model_catalog(
|
|||
"supports_tools": bool(config.get("supports_tools", False)),
|
||||
"supports_image_generation": role == "image_gen",
|
||||
"capabilities_override": {},
|
||||
"embedding_dimension": None,
|
||||
"enabled": True,
|
||||
"billing_tier": config.get("billing_tier", "free"),
|
||||
"catalog": _catalog_metadata(config),
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ from __future__ import annotations
|
|||
import contextlib
|
||||
import logging
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
import anyio
|
||||
|
|
@ -186,14 +185,6 @@ async def verify_connection(conn: Connection) -> VerifyResult:
|
|||
return VerifyResult("UNREACHABLE", False, _docker_hint(base_url, exc))
|
||||
|
||||
|
||||
async def persist_verification(conn: Connection) -> VerifyResult:
|
||||
result = await verify_connection(conn)
|
||||
conn.last_verified_at = datetime.now(UTC)
|
||||
conn.last_status = result.status
|
||||
conn.last_error = "" if result.ok else result.message
|
||||
return result
|
||||
|
||||
|
||||
def _discovery_error_message(conn: Connection, exc: httpx.HTTPError) -> str:
|
||||
base_url = _base_url_or_default(conn)
|
||||
if isinstance(exc, httpx.HTTPStatusError):
|
||||
|
|
@ -494,7 +485,6 @@ __all__ = [
|
|||
"VerifyResult",
|
||||
"derive_capabilities",
|
||||
"discover_models",
|
||||
"persist_verification",
|
||||
"test_model",
|
||||
"verify_connection",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ export const modelRead = z.object({
|
|||
supports_tools: z.boolean().nullable().optional(),
|
||||
supports_image_generation: z.boolean().nullable().optional(),
|
||||
capabilities_override: z.record(z.string(), z.any()).default({}),
|
||||
embedding_dimension: z.number().nullable().optional(),
|
||||
enabled: z.boolean(),
|
||||
billing_tier: z.string().nullable().optional(),
|
||||
catalog: z.record(z.string(), z.any()).default({}),
|
||||
|
|
@ -33,9 +32,6 @@ export const connectionRead = z.object({
|
|||
user_id: z.string().nullable().optional(),
|
||||
enabled: z.boolean(),
|
||||
has_api_key: z.boolean(),
|
||||
last_verified_at: z.string().nullable().optional(),
|
||||
last_status: z.string().nullable().optional(),
|
||||
last_error: z.string().nullable().optional(),
|
||||
models: z.array(modelRead).default([]),
|
||||
created_at: z.string().nullable().optional(),
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue