diff --git a/cortex-js/package.json b/cortex-js/package.json index f96f76baf..ef20491ce 100644 --- a/cortex-js/package.json +++ b/cortex-js/package.json @@ -11,7 +11,7 @@ "scripts": { "dev": "nest dev", "build": "nest build && cpx \"cpuinfo/bin/**\" dist/bin", - "build:binary": "run-script-os && cpx \"cpuinfo/bin/**\" dist/bin", + "build:binary": "npx -q patch-package && run-script-os && cpx \"cpuinfo/bin/**\" dist/bin", "build:binary:windows": "bun build --compile ./src/command.ts --outfile cortex.exe --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage", "build:binary:linux": "bun build --compile ./src/command.ts --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage", "build:binary:macos": "bun build --compile ./src/command.ts --outfile cortex --external @nestjs/microservices --external @nestjs/websockets/socket-module --external class-transformer/storage", @@ -31,8 +31,7 @@ "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", "test:e2e": "jest --config ./test/jest-e2e.json", "typeorm": "typeorm-ts-node-esm", - "build:dev": "npx nest build && chmod +x ./dist/src/command.js && npm link", - "postinstall": "npx --yes patch-package" + "build:dev": "npx nest build && chmod +x ./dist/src/command.js && npm link" }, "dependencies": { "@huggingface/gguf": "^0.1.5", diff --git a/cortex-js/src/usecases/cortex/cortex.usecases.ts b/cortex-js/src/usecases/cortex/cortex.usecases.ts index 04dafd0b3..b1210471b 100644 --- a/cortex-js/src/usecases/cortex/cortex.usecases.ts +++ b/cortex-js/src/usecases/cortex/cortex.usecases.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { ChildProcess, spawn } from 'child_process'; -import { join } from 'path'; +import { delimiter, join } from 'path'; import { CortexOperationSuccessfullyDto } from '@/infrastructure/dtos/cortex/cortex-operation-successfully.dto'; import { HttpService } from '@nestjs/axios'; @@ -11,6 +11,7 @@ import { CORTEX_CPP_HEALTH_Z_URL, CORTEX_CPP_PROCESS_DESTROY_URL, } from '@/infrastructure/constants/cortex'; +import { Engines } from '@/infrastructure/commanders/types/engine.interface'; @Injectable() export class CortexUsecases { @@ -44,6 +45,11 @@ export class CortexUsecases { throw new Error('The engine is not available, please run "cortex init".'); } + const cortexCPPPath = join( + await this.fileManagerService.getDataFolderPath(), + 'cortex-cpp', + ); + // go up one level to get the binary folder, have to also work on windows this.cortexProcess = spawn(cortexCppPath, args, { detached: !attach, @@ -52,6 +58,11 @@ export class CortexUsecases { env: { ...process.env, CUDA_VISIBLE_DEVICES: '0', + PATH: (process.env.PATH || '').concat(delimiter, cortexCPPPath), + LD_LIBRARY_PATH: (process.env.LD_LIBRARY_PATH || '').concat( + delimiter, + cortexCPPPath, + ), // // Vulkan - Support 1 device at a time for now // ...(executableOptions.vkVisibleDevices?.length > 0 && { // GGML_VULKAN_DEVICE: executableOptions.vkVisibleDevices[0],