Adiciona controller do Ollama e reestrutura arquitetura

This commit is contained in:
LeoMortari
2025-09-30 20:30:22 -03:00
parent 76b7670fba
commit f7857fdcbc
31 changed files with 267 additions and 105 deletions

View File

@@ -0,0 +1,44 @@
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,
});
}
}