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

Commit 2e07fd5

Browse files
committed
feat: watch models and engines update for proper data retrieval
1 parent efa55f1 commit 2e07fd5

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class ChatController {
3333
@Body() createChatDto: CreateChatCompletionDto,
3434
@Res() res: Response,
3535
) {
36-
let { stream } = createChatDto;
36+
const { stream } = createChatDto;
3737
this.chatService
3838
.inference(createChatDto, extractCommonHeaders(headers))
3939
.then((response) => {

cortex-js/src/infrastructure/repositories/extensions/extension.repository.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Extension } from '@/domain/abstracts/extension.abstract';
44
import { readdir, lstat } from 'fs/promises';
55
import { join } from 'path';
66
import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service';
7-
import { existsSync } from 'fs';
7+
import { existsSync, watch } from 'fs';
88
import { Engines } from '@/infrastructure/commanders/types/engine.interface';
99
import { OAIEngineExtension } from '@/domain/abstracts/oai.abstract';
1010
import { HttpService } from '@nestjs/axios';
@@ -27,6 +27,15 @@ export class ExtensionRepositoryImpl implements ExtensionRepository {
2727
) {
2828
this.loadCoreExtensions();
2929
this.loadExternalExtensions();
30+
31+
// Watch engine folder only for now
32+
fileService.getCortexCppEnginePath().then(path =>
33+
watch(path, (eventType, filename) => {
34+
this.extensions.clear();
35+
this.loadCoreExtensions();
36+
this.loadExternalExtensions();
37+
})
38+
)
3039
}
3140
/**
3241
* Persist extension to the extensions map

cortex-js/src/infrastructure/repositories/models/model.repository.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
readdirSync,
1111
rmSync,
1212
writeFileSync,
13+
watch,
1314
} from 'fs';
1415
import { load, dump } from 'js-yaml';
1516
import { isLocalModel, normalizeModelId } from '@/utils/normalize-model-id';
@@ -25,6 +26,12 @@ export class ModelRepositoryImpl implements ModelRepository {
2526

2627
constructor(private readonly fileService: FileManagerService) {
2728
this.loadModels();
29+
30+
fileService.getModelsPath().then((path) =>
31+
watch(path, (eventType, filename) => {
32+
this.loadModels(true);
33+
}),
34+
);
2835
}
2936

3037
/**
@@ -121,11 +128,14 @@ export class ModelRepositoryImpl implements ModelRepository {
121128
* This would load all the models from the models folder
122129
* @returns the list of models
123130
*/
124-
private async loadModels(): Promise<Model[]> {
125-
if (this.loaded) return Array.from(this.models.values());
131+
private async loadModels(forceReload: boolean = false): Promise<Model[]> {
132+
if (this.loaded && !forceReload) return Array.from(this.models.values());
126133
const modelsPath =
127134
process.env.EXTENSIONS_PATH ?? (await this.fileService.getModelsPath());
128135

136+
this.models.clear();
137+
this.fileModel.clear();
138+
129139
if (!existsSync(modelsPath)) return [];
130140

131141
const modelFiles = readdirSync(modelsPath)

0 commit comments

Comments
 (0)