Skip to content

Commit

Permalink
feat: watch models and engines update for proper data retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan committed Aug 1, 2024
1 parent efa55f1 commit c365ff1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ChatController {
@Body() createChatDto: CreateChatCompletionDto,
@Res() res: Response,
) {
let { stream } = createChatDto;
const { stream } = createChatDto;
this.chatService
.inference(createChatDto, extractCommonHeaders(headers))
.then((response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Extension } from '@/domain/abstracts/extension.abstract';
import { readdir, lstat } from 'fs/promises';
import { join } from 'path';
import { FileManagerService } from '@/infrastructure/services/file-manager/file-manager.service';
import { existsSync } from 'fs';
import { existsSync, mkdirSync, watch } from 'fs';
import { Engines } from '@/infrastructure/commanders/types/engine.interface';
import { OAIEngineExtension } from '@/domain/abstracts/oai.abstract';
import { HttpService } from '@nestjs/axios';
Expand All @@ -27,6 +27,16 @@ export class ExtensionRepositoryImpl implements ExtensionRepository {
) {
this.loadCoreExtensions();
this.loadExternalExtensions();

// Watch engine folder only for now
fileService.getCortexCppEnginePath().then((path) => {
if (!existsSync(path)) mkdirSync(path);
watch(path, (eventType, filename) => {
this.extensions.clear();
this.loadCoreExtensions();
this.loadExternalExtensions();
});
});
}
/**
* Persist extension to the extensions map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
readdirSync,
rmSync,
writeFileSync,
watch,
} from 'fs';
import { load, dump } from 'js-yaml';
import { isLocalModel, normalizeModelId } from '@/utils/normalize-model-id';
Expand All @@ -25,6 +26,12 @@ export class ModelRepositoryImpl implements ModelRepository {

constructor(private readonly fileService: FileManagerService) {
this.loadModels();
fileService.getModelsPath().then((path) => {
if (!existsSync(path)) mkdirSync(path);
watch(path, (eventType, filename) => {
this.loadModels(true);
});
});
}

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

this.models.clear();
this.fileModel.clear();

if (!existsSync(modelsPath)) return [];

const modelFiles = readdirSync(modelsPath)
Expand Down

0 comments on commit c365ff1

Please sign in to comment.