|
1 | 1 | import { Injectable } from '@nestjs/common'; |
2 | 2 | import { ChildProcess, spawn } from 'child_process'; |
3 | | -import { join } from 'path'; |
| 3 | +import { join, delimiter } from 'path'; |
4 | 4 | import { CortexOperationSuccessfullyDto } from '@/infrastructure/dtos/cortex/cortex-operation-successfully.dto'; |
5 | 5 | import { HttpService } from '@nestjs/axios'; |
6 | 6 | import { |
@@ -45,6 +45,7 @@ export class CortexUsecases { |
45 | 45 | if (!existsSync(cortexCppPath)) { |
46 | 46 | throw new Error('The engine is not available, please run "cortex init".'); |
47 | 47 | } |
| 48 | + await this.addAdditionalDependencies(); |
48 | 49 |
|
49 | 50 | // go up one level to get the binary folder, have to also work on windows |
50 | 51 | this.cortexProcess = spawn(cortexCppPath, args, { |
@@ -103,4 +104,26 @@ export class CortexUsecases { |
103 | 104 | }) |
104 | 105 | .catch(() => false); |
105 | 106 | } |
| 107 | + |
| 108 | + private async addAdditionalDependencies() { |
| 109 | + const cortexCPPPath = join( |
| 110 | + await this.fileManagerService.getDataFolderPath(), |
| 111 | + 'cortex-cpp', |
| 112 | + ); |
| 113 | + const additionalLlamaCppPath = delimiter.concat( |
| 114 | + join(cortexCPPPath, 'cortex.llamacpp'), |
| 115 | + ); |
| 116 | + const additionalTensortLLMCppPath = delimiter.concat( |
| 117 | + join(cortexCPPPath, 'cortex.tensorrt-llm'), |
| 118 | + ); |
| 119 | + const additionalPaths = delimiter.concat( |
| 120 | + additionalLlamaCppPath, |
| 121 | + additionalTensortLLMCppPath, |
| 122 | + ); |
| 123 | + // Set the updated PATH |
| 124 | + process.env.PATH = (process.env.PATH || '').concat(additionalPaths); |
| 125 | + process.env.LD_LIBRARY_PATH = (process.env.LD_LIBRARY_PATH || '').concat( |
| 126 | + additionalPaths, |
| 127 | + ); |
| 128 | + } |
106 | 129 | } |
0 commit comments