mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
feat: add services and refactor repositories
This commit is contained in:
parent
d4fd1c08f5
commit
c177c6c121
@ -25,8 +25,8 @@ import { NlpModelService } from '../services/nlp-model.service';
|
|||||||
import { NlpDatasetRepository } from './nlp-dataset.repository';
|
import { NlpDatasetRepository } from './nlp-dataset.repository';
|
||||||
import { NlpMetricValueRepository } from './nlp-metric-value.repository';
|
import { NlpMetricValueRepository } from './nlp-metric-value.repository';
|
||||||
import { NlpMetricRepository } from './nlp-metric.repository';
|
import { NlpMetricRepository } from './nlp-metric.repository';
|
||||||
|
import { NlpParameterValueRepository } from './nlp-parameter-value.repository';
|
||||||
import { NlpParameterRepository } from './nlp-parameter.repository';
|
import { NlpParameterRepository } from './nlp-parameter.repository';
|
||||||
import { NlpParameterValueRepository } from './nlp-parameter.value.repository';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NlpExperimentRepository extends BaseRepository<
|
export class NlpExperimentRepository extends BaseRepository<
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
|
|
||||||
import { NlpDatasetRepository } from './nlp-dataset.repository';
|
import { NlpDatasetRepository } from './nlp-dataset.repository';
|
||||||
import { NlpExperimentRepository } from './nlp-experiment.repository';
|
import { NlpExperimentRepository } from './nlp-experiment.repository';
|
||||||
import { NlpParameterValueRepository } from './nlp-parameter.value.repository';
|
import { NlpParameterValueRepository } from './nlp-parameter-value.repository';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NlpParameterRepository extends BaseRepository<
|
export class NlpParameterRepository extends BaseRepository<
|
||||||
|
@ -27,7 +27,7 @@ export class NlpMetricStub extends BaseSchema {
|
|||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The associated Experiment
|
* The associated Experiments
|
||||||
*/
|
*/
|
||||||
@Prop([
|
@Prop([
|
||||||
{
|
{
|
||||||
|
@ -9,48 +9,57 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
|
|
||||||
|
import { BaseService } from '@/utils/generics/base-service';
|
||||||
|
|
||||||
import { NlpExperimentDto } from '../dto/nlp-experiment.dto';
|
import { NlpExperimentDto } from '../dto/nlp-experiment.dto';
|
||||||
import { NlpExperimentRepository } from '../repositories/nlp-experiment.repository';
|
import { NlpExperimentRepository } from '../repositories/nlp-experiment.repository';
|
||||||
import {
|
import {
|
||||||
NlpExperiment,
|
NlpExperiment,
|
||||||
NlpExperimentFull,
|
NlpExperimentFull,
|
||||||
|
NlpExperimentPopulate,
|
||||||
} from '../schemas/nlp-experiment.schema';
|
} from '../schemas/nlp-experiment.schema';
|
||||||
|
|
||||||
import { NlpModelService } from './nlp-model.service';
|
import { NlpModelService } from './nlp-model.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class NlpExperimentService {
|
export class NlpExperimentService extends BaseService<
|
||||||
|
NlpExperiment,
|
||||||
|
NlpExperimentPopulate,
|
||||||
|
NlpExperimentFull
|
||||||
|
> {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly nlpExperimentRepository: NlpExperimentRepository,
|
readonly repository: NlpExperimentRepository,
|
||||||
private readonly eventEmitter: EventEmitter2,
|
private readonly eventEmitter: EventEmitter2,
|
||||||
private readonly nlpModelService: NlpModelService,
|
private readonly nlpModelService: NlpModelService,
|
||||||
) {}
|
) {
|
||||||
|
super(repository);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new NLP experiment.
|
* Create a new NLP experiment.
|
||||||
* @param nlpExperimentDto - Data transfer object for creating an experiment
|
* @param nlpExperimentDto - Data transfer object for creating an experiment
|
||||||
* @returns {Promise<NlpExperimentFull>} - Created experiment details
|
* @returns {Promise<void>} - Created experiment details
|
||||||
*/
|
*/
|
||||||
async createExperiment(nlpExperimentDto: NlpExperimentDto): Promise<void> {
|
async createExperiment(nlpExperimentDto: NlpExperimentDto): Promise<void> {
|
||||||
const experiment = new NlpExperiment();
|
const experiment = new NlpExperiment();
|
||||||
Object.assign(experiment, nlpExperimentDto);
|
Object.assign(experiment, nlpExperimentDto);
|
||||||
|
|
||||||
// Create the experiment in the repository
|
// Create the experiment in the repository
|
||||||
await this.nlpExperimentRepository.create(experiment);
|
await this.repository.create(experiment);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an existing NLP experiment.
|
* Update an existing NLP experiment.
|
||||||
* @param id - The ID of the experiment to update
|
* @param id - The ID of the experiment to update
|
||||||
* @param nlpExperimentDto - The data to update the experiment with
|
* @param nlpExperimentDto - The data to update the experiment with
|
||||||
* @returns {Promise<NlpExperimentFull>} - Updated experiment details
|
* @returns {Promise<void>} - Updated experiment details
|
||||||
*/
|
*/
|
||||||
async updateExperiment(
|
async updateExperiment(
|
||||||
id: string,
|
id: string,
|
||||||
nlpExperimentDto: NlpExperimentDto,
|
nlpExperimentDto: NlpExperimentDto,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Perform the update in the repository
|
// Perform the update in the repository
|
||||||
await this.nlpExperimentRepository.updateOne(id, nlpExperimentDto);
|
await this.repository.updateOne(id, nlpExperimentDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,15 +69,15 @@ export class NlpExperimentService {
|
|||||||
*/
|
*/
|
||||||
async deleteCascadeExperiment(id: string): Promise<void> {
|
async deleteCascadeExperiment(id: string): Promise<void> {
|
||||||
// Perform the delete operation in the repository
|
// Perform the delete operation in the repository
|
||||||
await this.nlpExperimentRepository.deleteOne(id);
|
await this.repository.deleteOne(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all completed NLP experiments.
|
* Get all completed NLP experiments.
|
||||||
* @returns {Promise<NlpExperimentFull[]>} - List of completed experiments
|
* @returns {Promise<NlpExperiment[]>} - List of completed experiments
|
||||||
*/
|
*/
|
||||||
async getCompletedExperiments(): Promise<NlpExperiment[]> {
|
async getCompletedExperiments(): Promise<NlpExperiment[]> {
|
||||||
const experiments = await this.nlpExperimentRepository.find({
|
const experiments = await this.repository.find({
|
||||||
isCompleted: true,
|
isCompleted: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -81,7 +90,7 @@ export class NlpExperimentService {
|
|||||||
* @returns {Promise<NlpExperimentFull | null>} - The experiment, or null if not found
|
* @returns {Promise<NlpExperimentFull | null>} - The experiment, or null if not found
|
||||||
*/
|
*/
|
||||||
async getExperimentById(id: string): Promise<NlpExperimentFull | null> {
|
async getExperimentById(id: string): Promise<NlpExperimentFull | null> {
|
||||||
const experiment = await this.nlpExperimentRepository.findOne(id);
|
const experiment = await this.repository.findOne(id);
|
||||||
return experiment;
|
return experiment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
api/src/nlp/services/nlp-metric-service.ts
Normal file
29
api/src/nlp/services/nlp-metric-service.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { BaseService } from '@/utils/generics/base-service';
|
||||||
|
|
||||||
|
import { NlpMetricRepository } from '../repositories/nlp-metric.repository';
|
||||||
|
import {
|
||||||
|
NlpMetric,
|
||||||
|
NlpMetricFull,
|
||||||
|
NlpMetricPopulate,
|
||||||
|
} from '../schemas/nlp-metric.schema';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class NlpMetricService extends BaseService<
|
||||||
|
NlpMetric,
|
||||||
|
NlpMetricPopulate,
|
||||||
|
NlpMetricFull
|
||||||
|
> {
|
||||||
|
constructor(readonly repository: NlpMetricRepository) {
|
||||||
|
super(repository);
|
||||||
|
}
|
||||||
|
}
|
74
api/src/nlp/services/nlp-metric-value.service.ts
Normal file
74
api/src/nlp/services/nlp-metric-value.service.ts
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
|
|
||||||
|
import { BaseService } from '@/utils/generics/base-service';
|
||||||
|
|
||||||
|
import { NlpMetricValueDto } from '../dto/nlp-metric-value.dto';
|
||||||
|
import { NlpMetricValueRepository } from '../repositories/nlp-metric-value.repository';
|
||||||
|
import {
|
||||||
|
NlpMetricValue,
|
||||||
|
NlpMetricValueFull,
|
||||||
|
NlpMetricValuePopulate,
|
||||||
|
} from '../schemas/nlp-metric-value.schema';
|
||||||
|
|
||||||
|
import { NlpModelService } from './nlp-model.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class NlpMetricValueService extends BaseService<
|
||||||
|
NlpMetricValue,
|
||||||
|
NlpMetricValuePopulate,
|
||||||
|
NlpMetricValueFull
|
||||||
|
> {
|
||||||
|
constructor(
|
||||||
|
readonly repository: NlpMetricValueRepository,
|
||||||
|
private readonly eventEmitter: EventEmitter2,
|
||||||
|
private readonly nlpModelService: NlpModelService,
|
||||||
|
) {
|
||||||
|
super(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new NLP MetricValue.
|
||||||
|
* @param nlpMetricValueDto - Data transfer object for creating an MetricValue
|
||||||
|
* @returns {Promise<void>} - Created MetricValue details
|
||||||
|
*/
|
||||||
|
async createMetricValue(nlpMetricValueDto: NlpMetricValueDto): Promise<void> {
|
||||||
|
const MetricValue = new NlpMetricValue();
|
||||||
|
Object.assign(MetricValue, nlpMetricValueDto);
|
||||||
|
|
||||||
|
// Create the MetricValue in the repository
|
||||||
|
await this.repository.create(MetricValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing NLP MetricValue.
|
||||||
|
* @param id - The ID of the MetricValue to update
|
||||||
|
* @param nlpMetricValueDto - The data to update the MetricValue with
|
||||||
|
* @returns {Promise<void>} - Updated MetricValue details
|
||||||
|
*/
|
||||||
|
async updateMetricValue(
|
||||||
|
id: string,
|
||||||
|
nlpMetricValueDto: NlpMetricValueDto,
|
||||||
|
): Promise<void> {
|
||||||
|
// Perform the update in the repository
|
||||||
|
await this.repository.updateOne(id, nlpMetricValueDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete an NLP MetricValue and its related data.
|
||||||
|
* @param id - The ID of the MetricValue to delete
|
||||||
|
* @returns {Promise<void>} - A promise indicating completion
|
||||||
|
*/
|
||||||
|
async deleteCascadeMetricValue(id: string): Promise<void> {
|
||||||
|
// Perform the delete operation in the repository
|
||||||
|
await this.repository.deleteOne(id);
|
||||||
|
}
|
||||||
|
}
|
76
api/src/nlp/services/nlp-parameter-value.service.ts
Normal file
76
api/src/nlp/services/nlp-parameter-value.service.ts
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
|
|
||||||
|
import { BaseService } from '@/utils/generics/base-service';
|
||||||
|
|
||||||
|
import { NlpParameterValueDto } from '../dto/nlp-parameter-value.dto';
|
||||||
|
import { NlpParameterValueRepository } from '../repositories/nlp-parameter-value.repository';
|
||||||
|
import {
|
||||||
|
NlpParameterValue,
|
||||||
|
NlpParameterValueFull,
|
||||||
|
NlpParameterValuePopulate,
|
||||||
|
} from '../schemas/nlp-parameter-value.schema';
|
||||||
|
|
||||||
|
import { NlpModelService } from './nlp-model.service';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class NlpParameterValueService extends BaseService<
|
||||||
|
NlpParameterValue,
|
||||||
|
NlpParameterValuePopulate,
|
||||||
|
NlpParameterValueFull
|
||||||
|
> {
|
||||||
|
constructor(
|
||||||
|
readonly repository: NlpParameterValueRepository,
|
||||||
|
private readonly eventEmitter: EventEmitter2,
|
||||||
|
private readonly nlpModelService: NlpModelService,
|
||||||
|
) {
|
||||||
|
super(repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new NLP MetricValue.
|
||||||
|
* @param NlpParameterValueDto - Data transfer object for creating an MetricValue
|
||||||
|
* @returns {Promise<void>} - Created MetricValue details
|
||||||
|
*/
|
||||||
|
async createMetricValue(
|
||||||
|
NlpParameterValueDto: NlpParameterValueDto,
|
||||||
|
): Promise<void> {
|
||||||
|
const MetricValue = new NlpParameterValue();
|
||||||
|
Object.assign(MetricValue, NlpParameterValueDto);
|
||||||
|
|
||||||
|
// Create the MetricValue in the repository
|
||||||
|
await this.repository.create(MetricValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing NLP MetricValue.
|
||||||
|
* @param id - The ID of the MetricValue to update
|
||||||
|
* @param NlpParameterValueDto - The data to update the MetricValue with
|
||||||
|
* @returns {Promise<void>} - Updated MetricValue details
|
||||||
|
*/
|
||||||
|
async updateMetricValue(
|
||||||
|
id: string,
|
||||||
|
NlpParameterValueDto: NlpParameterValueDto,
|
||||||
|
): Promise<void> {
|
||||||
|
// Perform the update in the repository
|
||||||
|
await this.repository.updateOne(id, NlpParameterValueDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete an NLP MetricValue and its related data.
|
||||||
|
* @param id - The ID of the MetricValue to delete
|
||||||
|
* @returns {Promise<void>} - A promise indicating completion
|
||||||
|
*/
|
||||||
|
async deleteCascadeMetricValue(id: string): Promise<void> {
|
||||||
|
// Perform the delete operation in the repository
|
||||||
|
await this.repository.deleteOne(id);
|
||||||
|
}
|
||||||
|
}
|
29
api/src/nlp/services/nlp-parameter.service.ts
Normal file
29
api/src/nlp/services/nlp-parameter.service.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 Hexastack. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||||
|
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||||
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { BaseService } from '@/utils/generics/base-service';
|
||||||
|
|
||||||
|
import { NlpParameterRepository } from '../repositories/nlp-parameter.repository';
|
||||||
|
import {
|
||||||
|
NlpParameter,
|
||||||
|
NlpParameterFull,
|
||||||
|
NlpParameterPopulate,
|
||||||
|
} from '../schemas/nlp-parameter.schema';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class NlpParameterService extends BaseService<
|
||||||
|
NlpParameter,
|
||||||
|
NlpParameterPopulate,
|
||||||
|
NlpParameterFull
|
||||||
|
> {
|
||||||
|
constructor(readonly repository: NlpParameterRepository) {
|
||||||
|
super(repository);
|
||||||
|
}
|
||||||
|
}
|
@ -437,4 +437,8 @@ export abstract class BaseRepository<
|
|||||||
) {
|
) {
|
||||||
// Nothing ...
|
// Nothing ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async aggregate<T = any>(pipeline: any[]): Promise<T[]> {
|
||||||
|
return this.model.aggregate<T>(pipeline).exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user