Parcourir la source

fix: AI plan generation timeout - frontend 30s->180s, backend max_tokens 4000->2000

carlin il y a 1 semaine
Parent
commit
de7761e

+ 2 - 2
web/backend/app/services/plan_generator.py

@@ -70,7 +70,7 @@ class AIPlanGenerator:
         result = self.ai_client.chat_json(
             messages=[{"role": "user", "content": user_message}],
             system_prompt=system_prompt,
-            max_tokens=4000,
+            max_tokens=2000,
         )
 
         # Parse generated plan
@@ -273,7 +273,7 @@ class AIPlanGenerator:
         result = self.ai_client.chat_json(
             messages=[{"role": "user", "content": user_message}],
             system_prompt=system_prompt,
-            max_tokens=4000,
+            max_tokens=2000,
         )
 
         refined_plan = result.get("parsed_json", {})

+ 4 - 4
web/frontend/src/api/ai.ts

@@ -3,7 +3,7 @@ import api from './index'
 // ========== AI General Services ==========
 export const aiApi = {
   chat: (data: { messages: Array<{ role: string; content: string }>; system_prompt?: string; max_tokens?: number }) =>
-    api.post('/ai/chat', data),
+    api.post('/ai/chat', data, { timeout: 180000 }),
   health: () => api.get('/ai/health'),
   logs: (params?: { limit?: number }) => api.get('/ai/logs', { params }),
   usage: () => api.get('/ai/usage'),
@@ -37,9 +37,9 @@ export const searchApi = {
 // ========== AI Plan Generation ==========
 export const planGenApi = {
   generate: (data: { requirement: string; project_context?: Record<string, any>; existing_experience?: Array<any> }) =>
-    api.post('/ai-plan/generate', data),
+    api.post('/ai-plan/generate', data, { timeout: 180000 }),
   refine: (data: { original_plan: Record<string, any>; feedback: string }) =>
-    api.post('/ai-plan/refine', data),
+    api.post('/ai-plan/refine', data, { timeout: 180000 }),
   listTemplates: () => api.get('/ai-plan/templates'),
 }
 
@@ -50,7 +50,7 @@ export const analysisApi = {
     targets?: Record<string, number>
     fidelity?: string
     scan_parameters?: string[]
-  }) => api.post('/analysis/analyze', data),
+  }) => api.post('/analysis/analyze', data, { timeout: 180000 }),
   calibrate: (data: { metric: string; value: number; fidelity: string }) =>
     api.post('/analysis/calibrate', data),
   updateCalibration: (data: {

+ 3 - 1
web/frontend/src/views/ai/PlanGenerator.vue

@@ -15,7 +15,9 @@
       />
       <div class="actions">
         <el-button type="primary" :loading="generating" @click="generatePlan">
-          <el-icon><MagicStick /></el-icon> 生成方案
+          <el-icon><MagicStick /></el-icon>
+          <span v-if="generating">AI生成中,请稍候(30-60秒)...</span>
+          <span v-else>生成方案</span>
         </el-button>
         <el-button @click="loadExample">加载示例</el-button>
       </div>