diff --git a/src/modules/rag-chat/rag-chat.service.ts b/src/modules/rag-chat/rag-chat.service.ts index fcc98c0..2dd1df0 100644 --- a/src/modules/rag-chat/rag-chat.service.ts +++ b/src/modules/rag-chat/rag-chat.service.ts @@ -130,6 +130,16 @@ export class RagChatService { // Save user message await this.prisma.chatMessage.create({ data: { sessionId, role: 'user', content } }); + // Auto-title: use first user message if title is still default + if (!session.title || session.title === '新对话') { + await this.prisma.chatSession.update({ + where: { id: sessionId }, + data: { title: content.slice(0, 50) }, + }); + } + + // Also auto-title in sendMessage (this is the sync method) + // Load context const context = await this.loadContext(session.knowledgeBaseId); if (!context.text) {