import { Body, Controller, Get, Post, Query } from '@nestjs/common'; import { OllamaService } from './ollama.service'; import { ChatDto } from './dto/chat.dto'; @Controller('ollama') export class OllamaController { constructor(private readonly ollamaService: OllamaService) {} @Get('models') public async getModels( @Query('onlyChats') { onlyChats }: { onlyChats: boolean }, ) { return await this.ollamaService.getModels({ onlyChats }); } @Post('chat') public async chat(@Body() body: ChatDto) { const { message, model } = body; if (!message) { throw new Error('O atributo message é obrigatório'); } if (!model) { const [defaultModel] = await this.ollamaService.getModels({ onlyChats: true, }); if (!defaultModel) { throw new Error('Nenhum modelo encontrado'); } return await this.ollamaService.generateChat({ model: defaultModel.name, message, }); } return await this.ollamaService.generateChat({ model, message, }); } }