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

Commit fa49df1

Browse files
committed
chore: move db and models folder to dist
Signed-off-by: James <namnh0122@gmail.com>
1 parent ab36451 commit fa49df1

File tree

8 files changed

+27
-28
lines changed

8 files changed

+27
-28
lines changed

cortex-js/.env.development

Whitespace-only changes.

cortex-js/.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
EXTENSIONS_PATH=<EXTENSIONS_PATH>
22
CORTEX_MODELS_DIR=<CORTEX_MODELS_DIR>
3-
CORTEX_BINARY_PATH=<CORTEX_BINARY_PATH>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
21
import { CommandRunner, InquirerService, SubCommand } from 'nest-commander';
32
import { InitCliUsecases } from './usecases/init.cli.usecases';
43
import { InitOptions } from './types/init-options.interface';
54

6-
75
@SubCommand({
86
name: 'init',
97
aliases: ['setup'],
108
description: "Init settings and download cortex's dependencies",
119
})
1210
export class InitCommand extends CommandRunner {
13-
1411
constructor(
1512
private readonly inquirerService: InquirerService,
1613
private readonly initUsecases: InitCliUsecases,
@@ -19,15 +16,18 @@ export class InitCommand extends CommandRunner {
1916
}
2017

2118
async run(input: string[], options?: InitOptions): Promise<void> {
22-
options = await this.inquirerService.ask('init-run-mode-questions', options);
19+
options = await this.inquirerService.ask(
20+
'init-run-mode-questions',
21+
options,
22+
);
2323

2424
if (options.runMode === 'GPU' && !(await this.initUsecases.cudaVersion())) {
2525
options = await this.inquirerService.ask('init-cuda-questions', options);
2626
}
2727

2828
const version = input[0] ?? 'latest';
2929

30-
const engineFileName = this.initUsecases.parseEngineFileName(options)
30+
const engineFileName = this.initUsecases.parseEngineFileName(options);
3131
await this.initUsecases.installEngine(engineFileName, version);
3232

3333
if (options.installCuda === 'Yes') {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ export class ModelsCliUsecases {
140140
let stopWord = '';
141141
try {
142142
const { metadata } = await gguf(downloadUrl);
143-
// @ts-ignore
143+
// @ts-expect-error "tokenizer.ggml.eos_token_id"
144144
const index = metadata['tokenizer.ggml.eos_token_id'];
145-
// @ts-ignore
145+
// @ts-expect-error "tokenizer.ggml.tokens"
146146
stopWord = metadata['tokenizer.ggml.tokens'][index] ?? '';
147147
data.siblings[i].stopWord = stopWord;
148148
} catch (err) {

cortex-js/src/infrastructure/database/sqlite-database.providers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { databaseFile } from 'constant';
2+
import { resolve } from 'path';
23
import { DataSource } from 'typeorm';
34

45
export const sqliteDatabaseProviders = [
56
{
67
provide: 'DATA_SOURCE',
78
useFactory: async () => {
9+
const sqlitePath = resolve(__dirname, `../../../${databaseFile}`);
810
const dataSource = new DataSource({
911
type: 'sqlite',
10-
database: databaseFile,
12+
database: sqlitePath,
1113
synchronize: process.env.NODE_ENV !== 'production',
1214
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
1315
});

cortex-js/src/infrastructure/providers/cortex/cortex.provider.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { OAIEngineExtension } from '@/domain/abstracts/oai.abstract';
33
import { PromptTemplate } from '@/domain/models/prompt-template.interface';
44
import { join, resolve } from 'path';
55
import { Model, ModelSettingParams } from '@/domain/models/model.interface';
6-
import { ConfigService } from '@nestjs/config';
76
import { HttpService } from '@nestjs/axios';
87
import { defaultCortexCppHost, defaultCortexCppPort } from 'constant';
98
import { readdirSync } from 'node:fs';
@@ -21,20 +20,17 @@ export default class CortexProvider extends OAIEngineExtension {
2120
private loadModelUrl = `http://${defaultCortexCppHost}:${defaultCortexCppPort}/inferences/server/loadmodel`;
2221
private unloadModelUrl = `http://${defaultCortexCppHost}:${defaultCortexCppPort}/inferences/server/unloadmodel`;
2322

24-
constructor(
25-
private readonly configService: ConfigService,
26-
protected readonly httpService: HttpService,
27-
) {
23+
constructor(protected readonly httpService: HttpService) {
2824
super(httpService);
2925
}
3026

27+
modelDir = () => resolve(__dirname, `../../../models`);
28+
3129
override async loadModel(
3230
model: Model,
3331
settings?: ModelSettingParams,
3432
): Promise<void> {
35-
const modelsContainerDir =
36-
this.configService.get<string>('CORTEX_MODELS_DIR') ??
37-
resolve('./models');
33+
const modelsContainerDir = this.modelDir();
3834

3935
const modelFolderFullPath = join(modelsContainerDir, model.id);
4036
const ggufFiles = readdirSync(modelFolderFullPath).filter((file) => {
@@ -47,7 +43,7 @@ export default class CortexProvider extends OAIEngineExtension {
4743

4844
const modelBinaryLocalPath = join(modelFolderFullPath, ggufFiles[0]);
4945

50-
const cpuThreadCount = 1; // TODO: NamH Math.max(1, nitroResourceProbe.numCpuPhysicalCore);
46+
const cpuThreadCount = 1; // TODO: Math.max(1, nitroResourceProbe.numCpuPhysicalCore);
5147
const modelSettings = {
5248
// This is critical and requires real CPU physical core count (or performance core)
5349
model: model.id,

cortex-js/src/usecases/cortex/cortex.usecases.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { existsSync } from 'node:fs';
1010
export class CortexUsecases {
1111
private cortexProcess: ChildProcess | undefined;
1212

13-
constructor(private readonly httpService: HttpService) { }
13+
constructor(private readonly httpService: HttpService) {}
1414

1515
async startCortex(
1616
host: string = defaultCortexCppHost,
@@ -24,7 +24,11 @@ export class CortexUsecases {
2424
}
2525

2626
const args: string[] = ['1', host, `${port}`];
27-
const cortexCppPath = join(__dirname, '../../../cortex-cpp/cortex-cpp' + `${process.platform === 'win32' ? '.exe' : ''}`);
27+
const cortexCppPath = join(
28+
__dirname,
29+
'../../../cortex-cpp/cortex-cpp' +
30+
`${process.platform === 'win32' ? '.exe' : ''}`,
31+
);
2832

2933
if (!existsSync(cortexCppPath)) {
3034
throw new Error('Cortex binary not found');
@@ -85,7 +89,7 @@ export class CortexUsecases {
8589
}
8690

8791
private registerCortexEvents() {
88-
this.cortexProcess?.on('spawn', () => { });
92+
this.cortexProcess?.on('spawn', () => {});
8993

9094
this.cortexProcess?.on('message', (message) => {
9195
console.log('Cortex process message', message);

cortex-js/src/usecases/models/models.usecases.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { BadRequestException, Inject, Injectable } from '@nestjs/common';
55
import { Repository } from 'typeorm';
66
import { Model, ModelFormat } from '@/domain/models/model.interface';
77
import { ModelNotFoundException } from '@/infrastructure/exception/model-not-found.exception';
8-
import { join, basename } from 'path';
8+
import { join, basename, resolve } from 'path';
99
import {
1010
promises,
1111
createWriteStream,
@@ -14,7 +14,6 @@ import {
1414
rmdirSync,
1515
} from 'fs';
1616
import { StartModelSuccessDto } from '@/infrastructure/dtos/models/start-model-success.dto';
17-
import { ConfigService } from '@nestjs/config';
1817
import { ExtensionRepository } from '@/domain/repositories/extension.interface';
1918
import { EngineExtension } from '@/domain/abstracts/engine.abstract';
2019
import { HttpService } from '@nestjs/axios';
@@ -26,7 +25,6 @@ export class ModelsUsecases {
2625
@Inject('MODEL_REPOSITORY')
2726
private readonly modelRepository: Repository<ModelEntity>,
2827
private readonly extensionRepository: ExtensionRepository,
29-
private readonly configService: ConfigService,
3028
private readonly httpService: HttpService,
3129
) {}
3230

@@ -65,8 +63,7 @@ export class ModelsUsecases {
6563
}
6664

6765
async remove(id: string) {
68-
const modelsContainerDir =
69-
this.configService.get<string>('CORTEX_MODELS_DIR') ?? './models';
66+
const modelsContainerDir = this.modelDir();
7067

7168
if (!existsSync(modelsContainerDir)) {
7269
return;
@@ -150,6 +147,8 @@ export class ModelsUsecases {
150147
});
151148
}
152149

150+
modelDir = () => resolve(__dirname, `../../../models`);
151+
153152
async downloadModel(modelId: string, callback?: (progress: number) => void) {
154153
const model = await this.getModelOrThrow(modelId);
155154

@@ -165,8 +164,7 @@ export class ModelsUsecases {
165164
}
166165

167166
const fileName = basename(downloadUrl);
168-
const modelsContainerDir =
169-
this.configService.get<string>('CORTEX_MODELS_DIR') ?? './models';
167+
const modelsContainerDir = this.modelDir();
170168

171169
if (!existsSync(modelsContainerDir)) {
172170
mkdirSync(modelsContainerDir, { recursive: true });

0 commit comments

Comments
 (0)