import { DetectFaceResult, IMachineLearningRepository, MachineLearningInput, MACHINE_LEARNING_URL } from '@app/domain'; import { Injectable } from '@nestjs/common'; import axios from 'axios'; import { createReadStream } from 'fs'; const client = axios.create({ baseURL: MACHINE_LEARNING_URL }); @Injectable() export class MachineLearningRepository implements IMachineLearningRepository { private post(input: MachineLearningInput, endpoint: string): Promise { return client.post(endpoint, createReadStream(input.imagePath)).then((res) => res.data); } classifyImage(input: MachineLearningInput): Promise { return this.post(input, '/image-classifier/tag-image'); } detectFaces(input: MachineLearningInput): Promise { return this.post(input, '/facial-recognition/detect-faces'); } encodeImage(input: MachineLearningInput): Promise { return this.post(input, '/sentence-transformer/encode-image'); } encodeText(input: string): Promise { return client.post('/sentence-transformer/encode-text', { text: input }).then((res) => res.data); } }