Skip to content

Commit

Permalink
fix(backend): generate topic when finish completion
Browse files Browse the repository at this point in the history
  • Loading branch information
AprilNEA committed Dec 11, 2023
1 parent c30081d commit 67376fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/backend/src/modules/chat/chat.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class ChatController {
modelId: data.modelId,
input: data.content,
messages: chatSession.messages,
// key,
topic: chatSession.topic,
});
}
}
20 changes: 20 additions & 0 deletions packages/backend/src/modules/chat/chat.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ ${message}
input,
modelId,
messages, // key,
topic,
}: {
userId: number;
sessionId: string;
Expand All @@ -273,6 +274,7 @@ ${message}
messages: ChatMessage[];
/* Request API Key */
// key: string;
topic?: string;
}) {
const { name: model } = await this.prisma.client.model.findUniqueOrThrow({
where: { id: modelId },
Expand Down Expand Up @@ -338,6 +340,24 @@ ${message}
}),
]);
subscriber.complete();
/* 首次对话自动总结对话,
* First conversation automatically summarizes the conversation
*/
if (!topic) {
await this.summarizeTopic(
[
...histories,
{ role: 'user', content: input },
{
role: 'assistant',
content: generated,
},
]
.map((m) => `${m.role}: ${m.content}`)
.join('\n'),
sessionId,
);
}
}
})();
});
Expand Down

0 comments on commit 67376fb

Please sign in to comment.