| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- const http = require('http');
- const testData = {
- title: 'Python编程入门',
- description: '适合初学者的Python编程教程,要有代码示例和练习题',
- bookScale: '小册子'
- };
- console.log('步骤1: 创建书籍...');
- const req = http.request({
- hostname: 'localhost',
- port: 3000,
- path: '/api/book-generator/langgraph/books',
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- }
- }, (res) => {
- let data = '';
- res.on('data', (chunk) => data += chunk);
- res.on('end', () => {
- const result = JSON.parse(data);
- console.log('创建书籍响应:', res.statusCode);
- console.log('书籍ID:', result.data?.id);
-
- if (result.data?.id) {
- const bookId = result.data.id;
- console.log('\n步骤2: 触发生成...');
-
- const genReq = http.request({
- hostname: 'localhost',
- port: 3000,
- path: `/api/book-generator/langgraph/books/${bookId}/generate`,
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- }
- }, (genRes) => {
- let genData = '';
- genRes.on('data', (chunk) => genData += chunk);
- genRes.on('end', () => {
- console.log('生成响应:', genRes.statusCode);
- console.log('生成数据:', genData);
- });
- });
-
- genReq.on('error', (e) => {
- console.error('生成请求失败:', e.message);
- });
-
- genReq.end();
- }
- });
- });
- req.on('error', (e) => {
- console.error('创建请求失败:', e.message);
- });
- req.write(JSON.stringify(testData));
- req.end();
|