ffb-production.controller.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { Controller, Get, Post, Delete, Body, Param, Query, BadRequestException } from '@nestjs/common';
  2. import { FFBProduction } from './ffb-production.schema';
  3. import { FFBProductionService } from './services/ffb-production.service';
  4. import { FFBLangChainService } from './services/ffb-langchain.service';
  5. @Controller('ffb-production')
  6. export class FFBProductionController {
  7. constructor(
  8. private readonly ffbService: FFBProductionService,
  9. private readonly ffbLangChainService: FFBLangChainService,
  10. ) { }
  11. @Post('chat')
  12. async query(@Body('message') message: string, @Body('provider') provider?: 'openai' | 'gemini') {
  13. if (!message) {
  14. throw new BadRequestException('Message is required');
  15. }
  16. const response = await this.ffbLangChainService.chatStateless(message, provider);
  17. return { response };
  18. }
  19. /** Vector search endpoint */
  20. @Get('search')
  21. async search(@Query('q') q: string, @Query('k') k?: string) {
  22. console.log(`GET /ffb-production/search?q=${q}&k=${k}`);
  23. const topK = k ? parseInt(k, 10) : 5;
  24. return this.ffbService.search(q, topK);
  25. }
  26. /** Create a new FFB production record (with embedding) */
  27. @Post()
  28. async create(@Body() body: FFBProduction) {
  29. console.log('POST /ffb-production');
  30. return this.ffbService.create(body);
  31. }
  32. /** Find all records */
  33. @Get()
  34. async findAll(@Query() query: any) {
  35. console.log('GET /ffb-production', query);
  36. // Extract pagination parameters
  37. const page = query.page ? parseInt(query.page, 10) : 1;
  38. const limit = query.limit ? parseInt(query.limit, 10) : 10;
  39. // Clean query object (remove page and limit from filters)
  40. const filter = { ...query };
  41. delete filter.page;
  42. delete filter.limit;
  43. return this.ffbService.findAll(filter, { page, limit });
  44. }
  45. /** Find a record by ID */
  46. @Get(':id')
  47. async findById(@Param('id') id: string) {
  48. console.log(`GET /ffb-production/${id}`);
  49. return this.ffbService.findById(id);
  50. }
  51. /** Delete a record by ID */
  52. @Delete(':id')
  53. async delete(@Param('id') id: string) {
  54. console.log(`DELETE /ffb-production/${id}`);
  55. return this.ffbService.delete(id);
  56. }
  57. /** Generate simple remark string (stateless) */
  58. @Post('generate-remark')
  59. async generateRemarks(@Body() body: any) {
  60. console.log(`POST /ffb-production/generate-remark`);
  61. const remark = await this.ffbService.generateRemarks(body);
  62. return { remark };
  63. }
  64. @Post('generate-issues')
  65. async generateIssues(@Body() body: any) {
  66. console.log(`POST /ffb-production/generate-issues`);
  67. const issues = await this.ffbService.generateIssues(body);
  68. return { issues };
  69. }
  70. }