Adiciona controller do Ollama e reestrutura arquitetura
This commit is contained in:
44
src/modules/ollama/ollama.controller.ts
Normal file
44
src/modules/ollama/ollama.controller.ts
Normal 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user