You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
'use strict';
|
|
|
|
const { v4: uuidv4 } = require('uuid');
|
|
const { reportBusinessCall } = require('../../services/dashboardReporter');
|
|
const { requestFastGptTextWithApp, parseOutlineContent } = require('./ai');
|
|
|
|
module.exports.generateOutline = async (ctx, next) => {
|
|
try {
|
|
const { demand, context } = ctx.request.body || {};
|
|
const demandText = String(demand || '').trim();
|
|
if (!demandText) throw '缺少参数: demand';
|
|
const textContent = context
|
|
? `需求:${demandText}\n上下文:${JSON.stringify(context)}`
|
|
: `需求:${demandText}`;
|
|
const actionId = `report-outline:${uuidv4()}`;
|
|
const content = await requestFastGptTextWithApp(ctx, textContent, {
|
|
actionId,
|
|
variables: {
|
|
type: '目录生成',
|
|
}
|
|
});
|
|
const outline = parseOutlineContent(content);
|
|
await reportBusinessCall({
|
|
ctx,
|
|
applicationId: 'exp-report',
|
|
eventId: actionId,
|
|
traceId: actionId,
|
|
reportContext: { action: 'outline_generation' },
|
|
});
|
|
ctx.body = { outline, rawContent: content };
|
|
ctx.status = 200;
|
|
} catch (error) {
|
|
ctx.logger.log(error);
|
|
ctx.status = 400;
|
|
ctx.body = { message: typeof error === 'string' ? error : '生成目录失败' };
|
|
}
|
|
};
|
|
|