From a69dd645ca6080e263a6008fa7f1595031985159 Mon Sep 17 00:00:00 2001 From: AlanPaine Date: Mon, 30 Mar 2026 08:22:09 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/api/endpoints/meetings.py | 8 +++++++- backend/app/services/async_meeting_service.py | 18 +++++++++++++++--- backend/app/services/audio_service.py | 9 ++++++--- frontend/src/pages/MeetingDetails.jsx | 2 +- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/backend/app/api/endpoints/meetings.py b/backend/app/api/endpoints/meetings.py index cf9585c..6956794 100644 --- a/backend/app/api/endpoints/meetings.py +++ b/backend/app/api/endpoints/meetings.py @@ -517,6 +517,7 @@ async def upload_audio( meeting_id: int = Form(...), auto_summarize: str = Form("true"), prompt_id: Optional[int] = Form(None), # 可选的提示词模版ID + model_code: Optional[str] = Form(None), # 可选的总结模型编码 background_tasks: BackgroundTasks = None, current_user: dict = Depends(get_current_user) ): @@ -530,6 +531,7 @@ async def upload_audio( meeting_id: 会议ID auto_summarize: 是否自动生成总结("true"/"false",默认"true") prompt_id: 提示词模版ID(可选,如果不指定则使用默认模版) + model_code: 总结模型编码(可选,如果不指定则使用默认模型) background_tasks: FastAPI后台任务 current_user: 当前登录用户 @@ -539,6 +541,8 @@ async def upload_audio( """ auto_summarize_bool = auto_summarize.lower() in ("true", "1", "yes") + model_code = model_code.strip() if model_code else None + # 0. 如果没有传入 prompt_id,尝试获取默认模版ID if prompt_id is None: with get_db_connection() as connection: @@ -599,6 +603,7 @@ async def upload_audio( auto_summarize=auto_summarize_bool, background_tasks=background_tasks, prompt_id=prompt_id, + model_code=model_code, duration=audio_duration # 传递时长参数 ) @@ -632,6 +637,7 @@ async def upload_audio( "task_id": transcription_task_id, "transcription_started": transcription_task_id is not None, "auto_summarize": auto_summarize_bool, + "model_code": model_code, "replaced_existing": result["replaced_existing"], "previous_transcription_cleared": result["replaced_existing"] and result["has_transcription"] } @@ -942,7 +948,7 @@ def list_active_llm_models(current_user: dict = Depends(get_current_user)): "SELECT model_code, model_name, provider, is_default FROM llm_model_config WHERE is_active = 1 ORDER BY is_default DESC, model_code ASC" ) models = cursor.fetchall() - return create_api_response(code="200", message="获取模型列表成功", data={"models": models}) + return create_api_response(code="200", message="获取模型列表成功", data=models) except Exception as e: return create_api_response(code="500", message=f"获取模型列表失败: {str(e)}") @router.get("/meetings/{meeting_id}/navigation") diff --git a/backend/app/services/async_meeting_service.py b/backend/app/services/async_meeting_service.py index 98d7971..a44ad3e 100644 --- a/backend/app/services/async_meeting_service.py +++ b/backend/app/services/async_meeting_service.py @@ -127,7 +127,13 @@ class AsyncMeetingService: self._update_task_in_db(task_id, 'failed', 0, error_message=error_msg) self._update_task_status_in_redis(task_id, 'failed', 0, error_message=error_msg) - def monitor_and_auto_summarize(self, meeting_id: int, transcription_task_id: str, prompt_id: Optional[int] = None): + def monitor_and_auto_summarize( + self, + meeting_id: int, + transcription_task_id: str, + prompt_id: Optional[int] = None, + model_code: Optional[str] = None + ): """ 监控转录任务,完成后自动生成总结 此方法设计为由BackgroundTasks调用,在后台运行 @@ -136,13 +142,14 @@ class AsyncMeetingService: meeting_id: 会议ID transcription_task_id: 转录任务ID prompt_id: 提示词模版ID(可选,如果不指定则使用默认模版) + model_code: 总结模型编码(可选,如果不指定则使用默认模型) 流程: 1. 循环轮询转录任务状态 2. 转录成功后自动启动总结任务 3. 转录失败或超时则停止轮询并记录日志 """ - print(f"[Monitor] Started monitoring transcription task {transcription_task_id} for meeting {meeting_id}, prompt_id: {prompt_id}") + print(f"[Monitor] Started monitoring transcription task {transcription_task_id} for meeting {meeting_id}, prompt_id: {prompt_id}, model_code: {model_code}") # 获取配置参数 poll_interval = TRANSCRIPTION_POLL_CONFIG['poll_interval'] @@ -178,7 +185,12 @@ class AsyncMeetingService: else: # 启动总结任务 try: - summary_task_id = self.start_summary_generation(meeting_id, user_prompt="", prompt_id=prompt_id) + summary_task_id = self.start_summary_generation( + meeting_id, + user_prompt="", + prompt_id=prompt_id, + model_code=model_code + ) print(f"[Monitor] Summary task {summary_task_id} started for meeting {meeting_id}") # 在后台执行总结任务 diff --git a/backend/app/services/audio_service.py b/backend/app/services/audio_service.py index 778c338..ea39ca6 100644 --- a/backend/app/services/audio_service.py +++ b/backend/app/services/audio_service.py @@ -25,6 +25,7 @@ def handle_audio_upload( auto_summarize: bool = True, background_tasks: BackgroundTasks = None, prompt_id: int = None, + model_code: str = None, duration: int = 0 ) -> dict: """ @@ -46,6 +47,7 @@ def handle_audio_upload( auto_summarize: 是否自动生成总结(默认True) background_tasks: FastAPI 后台任务对象 prompt_id: 提示词模版ID(可选,如果不指定则使用默认模版) + model_code: 总结模型编码(可选,如果不指定则使用默认模型) duration: 音频时长(秒) Returns: @@ -58,7 +60,7 @@ def handle_audio_upload( "has_transcription": bool # 原来是否有转录记录 (成功时) } """ - print(f"[Audio Service] handle_audio_upload called - Meeting ID: {meeting_id}, Auto-summarize: {auto_summarize}, Received prompt_id: {prompt_id}, Type: {type(prompt_id)}") + print(f"[Audio Service] handle_audio_upload called - Meeting ID: {meeting_id}, Auto-summarize: {auto_summarize}, Received prompt_id: {prompt_id}, model_code: {model_code}") # 1. 权限和已有文件检查 try: @@ -145,9 +147,10 @@ def handle_audio_upload( async_meeting_service.monitor_and_auto_summarize, meeting_id, transcription_task_id, - prompt_id # 传递 prompt_id 给自动总结监控任务 + prompt_id, + model_code ) - print(f"[audio_service] Auto-summarize enabled, monitor task added for meeting {meeting_id}, prompt_id: {prompt_id}") + print(f"[audio_service] Auto-summarize enabled, monitor task added for meeting {meeting_id}, prompt_id: {prompt_id}, model_code: {model_code}") except Exception as e: print(f"Failed to start transcription: {e}") diff --git a/frontend/src/pages/MeetingDetails.jsx b/frontend/src/pages/MeetingDetails.jsx index 4643d10..c22c388 100644 --- a/frontend/src/pages/MeetingDetails.jsx +++ b/frontend/src/pages/MeetingDetails.jsx @@ -179,7 +179,7 @@ const MeetingDetails = ({ user }) => { const fetchLlmModels = async () => { try { const res = await apiClient.get(buildApiUrl(API_ENDPOINTS.MEETINGS.LLM_MODELS)); - const models = res.data.models || []; + const models = Array.isArray(res.data) ? res.data : (res.data?.models || []); setLlmModels(models); const def = models.find(m => m.is_default); if (def) setSelectedModelCode(def.model_code);