Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: deprecate cortex configs #901

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}
9 changes: 8 additions & 1 deletion cortex-js/src/domain/abstracts/engine.abstract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ 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',
}

/**
* This class should be extended by any class that represents an engine extension.
* It provides methods for loading and unloading models, and for making inference requests.
Expand All @@ -14,7 +21,7 @@ export abstract class EngineExtension extends Extension {

transformResponse?: Function;

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

/**
* Makes an inference request to the engine.
Expand Down
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.

This file was deleted.

Loading
Loading