145 lines
4.4 KiB
TypeScript
145 lines
4.4 KiB
TypeScript
|
|
/**
|
|||
|
|
* 诊断生成失败问题
|
|||
|
|
* 检查最近的失败任务和错误信息
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
import { PrismaClient } from '@prisma/client';
|
|||
|
|
|
|||
|
|
const prisma = new PrismaClient();
|
|||
|
|
|
|||
|
|
async function diagnose() {
|
|||
|
|
try {
|
|||
|
|
console.log('\n========== 诊断生成失败问题 ==========\n');
|
|||
|
|
|
|||
|
|
// 1. 检查最近的失败任务
|
|||
|
|
console.log('1. 最近的失败任务(最近10个):');
|
|||
|
|
const failedTasks = await prisma.aIContentTask.findMany({
|
|||
|
|
where: {
|
|||
|
|
status: 'failed',
|
|||
|
|
},
|
|||
|
|
orderBy: {
|
|||
|
|
createdAt: 'desc',
|
|||
|
|
},
|
|||
|
|
take: 10,
|
|||
|
|
select: {
|
|||
|
|
id: true,
|
|||
|
|
status: true,
|
|||
|
|
errorMessage: true,
|
|||
|
|
generationStyle: true,
|
|||
|
|
createdAt: true,
|
|||
|
|
courseId: true,
|
|||
|
|
},
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (failedTasks.length === 0) {
|
|||
|
|
console.log(' ✅ 没有失败的任务');
|
|||
|
|
} else {
|
|||
|
|
failedTasks.forEach((task, index) => {
|
|||
|
|
console.log(`\n 任务 ${index + 1}:`);
|
|||
|
|
console.log(` ID: ${task.id}`);
|
|||
|
|
console.log(` 状态: ${task.status}`);
|
|||
|
|
console.log(` 错误信息: ${task.errorMessage || '无'}`);
|
|||
|
|
console.log(` 生成风格: ${task.generationStyle || '无'}`);
|
|||
|
|
console.log(` 创建时间: ${task.createdAt}`);
|
|||
|
|
console.log(` 课程ID: ${task.courseId || '无'}`);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 2. 检查最近的课程(包括失败状态)
|
|||
|
|
console.log('\n\n2. 最近的课程(最近10个,包括生成状态):');
|
|||
|
|
const recentCourses = await prisma.course.findMany({
|
|||
|
|
orderBy: {
|
|||
|
|
createdAt: 'desc',
|
|||
|
|
},
|
|||
|
|
take: 10,
|
|||
|
|
select: {
|
|||
|
|
id: true,
|
|||
|
|
title: true,
|
|||
|
|
generationStatus: true,
|
|||
|
|
generationProgress: true,
|
|||
|
|
createdAt: true,
|
|||
|
|
aiContentTask: {
|
|||
|
|
select: {
|
|||
|
|
id: true,
|
|||
|
|
status: true,
|
|||
|
|
errorMessage: true,
|
|||
|
|
generationStyle: true,
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
recentCourses.forEach((course, index) => {
|
|||
|
|
console.log(`\n 课程 ${index + 1}:`);
|
|||
|
|
console.log(` 标题: ${course.title}`);
|
|||
|
|
console.log(` 生成状态: ${course.generationStatus || '无'}`);
|
|||
|
|
console.log(` 生成进度: ${course.generationProgress || 0}`);
|
|||
|
|
if (course.aiContentTask) {
|
|||
|
|
console.log(` 任务状态: ${course.aiContentTask.status}`);
|
|||
|
|
console.log(` 任务错误: ${course.aiContentTask.errorMessage || '无'}`);
|
|||
|
|
console.log(` 任务风格: ${course.aiContentTask.generationStyle || '无'}`);
|
|||
|
|
} else {
|
|||
|
|
console.log(` 任务: 无`);
|
|||
|
|
}
|
|||
|
|
console.log(` 创建时间: ${course.createdAt}`);
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
// 3. 检查是否有 response_format 相关的错误
|
|||
|
|
console.log('\n\n3. 检查 response_format 相关错误:');
|
|||
|
|
const responseFormatErrors = failedTasks.filter(
|
|||
|
|
task => task.errorMessage?.includes('response_format') || task.errorMessage?.includes('parameter')
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
if (responseFormatErrors.length === 0) {
|
|||
|
|
console.log(' ✅ 没有 response_format 相关错误');
|
|||
|
|
} else {
|
|||
|
|
console.log(` ⚠️ 发现 ${responseFormatErrors.length} 个 response_format 相关错误:`);
|
|||
|
|
responseFormatErrors.forEach((task, index) => {
|
|||
|
|
console.log(`\n 错误 ${index + 1}:`);
|
|||
|
|
console.log(` 任务ID: ${task.id}`);
|
|||
|
|
console.log(` 错误信息: ${task.errorMessage}`);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 4. 检查最近的 SelectStyle 调用
|
|||
|
|
console.log('\n\n4. 检查最近的模式选择记录(通过任务状态变化):');
|
|||
|
|
const tasksWithStyle = await prisma.aIContentTask.findMany({
|
|||
|
|
where: {
|
|||
|
|
generationStyle: {
|
|||
|
|
not: null,
|
|||
|
|
},
|
|||
|
|
},
|
|||
|
|
orderBy: {
|
|||
|
|
updatedAt: 'desc',
|
|||
|
|
},
|
|||
|
|
take: 5,
|
|||
|
|
select: {
|
|||
|
|
id: true,
|
|||
|
|
generationStyle: true,
|
|||
|
|
status: true,
|
|||
|
|
updatedAt: true,
|
|||
|
|
},
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (tasksWithStyle.length === 0) {
|
|||
|
|
console.log(' ⚠️ 没有找到已选择模式的任务');
|
|||
|
|
} else {
|
|||
|
|
tasksWithStyle.forEach((task, index) => {
|
|||
|
|
console.log(`\n 任务 ${index + 1}:`);
|
|||
|
|
console.log(` ID: ${task.id}`);
|
|||
|
|
console.log(` 风格: ${task.generationStyle}`);
|
|||
|
|
console.log(` 状态: ${task.status}`);
|
|||
|
|
console.log(` 更新时间: ${task.updatedAt}`);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('\n\n========== 诊断完成 ==========\n');
|
|||
|
|
} catch (error) {
|
|||
|
|
console.error('诊断失败:', error);
|
|||
|
|
} finally {
|
|||
|
|
await prisma.$disconnect();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
diagnose();
|