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