feat(admin):日志面板增加 prompt 详情 + 模型调用参数
展开日志详情后新增: - Prompt 区域:System Prompt(蓝色背景)和 User Message(灰色背景)完整显示 - 调用参数:temperature、max_tokens 等 - 耗时:独立显示 修改: - LogEntry 新增 messages? 和 params? 字段 - ai.ts 两个 handler 在日志中记录构造后的 messages 和调用参数 - 面板 toggleDetail 渲染 messages/params 区域
This commit is contained in:
+10
-6
@@ -35,12 +35,14 @@ export async function aiRoutes(app: FastifyInstance): Promise<void> {
|
||||
app.post<{ Body: AggregateReportBody }>("/ai/aggregate-report", async (request, reply) => {
|
||||
const { taskName, fragments, expectation } = request.body ?? ({} as AggregateReportBody);
|
||||
const t0 = Date.now();
|
||||
const params = { temperature: 0.3, max_tokens: 2048 };
|
||||
|
||||
if (!taskName || !Array.isArray(fragments) || fragments.length === 0) {
|
||||
logStore.add({
|
||||
timestamp: new Date().toISOString(), endpoint: "/ai/aggregate-report",
|
||||
model: config.model, durationMs: Date.now() - t0, status: 400,
|
||||
requestBody: request.body ?? {}, responseBody: { error: "taskName 与 fragments 不可为空" },
|
||||
requestBody: request.body ?? {}, params,
|
||||
responseBody: { error: "taskName 与 fragments 不可为空" },
|
||||
});
|
||||
return reply.status(400).send({ error: "taskName 与 fragments 不可为空" });
|
||||
}
|
||||
@@ -52,7 +54,7 @@ export async function aiRoutes(app: FastifyInstance): Promise<void> {
|
||||
logStore.add({
|
||||
timestamp: new Date().toISOString(), endpoint: "/ai/aggregate-report",
|
||||
model: config.model, durationMs: Date.now() - t0, status: 200,
|
||||
requestBody: request.body ?? {}, responseBody: resp,
|
||||
requestBody: request.body ?? {}, messages, params, responseBody: resp,
|
||||
});
|
||||
return resp;
|
||||
} catch (err) {
|
||||
@@ -61,7 +63,7 @@ export async function aiRoutes(app: FastifyInstance): Promise<void> {
|
||||
logStore.add({
|
||||
timestamp: new Date().toISOString(), endpoint: "/ai/aggregate-report",
|
||||
model: config.model, durationMs: Date.now() - t0, status,
|
||||
requestBody: request.body ?? {}, responseBody: {}, error: errMsg,
|
||||
requestBody: request.body ?? {}, params, responseBody: {}, error: errMsg,
|
||||
});
|
||||
if (err instanceof LlmError) {
|
||||
return reply.status(err.statusCode).send({ error: err.message });
|
||||
@@ -77,12 +79,14 @@ export async function aiRoutes(app: FastifyInstance): Promise<void> {
|
||||
const { taskName, taskDescription, reports, fragments } =
|
||||
request.body ?? ({} as GenerateMindMapBody);
|
||||
const t0 = Date.now();
|
||||
const params = { temperature: 0.3, max_tokens: 4096 };
|
||||
|
||||
if (!taskName || ((reports?.length ?? 0) === 0 && (fragments?.length ?? 0) === 0)) {
|
||||
logStore.add({
|
||||
timestamp: new Date().toISOString(), endpoint: "/ai/generate-mind-map",
|
||||
model: config.model, durationMs: Date.now() - t0, status: 400,
|
||||
requestBody: request.body ?? {}, responseBody: { error: "taskName 不可为空且 reports/fragments 至少一项非空" },
|
||||
requestBody: request.body ?? {}, params,
|
||||
responseBody: { error: "taskName 不可为空且 reports/fragments 至少一项非空" },
|
||||
});
|
||||
return reply.status(400).send({ error: "taskName 不可为空且 reports/fragments 至少一项非空" });
|
||||
}
|
||||
@@ -99,7 +103,7 @@ export async function aiRoutes(app: FastifyInstance): Promise<void> {
|
||||
logStore.add({
|
||||
timestamp: new Date().toISOString(), endpoint: "/ai/generate-mind-map",
|
||||
model: config.model, durationMs: Date.now() - t0, status: 200,
|
||||
requestBody: request.body ?? {}, responseBody: resp,
|
||||
requestBody: request.body ?? {}, messages, params, responseBody: resp,
|
||||
});
|
||||
return resp;
|
||||
} catch (err) {
|
||||
@@ -108,7 +112,7 @@ export async function aiRoutes(app: FastifyInstance): Promise<void> {
|
||||
logStore.add({
|
||||
timestamp: new Date().toISOString(), endpoint: "/ai/generate-mind-map",
|
||||
model: config.model, durationMs: Date.now() - t0, status,
|
||||
requestBody: request.body ?? {}, responseBody: {}, error: errMsg,
|
||||
requestBody: request.body ?? {}, params, responseBody: {}, error: errMsg,
|
||||
});
|
||||
if (err instanceof LlmError) {
|
||||
return reply.status(err.statusCode).send({ error: err.message });
|
||||
|
||||
Reference in New Issue
Block a user