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

Commit 2702751

Browse files
louis-janVan-QA
andauthored
fix: failed tests (#702)
Co-authored-by: Van-QA <van@jan.ai>
1 parent 40ada07 commit 2702751

30 files changed

+238
-154
lines changed

cortex-js/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"name": "@janhq/cortex",
33
"version": "0.0.1",
4-
"description": "",
5-
"author": "",
4+
"description": "Cortex is an openAI-compatible local AI server that developers can use to build LLM apps. It is packaged with a Docker-inspired command-line interface and a Typescript client library. It can be used as a standalone server, or imported as a library.",
5+
"author": "Jan <service@jan.ai>",
66
"license": "AGPL-3.0",
7+
"homepage": "https://github.com/janhq/cortex",
78
"bin": {
89
"cortex": "./dist/src/command.js"
910
},
@@ -114,7 +115,8 @@
114115
"coverageDirectory": "../coverage",
115116
"testEnvironment": "node",
116117
"moduleNameMapper": {
117-
"@/(.*)$": "<rootDir>/$1"
118+
"@/(.*)$": "<rootDir>/$1",
119+
"@commanders/(.*)$": "<rootDir>/../src/infrastructure/commanders/$1"
118120
}
119121
}
120122
}

cortex-js/src/app.module.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { AppLoggerMiddleware } from './infrastructure/middlewares/app.logger.mid
1717
import { EventEmitterModule } from '@nestjs/event-emitter';
1818
import { DownloadManagerModule } from './download-manager/download-manager.module';
1919
import { EventsController } from './infrastructure/controllers/events.controller';
20-
import { AppController } from './infrastructure/controllers/app.controller';
2120
import { AssistantsController } from './infrastructure/controllers/assistants.controller';
2221
import { ChatController } from './infrastructure/controllers/chat.controller';
2322
import { EmbeddingsController } from './infrastructure/controllers/embeddings.controller';
@@ -49,7 +48,6 @@ import { ProcessController } from './infrastructure/controllers/process.controll
4948
DownloadManagerModule,
5049
],
5150
controllers: [
52-
AppController,
5351
AssistantsController,
5452
ChatController,
5553
EmbeddingsController,

cortex-js/src/command.module.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command
3131
import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command';
3232
import { EventEmitterModule } from '@nestjs/event-emitter';
3333
import { DownloadManagerModule } from './download-manager/download-manager.module';
34+
import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command';
3435

3536
@Module({
3637
imports: [
@@ -78,6 +79,9 @@ import { DownloadManagerModule } from './download-manager/download-manager.modul
7879

7980
// Shortcuts
8081
RunCommand,
82+
83+
// Serve
84+
ServeStopCommand,
8185
],
8286
})
8387
export class CommandModule {}

cortex-js/src/download-manager/download-manager.service.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { Test, TestingModule } from '@nestjs/testing';
22
import { DownloadManagerService } from './download-manager.service';
3+
import { HttpModule } from '@nestjs/axios';
4+
import { EventEmitterModule } from '@nestjs/event-emitter';
35

46
describe('DownloadManagerService', () => {
57
let service: DownloadManagerService;
68

79
beforeEach(async () => {
810
const module: TestingModule = await Test.createTestingModule({
11+
imports: [HttpModule, EventEmitterModule.forRoot()],
912
providers: [DownloadManagerService],
1013
}).compile();
1114

cortex-js/src/infrastructure/commanders/benchmark.command.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { BenchmarkConfig } from './types/benchmark-config.interface';
44

55
@SubCommand({
66
name: 'benchmark',
7-
subCommands: [],
7+
arguments: '[model_id]',
8+
argsDescription: {
9+
model_id: 'Model to benchmark with',
10+
},
811
description:
912
'Benchmark and analyze the performance of a specific AI model using a variety of system resources',
1013
})
@@ -14,10 +17,13 @@ export class BenchmarkCommand extends CommandRunner {
1417
}
1518

1619
async run(
17-
_input: string[],
20+
passedParams: string[],
1821
options?: Partial<BenchmarkConfig>,
1922
): Promise<void> {
20-
return this.benchmarkUsecases.benchmark(options ?? {});
23+
return this.benchmarkUsecases.benchmark({
24+
...options,
25+
...(passedParams[0] ? { modelId: passedParams[0] } : {}),
26+
});
2127
}
2228

2329
@Option({

cortex-js/src/infrastructure/commanders/chat.command.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@ type ChatOptions = {
1616
attach: boolean;
1717
};
1818

19-
@SubCommand({ name: 'chat', description: 'Send a chat request to a model' })
19+
@SubCommand({
20+
name: 'chat',
21+
description: 'Send a chat request to a model',
22+
arguments: '[model_id] [message]',
23+
argsDescription: {
24+
model_id:
25+
'Model ID to chat with. If there is no model_id provided, it will prompt to select from running models.',
26+
message: 'Message to send to the model',
27+
},
28+
})
2029
export class ChatCommand extends CommandRunner {
2130
constructor(
2231
private readonly inquirerService: InquirerService,
@@ -27,17 +36,19 @@ export class ChatCommand extends CommandRunner {
2736
super();
2837
}
2938

30-
async run(_input: string[], options: ChatOptions): Promise<void> {
31-
let modelId = _input[0];
39+
async run(passedParams: string[], options: ChatOptions): Promise<void> {
40+
let modelId = passedParams[0];
3241
// First attempt to get message from input or options
3342
// Extract input from 1 to end of array
34-
let message = options.message ?? _input.slice(1).join(' ');
43+
let message = options.message ?? passedParams.slice(1).join(' ');
3544

3645
// Check for model existing
3746
if (!modelId || !(await this.modelsUsecases.findOne(modelId))) {
3847
// Model ID is not provided
3948
// first input might be message input
40-
message = _input.length ? _input.join(' ') : options.message ?? '';
49+
message = passedParams.length
50+
? passedParams.join(' ')
51+
: options.message ?? '';
4152
// If model ID is not provided, prompt user to select from running models
4253
const models = await this.psCliUsecases.getModels();
4354
if (models.length === 1) {
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RootCommand, CommandRunner, Option } from 'nest-commander';
1+
import { RootCommand, CommandRunner } from 'nest-commander';
22
import { ServeCommand } from './serve.command';
33
import { ChatCommand } from './chat.command';
44
import { ModelsCommand } from './models.command';
@@ -11,10 +11,9 @@ import pkg from '@/../package.json';
1111
import { PresetCommand } from './presets.command';
1212
import { EmbeddingCommand } from './embeddings.command';
1313
import { BenchmarkCommand } from './benchmark.command';
14+
import chalk from 'chalk';
15+
import { printSlogan } from '@/utils/logo';
1416

15-
interface CortexCommandOptions {
16-
version: boolean;
17-
}
1817
@RootCommand({
1918
subCommands: [
2019
ModelsCommand,
@@ -32,17 +31,12 @@ interface CortexCommandOptions {
3231
description: 'Cortex CLI',
3332
})
3433
export class CortexCommand extends CommandRunner {
35-
async run(input: string[], option: CortexCommandOptions): Promise<void> {
36-
if (option.version) console.log(pkg.version);
37-
}
38-
39-
@Option({
40-
flags: '-v, --version',
41-
description: 'Cortex version',
42-
defaultValue: false,
43-
name: 'version',
44-
})
45-
parseVersion() {
46-
return true;
34+
async run(): Promise<void> {
35+
printSlogan();
36+
console.log('\n');
37+
console.log(`Cortex CLI - v${pkg.version}`);
38+
console.log(chalk.blue(`Github: ${pkg.homepage}`));
39+
console.log('\n');
40+
this.command?.help();
4741
}
4842
}

cortex-js/src/infrastructure/commanders/embeddings.command.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ interface EmbeddingCommandOptions {
1818

1919
@SubCommand({
2020
name: 'embeddings',
21+
arguments: '[model_id]',
2122
description: 'Creates an embedding vector representing the input text.',
23+
argsDescription: {
24+
model_id:
25+
'Model to use for embedding. If not provided, it will prompt to select from running models.',
26+
},
2227
})
2328
export class EmbeddingCommand extends CommandRunner {
2429
constructor(
@@ -29,16 +34,19 @@ export class EmbeddingCommand extends CommandRunner {
2934
) {
3035
super();
3136
}
32-
async run(_input: string[], options: EmbeddingCommandOptions): Promise<void> {
33-
let modelId = _input[0];
37+
async run(
38+
passedParams: string[],
39+
options: EmbeddingCommandOptions,
40+
): Promise<void> {
41+
let modelId = passedParams[0];
3442
// First attempt to get message from input or options
35-
let input: string | string[] = options.input ?? _input.splice(1);
43+
let input: string | string[] = options.input ?? passedParams.splice(1);
3644

3745
// Check for model existing
3846
if (!modelId || !(await this.modelsUsecases.findOne(modelId))) {
3947
// Model ID is not provided
4048
// first input might be message input
41-
input = _input ?? options.input;
49+
input = passedParams ?? options.input;
4250
// If model ID is not provided, prompt user to select from running models
4351
const models = await this.psCliUsecases.getModels();
4452
if (models.length === 1) {

cortex-js/src/infrastructure/commanders/init.command.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { InitOptions } from './types/init-options.interface';
1010
@SubCommand({
1111
name: 'init',
1212
aliases: ['setup'],
13+
arguments: '[version]',
1314
description: "Init settings and download cortex's dependencies",
15+
argsDescription: {
16+
version: 'Version of cortex engine',
17+
},
1418
})
1519
export class InitCommand extends CommandRunner {
1620
constructor(
@@ -20,16 +24,19 @@ export class InitCommand extends CommandRunner {
2024
super();
2125
}
2226

23-
async run(input: string[], options?: InitOptions): Promise<void> {
27+
async run(passedParams: string[], options?: InitOptions): Promise<void> {
2428
if (options?.silent) {
25-
return this.initSilently(input);
29+
return this.initSilently(passedParams);
2630
} else {
27-
return this.initPrompts(input, options);
31+
return this.initPrompts(passedParams, options);
2832
}
2933
}
3034

31-
private initSilently = async (input: string[], options: InitOptions = {}) => {
32-
const version = input[0] ?? 'latest';
35+
private initSilently = async (
36+
passedParams: string[],
37+
options: InitOptions = {},
38+
) => {
39+
const version = passedParams[0] ?? 'latest';
3340
if (process.platform === 'darwin') {
3441
const engineFileName = this.initUsecases.parseEngineFileName(options);
3542
return this.initUsecases.installEngine(engineFileName, version);

cortex-js/src/infrastructure/commanders/models/model-get.command.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@ import { CommandRunner, SubCommand } from 'nest-commander';
22
import { ModelsCliUsecases } from '@commanders/usecases/models.cli.usecases';
33
import { exit } from 'node:process';
44

5-
@SubCommand({ name: 'get', description: 'Get a model by ID.' })
5+
@SubCommand({
6+
name: 'get',
7+
description: 'Get a model by ID.',
8+
arguments: '<model_id>',
9+
argsDescription: {
10+
model_id: 'Model ID to get information about.',
11+
},
12+
})
613
export class ModelGetCommand extends CommandRunner {
714
constructor(private readonly modelsCliUsecases: ModelsCliUsecases) {
815
super();
916
}
1017

11-
async run(input: string[]): Promise<void> {
12-
if (input.length === 0) {
18+
async run(passedParams: string[]): Promise<void> {
19+
if (passedParams.length === 0) {
1320
console.error('Model ID is required');
1421
exit(1);
1522
}
1623

17-
const model = await this.modelsCliUsecases.getModel(input[0]);
24+
const model = await this.modelsCliUsecases.getModel(passedParams[0]);
1825
if (!model) console.error('Model not found');
1926
else console.log(model);
2027
}

0 commit comments

Comments
 (0)