Refactor backend to support interface-definition driven model resources
- Introduce a new model structure for managing interface definitions and model resources, enhancing the backend's capability to handle various service integrations. - Update the Makefile to reflect changes in database seeding and resource management commands. - Remove the deprecated credentials management routes and replace them with a unified model registry API. - Modify existing routes and schemas to align with the new model structure, ensuring seamless integration with the frontend. - Enhance database seeding scripts to populate new model resources and their configurations. - Update README documentation to reflect the new architecture and usage instructions for model resources and interface definitions.
This commit is contained in:
@@ -6,9 +6,11 @@
|
||||
"""
|
||||
|
||||
from collections.abc import AsyncGenerator
|
||||
import json
|
||||
|
||||
import config
|
||||
from db.models import Base
|
||||
from services.interface_catalog import INTERFACE_DEFINITIONS
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import (
|
||||
AsyncSession,
|
||||
@@ -28,22 +30,26 @@ async def get_session() -> AsyncGenerator[AsyncSession, None]:
|
||||
async def init_db() -> None:
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
# MVP 兼容迁移:create_all 不会给已存在的表补列。
|
||||
await conn.execute(
|
||||
text(
|
||||
"ALTER TABLE provider_credentials "
|
||||
"ADD COLUMN IF NOT EXISTS voice VARCHAR(128) NOT NULL DEFAULT ''"
|
||||
"ALTER TABLE interface_definitions "
|
||||
"ALTER COLUMN field_schema TYPE JSONB USING field_schema::jsonb"
|
||||
)
|
||||
)
|
||||
await conn.execute(
|
||||
text(
|
||||
"ALTER TABLE provider_credentials "
|
||||
"ADD COLUMN IF NOT EXISTS speed DOUBLE PRECISION NOT NULL DEFAULT 1.0"
|
||||
for definition in INTERFACE_DEFINITIONS:
|
||||
await conn.execute(
|
||||
text(
|
||||
"INSERT INTO interface_definitions "
|
||||
"(interface_type, name, capability, field_schema, enabled, version) "
|
||||
"VALUES (:interface_type, :name, :capability, CAST(:field_schema AS jsonb), TRUE, 1) "
|
||||
"ON CONFLICT (interface_type) DO UPDATE SET "
|
||||
"name = EXCLUDED.name, capability = EXCLUDED.capability, "
|
||||
"field_schema = EXCLUDED.field_schema, enabled = TRUE, updated_at = now()"
|
||||
),
|
||||
{
|
||||
"interface_type": definition["interface_type"],
|
||||
"name": definition["name"],
|
||||
"capability": definition["capability"],
|
||||
"field_schema": json.dumps({"fields": definition["fields"]}),
|
||||
},
|
||||
)
|
||||
)
|
||||
await conn.execute(
|
||||
text(
|
||||
"ALTER TABLE provider_credentials "
|
||||
"ADD COLUMN IF NOT EXISTS language VARCHAR(32) NOT NULL DEFAULT ''"
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user