feat: add rag by codex
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
import { ChatbotService } from './providers/chatbot.service';
|
||||
import type { Response } from 'express';
|
||||
import { ChatDTO } from './dtos/chat.dto';
|
||||
import { ChatResponseDto } from './dtos/chat-response.dto';
|
||||
import { ActiveUser } from '@/common/decorators/active-user.decorator';
|
||||
import { User } from '../users/entities/user.entity';
|
||||
import { ApiAppResponse } from '@/common/decorators/api-app-response.decorator';
|
||||
@@ -33,7 +34,6 @@ export class ChatbotController {
|
||||
@ApiAppResponse([
|
||||
{
|
||||
status: HttpStatus.OK,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
variants: [{ model: GetConversationDTO, isArray: true }],
|
||||
},
|
||||
])
|
||||
@@ -45,7 +45,6 @@ export class ChatbotController {
|
||||
@ApiAppResponse([
|
||||
{
|
||||
status: HttpStatus.OK,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
variants: [{ model: GetConversationDetailsDTO }],
|
||||
},
|
||||
])
|
||||
@@ -63,7 +62,7 @@ export class ChatbotController {
|
||||
status: HttpStatus.OK,
|
||||
variants: [
|
||||
{
|
||||
model: ChatDTO,
|
||||
model: ChatResponseDto,
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -83,15 +82,18 @@ export class ChatbotController {
|
||||
@ActiveUser() user: User,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
res.setHeader('Content-Type', 'text/event-stream');
|
||||
res.setHeader('Cache-Control', 'no-cache');
|
||||
res.setHeader('Connection', 'keep-alive');
|
||||
const headers = {
|
||||
'Content-Type': 'text/event-stream',
|
||||
'Cache-Control': 'no-cache',
|
||||
Connection: 'keep-alive',
|
||||
};
|
||||
|
||||
for await (const content of this.chatbotService.streamChat(
|
||||
user,
|
||||
chatDto.message,
|
||||
chatDto.conversationId,
|
||||
)) {
|
||||
if (!res.headersSent) res.set(headers);
|
||||
res.write(
|
||||
`data: ${JSON.stringify({
|
||||
message: content,
|
||||
@@ -99,6 +101,7 @@ export class ChatbotController {
|
||||
);
|
||||
}
|
||||
|
||||
if (!res.headersSent) res.set(headers);
|
||||
res.end();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user