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

Commit 2cc0061

Browse files
committed
fix: benchmark with custom model param
1 parent a6be6ab commit 2cc0061

File tree

3 files changed

+40
-26
lines changed

3 files changed

+40
-26
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { CommandRunner, SubCommand, Option } from 'nest-commander';
22
import { BenchmarkCliUsecases } from './usecases/benchmark.cli.usecases';
3-
import { BenchmarkConfig } from './types/benchmark-config.interface';
3+
import {
4+
BenchmarkConfig,
5+
ParametersConfig,
6+
} from './types/benchmark-config.interface';
47

58
@SubCommand({
69
name: 'benchmark',
@@ -20,10 +23,12 @@ export class BenchmarkCommand extends CommandRunner {
2023
passedParams: string[],
2124
options?: Partial<BenchmarkConfig>,
2225
): Promise<void> {
23-
return this.benchmarkUsecases.benchmark({
24-
...options,
25-
...(passedParams[0] ? { modelId: passedParams[0] } : {}),
26-
});
26+
return this.benchmarkUsecases.benchmark(
27+
options ?? {},
28+
passedParams[0]
29+
? ({ model: passedParams[0] } as ParametersConfig)
30+
: undefined,
31+
);
2732
}
2833

2934
@Option({

cortex-js/src/infrastructure/commanders/types/benchmark-config.interface.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import { ChatCompletionMessageParam } from 'openai/resources';
22

3+
export interface ApiConfig {
4+
base_url: string;
5+
api_key: string;
6+
parameters: ParametersConfig;
7+
}
8+
9+
export interface ParametersConfig {
10+
messages: ChatCompletionMessageParam[];
11+
model: string;
12+
stream?: boolean;
13+
max_tokens?: number;
14+
stop?: string[];
15+
frequency_penalty?: number;
16+
presence_penalty?: number;
17+
temperature?: number;
18+
top_p?: number;
19+
}
20+
321
export interface BenchmarkConfig {
4-
api: {
5-
base_url: string;
6-
api_key: string;
7-
parameters: {
8-
messages: ChatCompletionMessageParam[];
9-
model: string;
10-
stream?: boolean;
11-
max_tokens?: number;
12-
stop?: string[];
13-
frequency_penalty?: number;
14-
presence_penalty?: number;
15-
temperature?: number;
16-
top_p?: number;
17-
};
18-
};
22+
api: ApiConfig;
1923
prompts?: {
2024
min: number;
2125
max: number;

cortex-js/src/infrastructure/commanders/usecases/benchmark.cli.usecases.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { FileManagerService } from '@/infrastructure/services/file-manager/file-
88
import { join } from 'path';
99
import { ModelsCliUsecases } from './models.cli.usecases';
1010
import { spawn } from 'child_process';
11-
import { BenchmarkConfig } from '@commanders/types/benchmark-config.interface';
11+
import {
12+
BenchmarkConfig,
13+
ParametersConfig,
14+
} from '@commanders/types/benchmark-config.interface';
1215
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
1316
import { inspect } from 'util';
1417
import { defaultBenchmarkConfiguration } from '@/infrastructure/constants/benchmark';
@@ -28,13 +31,17 @@ export class BenchmarkCliUsecases {
2831
/**
2932
* Benchmark and analyze the performance of a specific AI model using a variety of system resources
3033
*/
31-
async benchmark(options: Partial<BenchmarkConfig>) {
34+
async benchmark(
35+
options: Partial<BenchmarkConfig>,
36+
params?: ParametersConfig,
37+
) {
3238
return this.getBenchmarkConfig().then((config) => {
3339
this.config = {
3440
...config,
3541
...options,
3642
};
3743

44+
const model = params?.model ?? this.config.api.parameters.model;
3845
// TODO: Using OpenAI client or Cortex client to benchmark?
3946
this.openai = new OpenAI({
4047
apiKey: this.config.api.api_key,
@@ -49,15 +56,13 @@ export class BenchmarkCliUsecases {
4956

5057
return this.cortexUsecases
5158
.startCortex()
52-
.then(() =>
53-
this.modelsCliUsecases.startModel(this.config.api.parameters.model),
54-
)
59+
.then(() => this.modelsCliUsecases.startModel(model))
5560
.then(() =>
5661
this.psUsecases
5762
.getModels()
5863
.then((models) =>
5964
models.find(
60-
(e) => e.modelId === this.config.api.parameters.model,
65+
(e) => e.modelId === model,
6166
),
6267
),
6368
)

0 commit comments

Comments
 (0)