43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
"""
|
|
LLM 提供商模型
|
|
"""
|
|
from sqlalchemy import Column, String, Text, Boolean, Integer
|
|
|
|
from app.base_model import BaseModel
|
|
|
|
|
|
class LLMProvider(BaseModel):
|
|
"""
|
|
LLM 提供商配置
|
|
|
|
支持的提供商类型:
|
|
- openai: OpenAI (GPT-3.5, GPT-4, etc.)
|
|
- claude: Anthropic Claude
|
|
- qwen: 阿里通义千问
|
|
- ollama: 本地 Ollama
|
|
- azure_openai: Azure OpenAI
|
|
- zhipu: 智谱 AI
|
|
- moonshot: Moonshot (Kimi)
|
|
- deepseek: DeepSeek
|
|
"""
|
|
__tablename__ = "ai_llm_provider"
|
|
|
|
name = Column(String(100), nullable=False, comment="提供商名称")
|
|
provider_type = Column(String(50), nullable=False, comment="提供商类型")
|
|
api_key = Column(Text, default="", comment="API Key(加密存储)")
|
|
api_base = Column(String(500), default="", comment="API 地址(可选,用于自定义端点)")
|
|
api_version = Column(String(50), default="", comment="API 版本(Azure OpenAI 专用)")
|
|
ollama_host = Column(String(200), default="http://localhost:11434", comment="Ollama 服务地址")
|
|
is_active = Column(Boolean, default=True, comment="是否启用")
|
|
description = Column(Text, default="", comment="描述")
|
|
quota_limit = Column(Integer, default=0, comment="配额限制(0 表示无限制)")
|
|
quota_used = Column(Integer, default=0, comment="已使用配额")
|
|
|
|
def get_api_key_masked(self) -> str:
|
|
"""获取脱敏的 API Key"""
|
|
if not self.api_key:
|
|
return ''
|
|
if len(self.api_key) <= 8:
|
|
return '*' * len(self.api_key)
|
|
return self.api_key[:4] + '*' * (len(self.api_key) - 8) + self.api_key[-4:]
|