# Copyright 2026 zhaoxi826 # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from typing import List, Optional from sqlalchemy import String, Text, Boolean, text from sqlalchemy.dialects.postgresql import JSONB # 针对供应商模型列表优化 from sqlalchemy.orm import Mapped, mapped_column from .base import BaseDataModel class ProviderModel(BaseDataModel): """ Provider 物理模型。 作为模型/服务提供商适配器,标准化不同供应商(OpenAI, Anthropic 等)的配置。 """ __tablename__ = "provider" provider_id: Mapped[str] = mapped_column(String(64), primary_key=True) provider_title: Mapped[str] = mapped_column(String(100), index=True, nullable=False) provider_type: Mapped[str] = mapped_column(String(50), nullable=False) provider_url: Mapped[Optional[str]] = mapped_column(Text) provider_apikey: Mapped[Optional[str]] = mapped_column(Text) provider_models: Mapped[List[str]] = mapped_column( JSONB, default=list, server_default=text("'[]'::jsonb") ) provider_owner: Mapped[str] = mapped_column(String(64), index=True) is_active: Mapped[bool] = mapped_column( Boolean, default=True, server_default=text("true"), comment="该服务商节点是否在线/启用" )