refactor: 前端架构重构 - 提取 CSS 和逻辑到独立模块
前端重构: - 删除旧的大体积 Vue 组件(HomeView, FileManage, TextSplit 等) - 删除旧的 composables(useFormatters, useModels, useProjects) - 新增 core/, page-logic/, pages/, shared/ 模块化目录结构 - 提取 CSS 到 styles/pages/ 目录 - 添加全局样式 variables.css 和 common.css 后端 API 更新: - chunks: 语义分割 API 增强 - files: 文件处理 API 更新 - models: 模型管理 API 更新 - questions: 问答管理 API 更新 - database: 数据库连接优化 - semantic_embedding: 语义嵌入服务优化 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,38 @@ from app.schemas.model import ModelCreate, ModelUpdate, ModelResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
VALID_MODEL_TYPES = {"chat", "vlm", "embedding", "rerank"}
|
||||
|
||||
|
||||
def normalize_model_type(model_type: str | None, model_name: str | None) -> str:
|
||||
"""Normalize model type, with keyword fallback for legacy records."""
|
||||
if model_type in VALID_MODEL_TYPES and model_type != "chat":
|
||||
return model_type
|
||||
|
||||
normalized_name = (model_name or "").strip().lower()
|
||||
|
||||
rerank_keywords = ("rerank", "bce-reranker", "gte-rerank")
|
||||
embedding_keywords = (
|
||||
"embedding",
|
||||
"embed",
|
||||
"text-embedding",
|
||||
"bge-",
|
||||
"bge_m3",
|
||||
"gte-",
|
||||
"m3e",
|
||||
"e5-",
|
||||
"jina-embeddings",
|
||||
)
|
||||
vlm_keywords = ("vl", "vision", "visual", "multimodal", "qwen-vl", "gpt-4o")
|
||||
|
||||
if any(keyword in normalized_name for keyword in rerank_keywords):
|
||||
return "rerank"
|
||||
if any(keyword in normalized_name for keyword in embedding_keywords):
|
||||
return "embedding"
|
||||
if any(keyword in normalized_name for keyword in vlm_keywords):
|
||||
return "vlm"
|
||||
return model_type if model_type in VALID_MODEL_TYPES else "chat"
|
||||
|
||||
|
||||
async def test_model_connection(model: ModelConfig) -> dict:
|
||||
"""Test model connection by calling the API"""
|
||||
@@ -23,6 +55,7 @@ async def test_model_connection(model: ModelConfig) -> dict:
|
||||
api_base = model.api_base or ""
|
||||
provider = model.provider
|
||||
model_name = model.model_name
|
||||
model_type = normalize_model_type(model.model_type, model_name)
|
||||
api_key = model.api_key
|
||||
|
||||
headers = {
|
||||
@@ -32,7 +65,7 @@ async def test_model_connection(model: ModelConfig) -> dict:
|
||||
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||
if provider == "openai":
|
||||
if model_type in {"chat", "vlm"} and provider in {"openai", "ali"}:
|
||||
# OpenAI compatible API test
|
||||
response = await client.post(
|
||||
f"{api_base.rstrip('/')}/chat/completions",
|
||||
@@ -43,7 +76,7 @@ async def test_model_connection(model: ModelConfig) -> dict:
|
||||
"max_tokens": 5
|
||||
}
|
||||
)
|
||||
elif provider == "minimax":
|
||||
elif model_type in {"chat", "vlm"} and provider == "minimax":
|
||||
# MiniMax API test
|
||||
response = await client.post(
|
||||
f"{api_base.rstrip('/')}/chat/completions_v2",
|
||||
@@ -56,7 +89,7 @@ async def test_model_connection(model: ModelConfig) -> dict:
|
||||
"messages": [{"role": "user", "content": "Hi"}]
|
||||
}
|
||||
)
|
||||
elif provider == "glm":
|
||||
elif model_type in {"chat", "vlm"} and provider == "glm":
|
||||
# GLM API test
|
||||
response = await client.post(
|
||||
f"{api_base.rstrip('/')}/chat/completions",
|
||||
@@ -66,8 +99,21 @@ async def test_model_connection(model: ModelConfig) -> dict:
|
||||
"messages": [{"role": "user", "content": "Hi"}]
|
||||
}
|
||||
)
|
||||
elif model_type == "embedding" and provider in {"openai", "ali", "glm"}:
|
||||
response = await client.post(
|
||||
f"{api_base.rstrip('/')}/embeddings",
|
||||
headers=headers,
|
||||
json={
|
||||
"model": model_name,
|
||||
"input": "test"
|
||||
}
|
||||
)
|
||||
elif model_type == "embedding" and provider == "minimax":
|
||||
return {"success": False, "message": "MiniMax embedding 自动测试暂未接入,请手动确认端点与模型"}
|
||||
elif model_type == "rerank":
|
||||
return {"success": False, "message": "Rerank 自动测试暂未接入,请先保存配置并在实际流程中验证"}
|
||||
else:
|
||||
return {"success": False, "message": f"Unsupported provider: {provider}"}
|
||||
return {"success": False, "message": f"Unsupported provider/type: {provider}/{model_type}"}
|
||||
|
||||
if response.status_code == 200:
|
||||
return {"success": True, "message": "Connection successful"}
|
||||
@@ -114,6 +160,7 @@ async def create_model(model: ModelCreate, db: AsyncSession = Depends(get_db)):
|
||||
|
||||
db_model = ModelConfig(
|
||||
provider=model.provider,
|
||||
model_type=model.model_type,
|
||||
model_name=model.model_name,
|
||||
api_key=model.api_key,
|
||||
api_base=model.api_base,
|
||||
@@ -248,6 +295,7 @@ async def test_model(model_id: str, db: AsyncSession = Depends(get_db)):
|
||||
test_result = await test_model_connection(model)
|
||||
|
||||
# Save connection status to database
|
||||
model.model_type = normalize_model_type(model.model_type, model.model_name)
|
||||
model.connection_status = "connected" if test_result["success"] else "disconnected"
|
||||
await db.commit()
|
||||
await db.refresh(model)
|
||||
|
||||
Reference in New Issue
Block a user