Skip to content

Commit

Permalink
fix: persists engine version on init (janhq#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-menlo authored Aug 5, 2024
1 parent dbc63a0 commit b40100d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 12 additions & 0 deletions cortex-js/src/infrastructure/providers/cortex/cortex.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { readdirSync } from 'node:fs';
import { normalizeModelId } from '@/utils/normalize-model-id';
import { firstValueFrom } from 'rxjs';
import { fileManagerService } from '@/infrastructure/services/file-manager/file-manager.service';
import { existsSync, readFileSync } from 'fs';

export interface ModelStatResponse {
object: string;
Expand All @@ -34,6 +35,7 @@ export default class CortexProvider extends OAIEngineExtension {

constructor(protected readonly httpService: HttpService) {
super(httpService);
this.persistEngineVersion();
}

// Override the inference method to make an inference request to the engine
Expand Down Expand Up @@ -162,4 +164,14 @@ export default class CortexProvider extends OAIEngineExtension {
// Return an error if none of the conditions are met
return { error: 'Cannot split prompt template' };
};

private persistEngineVersion = async () => {
const versionFilePath = join(
await fileManagerService.getCortexCppEnginePath(),
this.name,
'version.txt',
);
if (existsSync(versionFilePath))
this.version = readFileSync(versionFilePath, 'utf-8');
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ExtensionRepositoryImpl implements ExtensionRepository {
// Watch engine folder only for now
fileManagerService.getCortexCppEnginePath().then((path) => {
if (!existsSync(path)) mkdirSync(path);
watch(path, (eventType, filename) => {
watch(path, () => {
this.extensions.clear();
this.loadCoreExtensions();
this.loadExternalExtensions();
Expand Down
11 changes: 9 additions & 2 deletions cortex-js/src/usecases/engines/engines.usecase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isEmpty } from 'lodash';
import { ForbiddenException, Injectable } from '@nestjs/common';
import { ExtensionRepository } from '@/domain/repositories/extension.interface';
import { cpSync, existsSync, mkdirSync, readdirSync } from 'fs';
import { cpSync, existsSync, mkdirSync, readdirSync, writeFileSync } from 'fs';
import { join } from 'path';
import { HttpService } from '@nestjs/axios';
import decompress from 'decompress';
Expand Down Expand Up @@ -275,6 +275,7 @@ export class EnginesUsecases {
engine,
DownloadType.Engine,
{ [toDownloadAsset.browser_download_url]: destination },
// On completed - post processing
async () => {
try {
await decompress(destination, engineDir);
Expand All @@ -287,9 +288,15 @@ export class EnginesUsecases {
// Copy the additional files to the cortex-cpp directory
for (const file of readdirSync(join(engineDir, engine))) {
if (!file.includes('engine')) {
await cpSync(join(engineDir, engine, file), join(engineDir, file));
cpSync(join(engineDir, engine, file), join(engineDir, file));
}
}

writeFileSync(
join(engineDir, engine, 'version.txt'),
release.tag_name.replace(/^v/, ''),
'utf-8',
);
},
);
}
Expand Down

0 comments on commit b40100d

Please sign in to comment.