Parcourir la source

自动分析失败为2

11wqe1 il y a 1 jour
Parent
commit
585d484222
1 fichiers modifiés avec 22 ajouts et 13 suppressions
  1. 22 13
      cocostudy.js

+ 22 - 13
cocostudy.js

@@ -361,7 +361,19 @@ const loadAgents = async () => {
   agent2a = outlineRes.data;
 };
 
-const callAgentChat = async (agent, message, userId, stepName = "Agent") => {
+const updateSpaceAnalyzeStatus = async (spaceId, isl) => {
+  try {
+    await callMysqlProc("updatespaceisanalyze", {
+      sid: spaceId,
+      isl,
+    });
+    console.log("[cocostudy] updatespaceisanalyze", { spaceId, isl });
+  } catch (err) {
+    console.error("[cocostudy] updatespaceisanalyze err", err.message || err);
+  }
+};
+
+const callAgentChat = async (agent, message, userId, stepName = "Agent", spaceId) => {
   let lastErr;
   for (let attempt = 1; attempt <= GRADE_RETRY_TIMES; attempt++) {
     try {
@@ -398,6 +410,9 @@ const callAgentChat = async (agent, message, userId, stepName = "Agent") => {
       }
     }
   }
+  if (spaceId) {
+    await updateSpaceAnalyzeStatus(spaceId, 2);
+  }
   throw lastErr;
 };
 
@@ -463,7 +478,8 @@ async function generateErrorAnalysis(quizSummary, userId, spaceId) {
     agent1a,
     `题目数据:\n${JSON.stringify(quizSummary)}`,
     userId,
-    "错因分析"
+    "错因分析",
+    spaceId
   );
   const errorAnalysis = parseAgentJsonMessage(raw);
   await generateLectureOutline(quizSummary, errorAnalysis, userId, spaceId);
@@ -474,7 +490,8 @@ async function generateLectureOutline(quizSummary, errorAnalysis, userId, spaceI
     agent2a,
     `==\n## 统计性信息如下:\n${JSON.stringify(quizSummary)}\n\n==\n\n## 错题深度分析如下:\n${JSON.stringify(errorAnalysis)}`,
     userId,
-    "讲义大纲"
+    "讲义大纲",
+    spaceId
   );
   await generatedetailedExplanation(quizSummary, errorAnalysis, lectureOutline, userId, spaceId);
 }
@@ -489,17 +506,9 @@ async function generatedetailedExplanation(quizSummary, errorAnalysis, lectureOu
     "\n生成的Agenda顺序:" +
     JSON.stringify(lectureOutline);
 
-  const answer = await callAgentChat(agent_data2, displayContent, userId, "详细讲解");
+  const answer = await callAgentChat(agent_data2, displayContent, userId, "详细讲解", spaceId);
   await insertChat(answer, spaceId, userId);
-
-  try {
-    await callMysqlProc("updatespaceisanalyze", {
-      sid: spaceId,
-      isl: 1,
-    });
-  } catch (err) {
-    console.error("[cocostudy] updatespaceisanalyze err", err.message || err);
-  }
+  await updateSpaceAnalyzeStatus(spaceId, 1);
 
   console.log("[cocostudy] 错题分析完成", { userId, spaceId });
 }