Remove gemini and ollama
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GeminiController } from './gemini.controller';
|
||||
|
||||
describe('GeminiController', () => {
|
||||
let controller: GeminiController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [GeminiController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<GeminiController>(GeminiController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
@Module({})
|
||||
export class GeminiModule {}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GeminiService } from './gemini.service';
|
||||
|
||||
describe('GeminiService', () => {
|
||||
let service: GeminiService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [GeminiService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<GeminiService>(GeminiService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,45 +0,0 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import OpenAI from 'openai';
|
||||
|
||||
@Injectable()
|
||||
export class GeminiService {
|
||||
private readonly model = 'gemini-2.0-flash';
|
||||
private readonly systemPrompt =
|
||||
'Você é um assistente de IA que responde em portugues.';
|
||||
|
||||
private readonly gemini = new OpenAI({
|
||||
apiKey: process.env.GEMINI_API_KEY,
|
||||
baseURL: 'https://generativelanguage.googleapis.com/v1beta/openai/',
|
||||
});
|
||||
|
||||
public async generate({
|
||||
model = this.model,
|
||||
message,
|
||||
systemPrompt = this.systemPrompt,
|
||||
}: {
|
||||
model?: string;
|
||||
message: string;
|
||||
systemPrompt?: string;
|
||||
}) {
|
||||
try {
|
||||
const response = await this.gemini.chat.completions.create({
|
||||
model,
|
||||
messages: [
|
||||
{
|
||||
role: 'system',
|
||||
content: systemPrompt,
|
||||
},
|
||||
{
|
||||
role: 'user',
|
||||
content: message,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
return response;
|
||||
} catch (error) {
|
||||
throw new Error(error as string);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
|
||||
export class ChatDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
message: string;
|
||||
|
||||
@IsString()
|
||||
model: string;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { OllamaController } from './ollama.controller';
|
||||
|
||||
describe('OllamaController', () => {
|
||||
let controller: OllamaController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [OllamaController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<OllamaController>(OllamaController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { OllamaService } from './ollama.service';
|
||||
|
||||
@Module({
|
||||
providers: [OllamaService],
|
||||
})
|
||||
export class OllamaModule {}
|
||||
@@ -1,18 +0,0 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { OllamaService } from './ollama.service';
|
||||
|
||||
describe('OllamaService', () => {
|
||||
let service: OllamaService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [OllamaService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<OllamaService>(OllamaService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
@@ -1,55 +0,0 @@
|
||||
import { Ollama } from 'ollama';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import type { ListResponse, ModelResponse } from 'ollama';
|
||||
|
||||
@Injectable()
|
||||
export class OllamaService {
|
||||
private readonly ollama: Ollama;
|
||||
|
||||
constructor() {
|
||||
this.ollama = new Ollama({ host: 'http://154.12.229.181:11434' });
|
||||
}
|
||||
|
||||
public async getModels({ onlyChats }: { onlyChats: boolean }) {
|
||||
try {
|
||||
const modelsData = await this.ollama.list();
|
||||
|
||||
if (onlyChats) {
|
||||
return this.getChatModels(modelsData);
|
||||
}
|
||||
|
||||
return modelsData.models;
|
||||
} catch (error) {
|
||||
throw new Error(error as string);
|
||||
}
|
||||
}
|
||||
|
||||
public getChatModels(modelsData: ListResponse): ModelResponse[] {
|
||||
const excludeFamilies = ['nomic-bert', 'embed', 'embedding'];
|
||||
|
||||
return modelsData.models.filter((model) => {
|
||||
const families = model.details?.families || [];
|
||||
|
||||
return !families.some((f) => excludeFamilies.includes(f.toLowerCase()));
|
||||
});
|
||||
}
|
||||
|
||||
public async generateChat({
|
||||
model,
|
||||
message,
|
||||
}: {
|
||||
model: string;
|
||||
message: string;
|
||||
}) {
|
||||
try {
|
||||
const response = await this.ollama.chat({
|
||||
model,
|
||||
messages: [{ role: 'user', content: message }],
|
||||
});
|
||||
|
||||
return response.message.content;
|
||||
} catch (error) {
|
||||
throw new Error(error as string);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,11 @@ export class CreateVideoDto {
|
||||
@MaxLength(244)
|
||||
description?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsUrl()
|
||||
@MaxLength(244)
|
||||
transcriptionUrl?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber(
|
||||
{ allowNaN: false, allowInfinity: false },
|
||||
|
||||
Reference in New Issue
Block a user