Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: persists engine version on init #969

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading