| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- /**
- * 测试 autoDetectBookType 在各种描述下的实际返回
- */
- const http = require('http');
- function post(path, data) {
- return new Promise((resolve, reject) => {
- const body = JSON.stringify(data);
- const req = http.request({
- hostname: 'localhost',
- port: 3000,
- path,
- method: 'POST',
- headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) }
- }, res => {
- let d = '';
- res.on('data', c => d += c);
- res.on('end', () => resolve(JSON.parse(d)));
- });
- req.on('error', reject);
- req.write(body);
- req.end();
- });
- }
- async function test() {
- const cases = [
- { title: '测试', description: '生成200字文本' },
- { title: '测试', description: '请写一段500字的内容' },
- { title: '测试', description: '写一个几千字的短文' },
- { title: '修仙小说', description: '写一个修仙故事' },
- { title: 'Python入门', description: '编程教程' },
- { title: '测试', description: '关于机器学习的内容' },
- ];
- for (const c of cases) {
- const result = await post('/api/book-generator/langgraph/books', {
- title: c.title,
- description: c.description
- });
- console.log(`描述: "${c.description}"`);
- console.log(` -> bookScale=${result.data.book.bookScale}, totalChapters=${result.data.book.totalChapters}, aiPreparing=${result.data.aiPreparing}`);
- }
- }
- test().catch(console.error);
|