feat: add conversation module

This commit is contained in:
2026-09-30 17:55:21 +03:30
parent 13ba11f951
commit 9842f4db31
14 changed files with 270 additions and 18 deletions
+50 -1
View File
@@ -1,6 +1,7 @@
import { Body, Controller, Post } from '@nestjs/common';
import { Body, Controller, Post, Res } from '@nestjs/common';
import { ChatbotService } from './providers/chatbot.service';
import { Public } from '../auth/decorators/public.decorator';
import type { Response } from 'express';
@Controller('chatbot')
export class ChatbotController {
@@ -17,4 +18,52 @@ export class ChatbotController {
public async chat(@Body('message') message: string) {
return this.chatbotService.chat(message);
}
@Post('stream')
// TEMP:
@Public()
public async streamChat(
@Body('message') message: string,
@Res() res: Response,
) {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
for await (const content of this.chatbotService.streamChat(message)) {
res.write(
`data: ${JSON.stringify({
message: content,
})}\n\n`,
);
}
res.end();
}
// @Sse('stream')
// @Public()
// public streamChat(
// @Body('message') message: string,
// ): Observable<MessageEvent> {
// return new Observable((subscriber) => {
// const run = async () => {
// try {
// for await (const content of this.chatbotService.streamChat(message)) {
// subscriber.next({
// data: {
// message: content,
// },
// });
// }
// subscriber.complete();
// } catch (err) {
// subscriber.error(err);
// }
// };
// void run();
// });
// }
}