完善模板测试弹窗与多文件解析链路

This commit is contained in:
zwt13703
2026-07-02 16:35:50 +08:00
parent a8716aa3c6
commit 8743a02110
6 changed files with 795 additions and 112 deletions
+7 -1
View File
@@ -1,3 +1,4 @@
import asyncio
import json
import os
import uuid
@@ -17,6 +18,7 @@ from models.paragraph import Paragraph
from models.template import Template
from schemas.schemas import GenerateFullRequest, GenerateTestRequest, Response
from services.ai_service import call_ai
from services.file_summary import summarize_minio_files
from services.generation_runtime import (
build_mock_content,
generation_progress,
@@ -48,6 +50,8 @@ async def generate_test(body: GenerateTestRequest, db: AsyncSession = Depends(ge
paragraph = await db.get(Paragraph, body.paragraph_id)
if paragraph is None or paragraph.template_id != body.template_id:
raise HTTPException(status_code=404, detail="段落不存在")
if body.prompt_text:
paragraph.prompt_text = body.prompt_text
model = None
if body.model_id:
@@ -55,11 +59,12 @@ async def generate_test(body: GenerateTestRequest, db: AsyncSession = Depends(ge
elif paragraph.model_id:
model = await db.get(AiModel, paragraph.model_id)
file_summaries = await asyncio.to_thread(summarize_minio_files, body.file_paths or []) if body.file_paths else []
if model is None or model.status != "enabled":
content = build_mock_content(paragraph)
message = "当前未找到可用模型,返回本地模拟生成结果。"
else:
result = await call_ai(paragraph, model)
result = await call_ai(paragraph, model, file_summaries)
content = result.content
message = f"已通过模型 {result.used_model} 生成。"
return Response(
@@ -67,6 +72,7 @@ async def generate_test(body: GenerateTestRequest, db: AsyncSession = Depends(ge
"paragraph_id": paragraph.id,
"content": content,
"message": message,
"file_summaries": file_summaries,
}
)