test-detect.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * 测试 autoDetectBookType 在各种描述下的实际返回
  3. */
  4. const http = require('http');
  5. function post(path, data) {
  6. return new Promise((resolve, reject) => {
  7. const body = JSON.stringify(data);
  8. const req = http.request({
  9. hostname: 'localhost',
  10. port: 3000,
  11. path,
  12. method: 'POST',
  13. headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }
  14. }, res => {
  15. let d = '';
  16. res.on('data', c => d += c);
  17. res.on('end', () => resolve(JSON.parse(d)));
  18. });
  19. req.on('error', reject);
  20. req.write(body);
  21. req.end();
  22. });
  23. }
  24. async function test() {
  25. const cases = [
  26. { title: '测试', description: '生成200字文本' },
  27. { title: '测试', description: '请写一段500字的内容' },
  28. { title: '测试', description: '写一个几千字的短文' },
  29. { title: '修仙小说', description: '写一个修仙故事' },
  30. { title: 'Python入门', description: '编程教程' },
  31. { title: '测试', description: '关于机器学习的内容' },
  32. ];
  33. for (const c of cases) {
  34. const result = await post('/api/book-generator/langgraph/books', {
  35. title: c.title,
  36. description: c.description
  37. });
  38. console.log(`描述: "${c.description}"`);
  39. console.log(` -> bookScale=${result.data.book.bookScale}, totalChapters=${result.data.book.totalChapters}, aiPreparing=${result.data.aiPreparing}`);
  40. }
  41. }
  42. test().catch(console.error);