Skip to content

fix(be): add history api in ai controller #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion apps/server/src/ai/ai.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import { Response } from 'express';

import { AiService } from './ai.service';
import { CreateHistoryDto } from './dto/create-history.dto';
import { ImproveQuestionDto } from './dto/improve-question.dto';
import { AiRequestValidationGuard } from './guards/restrict-request.guard';
import { CreateHistorySwagger } from './swagger/create-history.swagger';
import { ImproveQuestionSwagger } from './swagger/improve-question.swagger';
import { ImproveReplySwagger } from './swagger/improve-reply.swagger';
import { RetryQuestionSwagger } from './swagger/retry-question.swagger';
Expand All @@ -27,7 +29,6 @@
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');

let resultData = '';
let chunkData = '';
let buffer = '';

Expand Down Expand Up @@ -69,7 +70,7 @@
res.end();
});

aiStream.on('error', (err) => {

Check warning on line 73 in apps/server/src/ai/ai.controller.ts

View workflow job for this annotation

GitHub Actions / lint

'err' is defined but never used
res.status(500).json({ type: 'error', content: 'Error occurred while processing AI response' });
});
}
Expand Down Expand Up @@ -110,4 +111,11 @@
const aiStream = await this.aiService.retryImproveReply(retryImproveReplyDto);
this.handleStreamResponse(aiStream, res);
}

@Post('history')
@CreateHistorySwagger()
@ApiBody({ type: CreateHistoryDto })
public createHistory(@Body() createHistoryDto: CreateHistoryDto) {
this.aiService.createHistory(createHistoryDto);
}
}
Loading