test-split.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const http = require('http');
  2. const testData = {
  3. title: 'Python编程入门',
  4. description: '适合初学者的Python编程教程,要有代码示例和练习题',
  5. bookScale: '小册子'
  6. };
  7. console.log('步骤1: 创建书籍...');
  8. const req = http.request({
  9. hostname: 'localhost',
  10. port: 3000,
  11. path: '/api/book-generator/langgraph/books',
  12. method: 'POST',
  13. headers: {
  14. 'Content-Type': 'application/json',
  15. }
  16. }, (res) => {
  17. let data = '';
  18. res.on('data', (chunk) => data += chunk);
  19. res.on('end', () => {
  20. const result = JSON.parse(data);
  21. console.log('创建书籍响应:', res.statusCode);
  22. console.log('书籍ID:', result.data?.id);
  23. if (result.data?.id) {
  24. const bookId = result.data.id;
  25. console.log('\n步骤2: 触发生成...');
  26. const genReq = http.request({
  27. hostname: 'localhost',
  28. port: 3000,
  29. path: `/api/book-generator/langgraph/books/${bookId}/generate`,
  30. method: 'POST',
  31. headers: {
  32. 'Content-Type': 'application/json',
  33. }
  34. }, (genRes) => {
  35. let genData = '';
  36. genRes.on('data', (chunk) => genData += chunk);
  37. genRes.on('end', () => {
  38. console.log('生成响应:', genRes.statusCode);
  39. console.log('生成数据:', genData);
  40. });
  41. });
  42. genReq.on('error', (e) => {
  43. console.error('生成请求失败:', e.message);
  44. });
  45. genReq.end();
  46. }
  47. });
  48. });
  49. req.on('error', (e) => {
  50. console.error('创建请求失败:', e.message);
  51. });
  52. req.write(JSON.stringify(testData));
  53. req.end();