feat(model-boss): ✨ Add ModelBoss class/interface exports and module configuration in model-boss.module.ts
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
307013ba07
commit
f85e4799ab
2 changed files with 0 additions and 71 deletions
|
|
@ -1 +0,0 @@
|
|||
export { ModelBossModule, GPU_BOSS, HTTP_MODEL_BOSS_CLIENT } from './model-boss.module';
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
import { HttpModelBossClient, Priority, type ServiceModelConfig } from '@lilith/model-boss';
|
||||
import { GPUBoss } from '@lilith/model-boss';
|
||||
import { Global, Inject, Injectable, Module, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
import { createLogger } from '@/common';
|
||||
|
||||
export const GPU_BOSS = Symbol('GPU_BOSS');
|
||||
export const HTTP_MODEL_BOSS_CLIENT = Symbol('HTTP_MODEL_BOSS_CLIENT');
|
||||
|
||||
@Injectable()
|
||||
class ModelBossLifecycle implements OnModuleInit, OnModuleDestroy {
|
||||
private readonly logger = createLogger(ModelBossLifecycle.name);
|
||||
|
||||
constructor(
|
||||
@Inject(GPU_BOSS) private readonly boss: GPUBoss,
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
|
||||
async onModuleInit(): Promise<void> {
|
||||
await this.boss.connect();
|
||||
const totalVramMb = parseInt(this.configService.get('GPU_TOTAL_VRAM_MB', '8000'), 10);
|
||||
await this.boss.initializeGpu(0, totalVramMb, 'GPU-0');
|
||||
this.logger.logWithData('log', 'ModelBoss connected', { totalVramMb });
|
||||
}
|
||||
|
||||
async onModuleDestroy(): Promise<void> {
|
||||
await this.boss.close();
|
||||
this.logger.logWithData('log', 'ModelBoss disconnected');
|
||||
}
|
||||
}
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
providers: [
|
||||
{
|
||||
provide: GPU_BOSS,
|
||||
inject: [ConfigService],
|
||||
useFactory: (configService: ConfigService): GPUBoss => {
|
||||
const redisUrl =
|
||||
configService.get<string>('MODEL_BOSS_REDIS_URL') ??
|
||||
configService.get<string>('DATABASE_REDIS_URL') ??
|
||||
'redis://localhost:26392';
|
||||
return new GPUBoss({ redisUrl });
|
||||
},
|
||||
},
|
||||
{
|
||||
provide: HTTP_MODEL_BOSS_CLIENT,
|
||||
inject: [GPU_BOSS, ConfigService],
|
||||
useFactory: (boss: GPUBoss, configService: ConfigService): HttpModelBossClient => {
|
||||
const registry: Record<string, ServiceModelConfig> = {
|
||||
'imajin-moderator': {
|
||||
baseUrl: configService.get('IMAJIN_MODERATOR_URL', 'http://localhost:8008'),
|
||||
vramMb: parseInt(configService.get('IMAJIN_MODERATOR_VRAM_MB', '3500'), 10),
|
||||
priority: Priority.BATCH,
|
||||
},
|
||||
'imajin-semantic': {
|
||||
baseUrl: configService.get('IMAJIN_SEMANTIC_URL', 'http://localhost:8007'),
|
||||
vramMb: parseInt(configService.get('IMAJIN_SEMANTIC_VRAM_MB', '3500'), 10),
|
||||
priority: Priority.BATCH,
|
||||
},
|
||||
};
|
||||
return new HttpModelBossClient(boss, registry);
|
||||
},
|
||||
},
|
||||
ModelBossLifecycle,
|
||||
],
|
||||
exports: [GPU_BOSS, HTTP_MODEL_BOSS_CLIENT],
|
||||
})
|
||||
export class ModelBossModule {}
|
||||
Loading…
Add table
Reference in a new issue