Skip to content

Commit

Permalink
refactor: deprecate cortex configs
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Jul 22, 2024
1 parent 9857448 commit 7ec99a2
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 323 deletions.
2 changes: 0 additions & 2 deletions cortex-js/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { ContextModule } from './infrastructure/services/context/context.module'
import { ExtensionsModule } from './extensions/extensions.module';
import { ConfigsModule } from './usecases/configs/configs.module';
import { EnginesModule } from './usecases/engines/engines.module';
import { ConfigsController } from './infrastructure/controllers/configs.controller';
import { EnginesController } from './infrastructure/controllers/engines.controller';
import { ResourceManagerModule } from './infrastructure/services/resources-manager/resources-manager.module';

Expand Down Expand Up @@ -70,7 +69,6 @@ import { ResourceManagerModule } from './infrastructure/services/resources-manag
StatusController,
ProcessController,
EventsController,
ConfigsController,
EnginesController,
],
providers: [
Expand Down
14 changes: 2 additions & 12 deletions cortex-js/src/command.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { AssistantsModule } from './usecases/assistants/assistants.module';
import { MessagesModule } from './usecases/messages/messages.module';
import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module';
import { PSCommand } from './infrastructure/commanders/ps.command';
import { KillCommand } from './infrastructure/commanders/kill.command';
import { PresetCommand } from './infrastructure/commanders/presets.command';
import { TelemetryModule } from './usecases/telemetry/telemetry.module';
import { TelemetryCommand } from './infrastructure/commanders/telemetry.command';
Expand All @@ -33,16 +32,13 @@ import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve
import { ContextModule } from './infrastructure/services/context/context.module';
import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module';
import { ExtensionsModule } from './extensions/extensions.module';
import { ConfigsCommand } from './infrastructure/commanders/configs.command';
import { EnginesCommand } from './infrastructure/commanders/engines.command';
import { ConfigsModule } from './usecases/configs/configs.module';
import { EnginesModule } from './usecases/engines/engines.module';
import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command';
import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command';
import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command';
import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command';
import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command';
import { EnginesInitCommand } from './infrastructure/commanders/engines/engines-init.command';
import { EnginesSetCommand } from './infrastructure/commanders/engines/engines-set.command';

@Module({
imports: [
Expand Down Expand Up @@ -73,7 +69,6 @@ import { EnginesInitCommand } from './infrastructure/commanders/engines/engines-
ModelsCommand,
ChatCommand,
PSCommand,
KillCommand,
PresetCommand,
EmbeddingCommand,
BenchmarkCommand,
Expand All @@ -100,16 +95,11 @@ import { EnginesInitCommand } from './infrastructure/commanders/engines/engines-
// Serve
ServeStopCommand,

// Configs
ConfigsCommand,
ConfigsGetCommand,
ConfigsListCommand,
ConfigsSetCommand,

// Engines
EnginesListCommand,
EnginesGetCommand,
EnginesInitCommand,
EnginesSetCommand,
],
})
export class CommandModule {}
10 changes: 8 additions & 2 deletions cortex-js/src/domain/abstracts/engine.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import stream from 'stream';
import { Model, ModelSettingParams } from '../../domain/models/model.interface';
import { Extension } from './extension.abstract';

export enum EngineStatus {
READY = 'READY',
MISSING_CONFIGURATION = 'MISSING_CONFIGURATION',
NOT_INITIALIZED = 'NOT_INITIALIZED',
ERROR = 'ERROR',
}

export abstract class EngineExtension extends Extension {
abstract onLoad(): void;

transformPayload?: Function;

transformResponse?: Function;

initalized: boolean = false;
status: EngineStatus = EngineStatus.READY;

abstract inference(
dto: any,
Expand All @@ -23,5 +30,4 @@ export abstract class EngineExtension extends Extension {
): Promise<void> {}

async unloadModel(modelId: string): Promise<void> {}

}
4 changes: 2 additions & 2 deletions cortex-js/src/domain/abstracts/extension.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export abstract class Extension {
/** @type {string} Extension's version. */
version?: string;

/** @type {boolean} Whether the extension is initialized or not. */
initalized: boolean;
/** @type {string} The status of the extension. */
status: string;

/**
* Called when the extension is loaded.
Expand Down
10 changes: 9 additions & 1 deletion cortex-js/src/extensions/anthropic.engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { OAIEngineExtension } from '../domain/abstracts/oai.abstract';
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
import { EventEmitter2 } from '@nestjs/event-emitter';
import _ from 'lodash';
import { EngineStatus } from '@/domain/abstracts/engine.abstract';

/**
* A class that implements the InferenceExtension interface from the @janhq/core package.
Expand All @@ -16,7 +17,6 @@ export default class AnthropicEngineExtension extends OAIEngineExtension {
productName = 'Anthropic Inference Engine';
description = 'This extension enables Anthropic chat completion API calls';
version = '0.0.1';
initalized = true;
apiKey?: string;

constructor(
Expand All @@ -29,6 +29,10 @@ export default class AnthropicEngineExtension extends OAIEngineExtension {
eventEmmitter.on('config.updated', async (data) => {
if (data.group === this.name) {
this.apiKey = data.value;
this.status =
(this.apiKey?.length ?? 0) > 0
? EngineStatus.READY
: EngineStatus.MISSING_CONFIGURATION;
}
});
}
Expand All @@ -38,6 +42,10 @@ export default class AnthropicEngineExtension extends OAIEngineExtension {
this.name,
)) as unknown as { apiKey: string };
this.apiKey = configs?.apiKey;
this.status =
(this.apiKey?.length ?? 0) > 0
? EngineStatus.READY
: EngineStatus.MISSING_CONFIGURATION;
}

override async inference(
Expand Down
10 changes: 9 additions & 1 deletion cortex-js/src/extensions/groq.engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpService } from '@nestjs/axios';
import { OAIEngineExtension } from '../domain/abstracts/oai.abstract';
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { EngineStatus } from '@/domain/abstracts/engine.abstract';

/**
* A class that implements the InferenceExtension interface from the @janhq/core package.
Expand All @@ -14,7 +15,6 @@ export default class GroqEngineExtension extends OAIEngineExtension {
productName = 'Groq Inference Engine';
description = 'This extension enables fast Groq chat completion API calls';
version = '0.0.1';
initalized = true;
apiKey?: string;

constructor(
Expand All @@ -27,6 +27,10 @@ export default class GroqEngineExtension extends OAIEngineExtension {
eventEmmitter.on('config.updated', async (data) => {
if (data.group === this.name) {
this.apiKey = data.value;
this.status =
(this.apiKey?.length ?? 0) > 0
? EngineStatus.READY
: EngineStatus.MISSING_CONFIGURATION;
}
});
}
Expand All @@ -37,5 +41,9 @@ export default class GroqEngineExtension extends OAIEngineExtension {
)) as unknown as { apiKey: string };

this.apiKey = configs?.apiKey;
this.status =
(this.apiKey?.length ?? 0) > 0
? EngineStatus.READY
: EngineStatus.MISSING_CONFIGURATION;
}
}
10 changes: 9 additions & 1 deletion cortex-js/src/extensions/mistral.engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpService } from '@nestjs/axios';
import { OAIEngineExtension } from '../domain/abstracts/oai.abstract';
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { EngineStatus } from '@/domain/abstracts/engine.abstract';

/**
* A class that implements the InferenceExtension interface from the @janhq/core package.
Expand All @@ -14,7 +15,6 @@ export default class MistralEngineExtension extends OAIEngineExtension {
productName = 'Mistral Inference Engine';
description = 'This extension enables Mistral chat completion API calls';
version = '0.0.1';
initalized = true;
apiKey?: string;

constructor(
Expand All @@ -27,6 +27,10 @@ export default class MistralEngineExtension extends OAIEngineExtension {
eventEmmitter.on('config.updated', async (data) => {
if (data.group === this.name) {
this.apiKey = data.value;
this.status =
(this.apiKey?.length ?? 0) > 0
? EngineStatus.READY
: EngineStatus.MISSING_CONFIGURATION;
}
});
}
Expand All @@ -36,5 +40,9 @@ export default class MistralEngineExtension extends OAIEngineExtension {
this.name,
)) as unknown as { apiKey: string };
this.apiKey = configs?.apiKey;
this.status =
(this.apiKey?.length ?? 0) > 0
? EngineStatus.READY
: EngineStatus.MISSING_CONFIGURATION;
}
}
10 changes: 9 additions & 1 deletion cortex-js/src/extensions/openai.engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpService } from '@nestjs/axios';
import { OAIEngineExtension } from '../domain/abstracts/oai.abstract';
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { EngineStatus } from '@/domain/abstracts/engine.abstract';

/**
* A class that implements the InferenceExtension interface from the @janhq/core package.
Expand All @@ -14,7 +15,6 @@ export default class OpenAIEngineExtension extends OAIEngineExtension {
productName = 'OpenAI Inference Engine';
description = 'This extension enables OpenAI chat completion API calls';
version = '0.0.1';
initalized = true;
apiKey?: string;

constructor(
Expand All @@ -27,6 +27,10 @@ export default class OpenAIEngineExtension extends OAIEngineExtension {
eventEmmitter.on('config.updated', async (data) => {
if (data.group === this.name) {
this.apiKey = data.value;
this.status =
(this.apiKey?.length ?? 0) > 0
? EngineStatus.READY
: EngineStatus.MISSING_CONFIGURATION;
}
});
}
Expand All @@ -36,5 +40,9 @@ export default class OpenAIEngineExtension extends OAIEngineExtension {
this.name,
)) as unknown as { apiKey: string };
this.apiKey = configs?.apiKey;
this.status =
(this.apiKey?.length ?? 0) > 0
? EngineStatus.READY
: EngineStatus.MISSING_CONFIGURATION;
}
}
27 changes: 0 additions & 27 deletions cortex-js/src/infrastructure/commanders/configs.command.ts

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7ec99a2

Please sign in to comment.