test-content-gen.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. const { PrismaClient } = require('@prisma/client');
  2. const { langGraphGenerator } = require('./src/modules/book-generator');
  3. async function testContentGeneration() {
  4. const prisma = new PrismaClient();
  5. console.log('创建超迷你测试书籍(2章)测试内容生成...\n');
  6. // 1. 创建书籍
  7. const book = await prisma.book.create({
  8. data: {
  9. title: 'Git入门',
  10. description: 'Git版本控制基础教程',
  11. bookScale: '2000',
  12. targetAudience: '开发者',
  13. style: '实用教程',
  14. totalChapters: 2,
  15. }
  16. });
  17. console.log(`✅ 书籍创建成功: bookId=${book.id}\n`);
  18. // 2. 同步调用生成(不使用队列)
  19. console.log('开始生成(同步模式)...\n');
  20. try {
  21. await langGraphGenerator.generate(
  22. book.id.toString(),
  23. book.description,
  24. book.bookScale
  25. );
  26. console.log('\n🎉 生成完成!');
  27. // 3. 显示结果
  28. const finalBook = await prisma.book.findUnique({
  29. where: { id: book.id },
  30. select: {
  31. id: true,
  32. title: true,
  33. status: true,
  34. progress: true,
  35. }
  36. });
  37. console.log(`\n最终状态: ${finalBook.status}, 进度: ${finalBook.progress}%`);
  38. // 4. 显示第一个完成的内容
  39. const firstContent = await prisma.bookChapter.findFirst({
  40. where: { bookId: book.id, level: 3, contentStatus: 'completed' },
  41. select: {
  42. title: true,
  43. content: true,
  44. wordCount: true,
  45. },
  46. orderBy: { id: 'asc' }
  47. });
  48. if (firstContent) {
  49. console.log(`\n📝 第一个完成的小节:`);
  50. console.log(`标题: ${firstContent.title}`);
  51. console.log(`字数: ${firstContent.wordCount}`);
  52. console.log(`\n内容预览(前500字):`);
  53. console.log(firstContent.content.substring(0, 500));
  54. console.log('...\n');
  55. } else {
  56. console.log('\n⚠️ 没有找到已完成的内容');
  57. }
  58. } catch (error) {
  59. console.error('\n❌ 生成失败:', error.message);
  60. await prisma.book.update({
  61. where: { id: book.id },
  62. data: {
  63. status: 'failed',
  64. errorMsg: error.message,
  65. }
  66. });
  67. }
  68. await prisma.$disconnect();
  69. }
  70. testContentGeneration().catch(console.error);