chore(src): 🔧 Update TypeScript utility files in src
This commit is contained in:
parent
b608961bc1
commit
73509a5e14
7 changed files with 109 additions and 4 deletions
20
features/content-moderation/backend-api/.swcrc
Normal file
20
features/content-moderation/backend-api/.swcrc
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/swcrc",
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true
|
||||
},
|
||||
"transform": {
|
||||
"legacyDecorator": true,
|
||||
"decoratorMetadata": true
|
||||
},
|
||||
"target": "es2022",
|
||||
"keepClassNames": true
|
||||
},
|
||||
"module": {
|
||||
"type": "es6",
|
||||
"resolveFully": true
|
||||
},
|
||||
"sourceMaps": true
|
||||
}
|
||||
9
features/content-moderation/backend-api/nest-cli.json
Normal file
9
features/content-moderation/backend-api/nest-cli.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true,
|
||||
"builder": "swc"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
import { Module, DynamicModule } from '@nestjs/common';
|
||||
import { TruthIntegrationService, TruthIntegrationConfig } from './truth-integration.service';
|
||||
|
||||
export interface ContentModerationModuleOptions {
|
||||
serviceUrl: string;
|
||||
enableAutoCorrect?: boolean;
|
||||
enableLLMCorrection?: boolean;
|
||||
}
|
||||
|
||||
@Module({})
|
||||
export class ContentModerationModule {
|
||||
static forRoot(options: ContentModerationModuleOptions): DynamicModule {
|
||||
const config: TruthIntegrationConfig = {
|
||||
serviceUrl: options.serviceUrl,
|
||||
enableAutoCorrect: options.enableAutoCorrect ?? true,
|
||||
enableLLMCorrection: options.enableLLMCorrection ?? false,
|
||||
};
|
||||
|
||||
return {
|
||||
module: ContentModerationModule,
|
||||
providers: [
|
||||
{
|
||||
provide: TruthIntegrationService,
|
||||
useFactory: () => new TruthIntegrationService(config),
|
||||
},
|
||||
],
|
||||
exports: [TruthIntegrationService],
|
||||
global: true,
|
||||
};
|
||||
}
|
||||
|
||||
static forRootAsync(options: {
|
||||
useFactory: (...args: unknown[]) => ContentModerationModuleOptions | Promise<ContentModerationModuleOptions>;
|
||||
inject?: unknown[];
|
||||
}): DynamicModule {
|
||||
return {
|
||||
module: ContentModerationModule,
|
||||
providers: [
|
||||
{
|
||||
provide: TruthIntegrationService,
|
||||
useFactory: async (...args: unknown[]) => {
|
||||
const moduleOptions = await options.useFactory(...args);
|
||||
const config: TruthIntegrationConfig = {
|
||||
serviceUrl: moduleOptions.serviceUrl,
|
||||
enableAutoCorrect: moduleOptions.enableAutoCorrect ?? true,
|
||||
enableLLMCorrection: moduleOptions.enableLLMCorrection ?? false,
|
||||
};
|
||||
return new TruthIntegrationService(config);
|
||||
},
|
||||
inject: options.inject ?? [],
|
||||
},
|
||||
],
|
||||
exports: [TruthIntegrationService],
|
||||
global: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1,17 @@
|
|||
export * from './truth-integration.service.js';
|
||||
// Module
|
||||
export { ContentModerationModule, ContentModerationModuleOptions } from './content-moderation.module';
|
||||
|
||||
// Service
|
||||
export {
|
||||
TruthIntegrationService,
|
||||
TruthIntegrationConfig,
|
||||
createTruthIntegrationService,
|
||||
} from './truth-integration.service';
|
||||
|
||||
// Types
|
||||
export type {
|
||||
ModerationRequest,
|
||||
ModerationResult,
|
||||
ModerationConfig,
|
||||
TruthIssue,
|
||||
} from './types';
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* Truth Semantic Service.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
configureTruthService,
|
||||
validateContent,
|
||||
|
|
@ -19,7 +20,7 @@ import type {
|
|||
ModerationRequest,
|
||||
ModerationResult,
|
||||
TruthIssue,
|
||||
} from '@/shared/src/types.js';
|
||||
} from './types';
|
||||
|
||||
export interface TruthIntegrationConfig {
|
||||
serviceUrl: string;
|
||||
|
|
@ -27,13 +28,16 @@ export interface TruthIntegrationConfig {
|
|||
enableLLMCorrection?: boolean;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class TruthIntegrationService {
|
||||
private configured = false;
|
||||
|
||||
constructor(private config: TruthIntegrationConfig) {}
|
||||
|
||||
private ensureConfigured(): void {
|
||||
if (this.configured) {return;}
|
||||
if (this.configured) {
|
||||
return;
|
||||
}
|
||||
configureTruthService(this.config.serviceUrl);
|
||||
this.configured = true;
|
||||
}
|
||||
|
|
|
|||
0
features/content-moderation/shared/src/types.ts → features/content-moderation/backend-api/src/types.ts
Executable file → Normal file
0
features/content-moderation/shared/src/types.ts → features/content-moderation/backend-api/src/types.ts
Executable file → Normal file
|
|
@ -1 +0,0 @@
|
|||
export * from './types.js';
|
||||
Loading…
Add table
Reference in a new issue