Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 7e4e1b8

Browse files
authored
feat: support cortex configs and engines commands (#782)
1 parent aae83ae commit 7e4e1b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+875
-192
lines changed

cortex-js/src/app.module.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import { StatusController } from './infrastructure/controllers/status.controller
2626
import { ProcessController } from './infrastructure/controllers/process.controller';
2727
import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module';
2828
import { ContextModule } from './infrastructure/services/context/context.module';
29+
import { ExtensionsModule } from './extensions/extensions.module';
30+
import { ConfigsModule } from './usecases/configs/configs.module';
31+
import { EnginesModule } from './usecases/engines/engines.module';
32+
import { ConfigsController } from './infrastructure/controllers/configs.controller';
33+
import { EnginesController } from './infrastructure/controllers/engines.controller';
2934

3035
@Module({
3136
imports: [
@@ -50,6 +55,9 @@ import { ContextModule } from './infrastructure/services/context/context.module'
5055
TelemetryModule,
5156
ContextModule,
5257
DownloadManagerModule,
58+
ExtensionsModule,
59+
ConfigsModule,
60+
EnginesModule,
5361
],
5462
controllers: [
5563
AssistantsController,
@@ -60,6 +68,8 @@ import { ContextModule } from './infrastructure/services/context/context.module'
6068
StatusController,
6169
ProcessController,
6270
EventsController,
71+
ConfigsController,
72+
EnginesController,
6373
],
6474
providers: [
6575
{

cortex-js/src/app.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ export const getApp = async () => {
77
const app = await NestFactory.create(AppModule, {
88
snapshot: true,
99
cors: true,
10-
logger: console
10+
logger: console,
1111
});
1212

13+
// Set the global prefix for the API /v1/
14+
app.setGlobalPrefix('v1');
15+
1316
const fileService = app.get(FileManagerService);
1417
await fileService.getConfig();
1518

cortex-js/src/command.module.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ import { EventEmitterModule } from '@nestjs/event-emitter';
3434
import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module';
3535
import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command';
3636
import { ContextModule } from './infrastructure/services/context/context.module';
37+
import { ExtensionsModule } from './extensions/extensions.module';
38+
import { ConfigsCommand } from './infrastructure/commanders/configs.command';
39+
import { EnginesCommand } from './infrastructure/commanders/engines.command';
40+
import { ConfigsModule } from './usecases/configs/configs.module';
41+
import { EnginesModule } from './usecases/engines/engines.module';
42+
import { ConfigsGetCommand } from './infrastructure/commanders/configs/configs-get.command';
43+
import { ConfigsListCommand } from './infrastructure/commanders/configs/configs-list.command';
44+
import { ConfigsSetCommand } from './infrastructure/commanders/configs/configs-set.command';
45+
import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command';
46+
import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command';
3747

3848
@Module({
3949
imports: [
@@ -55,6 +65,9 @@ import { ContextModule } from './infrastructure/services/context/context.module'
5565
TelemetryModule,
5666
ContextModule,
5767
DownloadManagerModule,
68+
ExtensionsModule,
69+
ConfigsModule,
70+
EnginesModule,
5871
],
5972
providers: [
6073
CortexCommand,
@@ -67,6 +80,7 @@ import { ContextModule } from './infrastructure/services/context/context.module'
6780
PresetCommand,
6881
EmbeddingCommand,
6982
BenchmarkCommand,
83+
EnginesCommand,
7084

7185
// Questions
7286
InitRunModeQuestions,
@@ -88,6 +102,16 @@ import { ContextModule } from './infrastructure/services/context/context.module'
88102

89103
// Serve
90104
ServeStopCommand,
105+
106+
// Configs
107+
ConfigsCommand,
108+
ConfigsGetCommand,
109+
ConfigsListCommand,
110+
ConfigsSetCommand,
111+
112+
// Engines
113+
EnginesListCommand,
114+
EnginesGetCommand,
91115
],
92116
})
93117
export class CommandModule {}

cortex-js/src/domain/abstracts/engine.abstract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Model, ModelSettingParams } from '../../domain/models/model.interface';
44
import { Extension } from './extension.abstract';
55

66
export abstract class EngineExtension extends Extension {
7-
abstract provider: string;
7+
abstract onLoad(): void;
88

99
abstract inference(
1010
dto: any,

cortex-js/src/domain/abstracts/extension.abstract.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
export abstract class Extension {
66
/** @type {string} Name of the extension. */
7-
name?: string;
7+
name: string;
88

99
/** @type {string} Product Name of the extension. */
1010
productName?: string;

cortex-js/src/domain/abstracts/oai.abstract.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export abstract class OAIEngineExtension extends EngineExtension {
1010
super();
1111
}
1212

13+
override onLoad(): void {}
14+
1315
override async inference(
1416
createChatDto: any,
1517
headers: Record<string, string>,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Module } from '@nestjs/common';
2+
import GroqEngineExtension from './groq.engine';
3+
import MistralEngineExtension from './mistral.engine';
4+
import OpenAIEngineExtension from './openai.engine';
5+
import { HttpModule, HttpService } from '@nestjs/axios';
6+
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
7+
import { ConfigsModule } from '@/usecases/configs/configs.module';
8+
9+
const provider = {
10+
provide: 'EXTENSIONS_PROVIDER',
11+
inject: [HttpService, ConfigsUsecases],
12+
useFactory: (httpService: HttpService, configUsecases: ConfigsUsecases) => [
13+
new OpenAIEngineExtension(httpService, configUsecases),
14+
new GroqEngineExtension(httpService, configUsecases),
15+
new MistralEngineExtension(httpService, configUsecases),
16+
],
17+
};
18+
19+
@Module({
20+
imports: [HttpModule, ConfigsModule],
21+
controllers: [],
22+
providers: [provider],
23+
exports: [provider],
24+
})
25+
export class ExtensionsModule {}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { HttpService } from '@nestjs/axios';
2+
import { OAIEngineExtension } from '../domain/abstracts/oai.abstract';
3+
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase';
4+
5+
/**
6+
* A class that implements the InferenceExtension interface from the @janhq/core package.
7+
* The class provides methods for initializing and stopping a model, and for making inference requests.
8+
* It also subscribes to events emitted by the @janhq/core package and handles new message requests.
9+
*/
10+
export default class GroqEngineExtension extends OAIEngineExtension {
11+
apiUrl = 'https://api.groq.com/openai/v1/chat/completions';
12+
name = 'groq';
13+
productName = 'Groq Inference Engine';
14+
description = 'This extension enables fast Groq chat completion API calls';
15+
version = '0.0.1';
16+
17+
constructor(
18+
protected readonly httpService: HttpService,
19+
protected readonly configsUsecases: ConfigsUsecases,
20+
) {
21+
super(httpService);
22+
}
23+
24+
async onLoad() {
25+
const configs = (await this.configsUsecases.getGroupConfigs(
26+
this.name,
27+
)) as unknown as { apiKey: string };
28+
if (!configs?.apiKey)
29+
await this.configsUsecases.saveConfig('apiKey', '', this.name);
30+
}
31+
}

cortex-js/src/extensions/groq/index.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

cortex-js/src/extensions/groq/package.json

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)