This repository was archived by the owner on Jul 4, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed
cortex-js/src/infrastructure Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff 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 ) => {
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { Extension } from '@/domain/abstracts/extension.abstract';
44import { readdir , lstat } from 'fs/promises' ;
55import { join } from 'path' ;
66import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service' ;
7- import { existsSync } from 'fs' ;
7+ import { existsSync , mkdirSync , watch } from 'fs' ;
88import { Engines } from '@/infrastructure/commanders/types/engine.interface' ;
99import { OAIEngineExtension } from '@/domain/abstracts/oai.abstract' ;
1010import { HttpService } from '@nestjs/axios' ;
@@ -27,6 +27,16 @@ 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+ if ( ! existsSync ( path ) ) mkdirSync ( path ) ;
34+ watch ( path , ( eventType , filename ) => {
35+ this . extensions . clear ( ) ;
36+ this . loadCoreExtensions ( ) ;
37+ this . loadExternalExtensions ( ) ;
38+ } ) ;
39+ } ) ;
3040 }
3141 /**
3242 * Persist extension to the extensions map
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
1010 readdirSync ,
1111 rmSync ,
1212 writeFileSync ,
13+ watch ,
1314} from 'fs' ;
1415import { load , dump } from 'js-yaml' ;
1516import { 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+ fileService . getModelsPath ( ) . then ( ( path ) => {
30+ if ( ! existsSync ( path ) ) mkdirSync ( 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 )
You can’t perform that action at this time.
0 commit comments