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

Commit 8adab7e

Browse files
authored
Merge pull request #576 from janhq/chore/update-api
chore: remove inference settings
2 parents 502ae34 + 4631366 commit 8adab7e

21 files changed

+58
-281
lines changed

cortex-js/src/app.module.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,26 @@ import { DevtoolsModule } from '@nestjs/devtools-integration';
66
import { DatabaseModule } from './infrastructure/database/database.module';
77
import { ChatModule } from './usecases/chat/chat.module';
88
import { AssistantsModule } from './usecases/assistants/assistants.module';
9-
import { InferenceSettingsModule } from './usecases/inference-settings/inference-settings.module';
109
import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module';
1110
import { CortexModule } from './usecases/cortex/cortex.module';
1211
import { ConfigModule } from '@nestjs/config';
12+
import { env } from 'node:process';
1313

1414
@Module({
1515
imports: [
1616
DevtoolsModule.register({
17-
http: process.env.NODE_ENV !== 'production',
17+
http: env.NODE_ENV !== 'production',
1818
}),
1919
ConfigModule.forRoot({
2020
isGlobal: true,
21-
envFilePath:
22-
process.env.NODE_ENV === 'production' ? '.env' : '.env.development',
21+
envFilePath: env.NODE_ENV !== 'production' ? '.env.development' : '.env',
2322
}),
2423
DatabaseModule,
2524
MessagesModule,
2625
ThreadsModule,
2726
ModelsModule,
2827
ChatModule,
2928
AssistantsModule,
30-
InferenceSettingsModule,
3129
CortexModule,
3230
ExtensionModule,
3331
],

cortex-js/src/infrastructure/commanders/inquirer/init.questions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Question, QuestionSet } from 'nest-commander';
2+
import { platform } from 'node:process';
23

34
@QuestionSet({ name: 'create-init-questions' })
45
export class CreateInitQuestions {
@@ -8,7 +9,7 @@ export class CreateInitQuestions {
89
name: 'runMode',
910
default: 'CPU',
1011
choices: ['CPU', 'GPU'],
11-
when: () => process.platform !== 'darwin',
12+
when: () => platform !== 'darwin',
1213
})
1314
parseRunMode(val: string) {
1415
return val;
@@ -31,7 +32,7 @@ export class CreateInitQuestions {
3132
message: 'Select CPU instructions set',
3233
name: 'instructions',
3334
choices: ['AVX2', 'AVX', 'AVX-512'],
34-
when: () => process.platform !== 'darwin',
35+
when: () => platform !== 'darwin',
3536
})
3637
parseContent(val: string) {
3738
return val;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ export class PullCommand extends CommandRunner {
3434
super();
3535
}
3636

37-
async run(input: string[]): Promise<void> {
37+
async run(input: string[]) {
3838
if (input.length < 1) {
39-
return Promise.reject('Model ID is required');
39+
console.error('Model ID is required');
40+
exit(1);
4041
}
4142

4243
const modelId = input[0];
@@ -46,7 +47,7 @@ export class PullCommand extends CommandRunner {
4647

4748
const bar = new SingleBar({}, Presets.shades_classic);
4849
bar.start(100, 0);
49-
await this.modelsUsecases.downloadModel({ modelId }, (progress) => {
50+
await this.modelsUsecases.downloadModel(modelId, (progress) => {
5051
bar.update(progress);
5152
});
5253
console.log('\nDownload complete!');

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,7 @@ export class StartCommand extends CommandRunner {
4040
}
4141

4242
private async startModel(modelId: string) {
43-
// TODO: NamH remove these hardcoded value
44-
const settings: ModelSettingParams = {
45-
cpu_threads: 10,
46-
ctx_len: 2048,
47-
embedding: false,
48-
prompt_template:
49-
'{system_message}\n### Instruction: {prompt}\n### Response:',
50-
system_prompt: '',
51-
user_prompt: '\n### Instruction: ',
52-
ai_prompt: '\n### Response:',
53-
ngl: 100,
54-
};
55-
return this.modelsUsecases.startModel(modelId, settings);
43+
return this.modelsUsecases.startModel(modelId);
5644
}
5745

5846
private async getModelOrStop(modelId: string): Promise<Model> {

cortex-js/src/infrastructure/controllers/inference-settings.controller.spec.ts

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

cortex-js/src/infrastructure/controllers/inference-settings.controller.ts

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

cortex-js/src/infrastructure/controllers/models.controller.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,65 @@ import { CreateModelDto } from '@/infrastructure/dtos/models/create-model.dto';
1313
import { UpdateModelDto } from '@/infrastructure/dtos/models/update-model.dto';
1414
import { ApiResponse, ApiTags } from '@nestjs/swagger';
1515
import { StartModelSuccessDto } from '@/infrastructure/dtos/models/start-model-success.dto';
16-
import { DownloadModelDto } from '@/infrastructure/dtos/models/download-model.dto';
1716
import { ModelSettingParamsDto } from '../dtos/models/model-setting-params.dto';
1817

1918
@ApiTags('Models')
2019
@Controller('models')
2120
export class ModelsController {
22-
constructor(private readonly modelsService: ModelsUsecases) {}
21+
constructor(private readonly modelsUsecases: ModelsUsecases) {}
2322

2423
@Post()
2524
create(@Body() createModelDto: CreateModelDto) {
26-
return this.modelsService.create(createModelDto);
25+
return this.modelsUsecases.create(createModelDto);
2726
}
2827

2928
@HttpCode(200)
3029
@ApiResponse({
3130
status: 200,
32-
description: 'The model has been loaded successfully.',
31+
description: 'The model has been started successfully.',
3332
type: StartModelSuccessDto,
3433
})
3534
@Post(':modelId/start')
3635
startModel(
3736
@Param('modelId') modelId: string,
3837
@Body() settings: ModelSettingParamsDto,
3938
) {
40-
return this.modelsService.startModel(modelId, settings);
39+
return this.modelsUsecases.startModel(modelId, settings);
4140
}
4241

43-
@Post('download')
44-
downloadModel(@Body() downloadModelDto: DownloadModelDto) {
45-
return this.modelsService.downloadModel(downloadModelDto);
42+
@HttpCode(200)
43+
@ApiResponse({
44+
status: 200,
45+
description: 'The model has been stopped successfully.',
46+
type: StartModelSuccessDto,
47+
})
48+
@Post(':modelId/stop')
49+
stopModel(@Param('modelId') modelId: string) {
50+
return this.modelsUsecases.stopModel(modelId);
51+
}
52+
53+
@Get('download/:modelId')
54+
downloadModel(@Param('modelId') modelId: string) {
55+
return this.modelsUsecases.downloadModel(modelId);
4656
}
4757

4858
@Get()
4959
findAll() {
50-
return this.modelsService.findAll();
60+
return this.modelsUsecases.findAll();
5161
}
5262

5363
@Get(':id')
5464
findOne(@Param('id') id: string) {
55-
return this.modelsService.findOne(id);
65+
return this.modelsUsecases.findOne(id);
5666
}
5767

5868
@Patch(':id')
5969
update(@Param('id') id: string, @Body() updateModelDto: UpdateModelDto) {
60-
return this.modelsService.update(id, updateModelDto);
70+
return this.modelsUsecases.update(id, updateModelDto);
6171
}
6272

6373
@Delete(':id')
6474
remove(@Param('id') id: string) {
65-
return this.modelsService.remove(id);
75+
return this.modelsUsecases.remove(id);
6676
}
6777
}

cortex-js/src/infrastructure/database/database.module.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { sqliteDatabaseProviders } from './sqlite-database.providers';
44
import { modelProviders } from './providers/model.providers';
55
import { assistantProviders } from './providers/assistant.providers';
66
import { messageProviders } from './providers/message.providers';
7-
import { inferenceSettingProviders } from './providers/inference-setting.providers';
87

98
@Module({
109
providers: [
@@ -13,14 +12,12 @@ import { inferenceSettingProviders } from './providers/inference-setting.provide
1312
...modelProviders,
1413
...assistantProviders,
1514
...messageProviders,
16-
...inferenceSettingProviders,
1715
],
1816
exports: [
1917
...threadProviders,
2018
...modelProviders,
2119
...assistantProviders,
2220
...messageProviders,
23-
...inferenceSettingProviders,
2421
],
2522
})
2623
export class DatabaseModule {}

cortex-js/src/infrastructure/database/providers/inference-setting.providers.ts

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

cortex-js/src/infrastructure/dtos/cortex/start-cortex.dto.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1+
import { ApiProperty } from '@nestjs/swagger';
12
import { IsIP, IsNumber, IsString, Max, Min } from 'class-validator';
3+
import { defaultCortexCppHost, defaultCortexCppPort } from 'constant';
24

35
export class StartCortexDto {
6+
@ApiProperty({
7+
name: 'host',
8+
description: 'Cortexcpp host',
9+
default: defaultCortexCppHost,
10+
})
411
@IsString()
512
@IsIP()
613
host: string;
714

15+
@ApiProperty({
16+
name: 'port',
17+
description: 'Cortexcpp port',
18+
default: defaultCortexCppPort,
19+
})
820
@IsNumber()
921
@Min(0)
1022
@Max(65535)

0 commit comments

Comments
 (0)