|
1 | | -import { RootCommand, CommandRunner } from 'nest-commander'; |
2 | | -import { ModelsUsecases } from 'src/usecases/models/models.usecases'; |
3 | | -import { LoadModelDto } from '../dtos/models/load-model.dto'; |
4 | | -import { CortexUsecases } from 'src/usecases/cortex/cortex.usecases'; |
| 1 | +import { RootCommand, CommandRunner, Option } from 'nest-commander'; |
5 | 2 | import { PullCommand } from './pull.command'; |
6 | 3 | import { ServeCommand } from './serve.command'; |
7 | 4 | import { InferenceCommand } from './inference.command'; |
| 5 | +import { ModelsCommand } from './models.command'; |
| 6 | +import { CortexUsecases } from '@/usecases/cortex/cortex.usecases'; |
| 7 | +import { defaultCortexJsHost, defaultCortexJsPort } from 'constant'; |
8 | 8 |
|
9 | 9 | @RootCommand({ |
10 | | - subCommands: [PullCommand, ServeCommand, InferenceCommand], |
| 10 | + subCommands: [ModelsCommand, PullCommand, ServeCommand, InferenceCommand], |
11 | 11 | }) |
12 | 12 | export class BasicCommand extends CommandRunner { |
13 | | - constructor( |
14 | | - private readonly modelsUsecases: ModelsUsecases, |
15 | | - private readonly cortexUsecases: CortexUsecases, |
16 | | - ) { |
| 13 | + constructor(private readonly cortexUsecases: CortexUsecases) { |
17 | 14 | super(); |
18 | 15 | } |
19 | 16 |
|
20 | | - async run(input: string[]): Promise<void> { |
| 17 | + async run(input: string[], options?: any): Promise<void> { |
21 | 18 | const command = input[0]; |
22 | 19 |
|
23 | 20 | switch (command) { |
24 | | - case 'models': |
25 | | - this.modelsUsecases.findAll().then((e: any) => console.log(e)); |
26 | | - return; |
27 | | - |
28 | 21 | case 'start': |
29 | | - return this.startCortex(); |
30 | | - |
31 | | - case 'load': |
32 | | - return this.loadModel(input); |
33 | | - |
| 22 | + const host = options?.host || defaultCortexJsHost; |
| 23 | + const port = options?.port || defaultCortexJsPort; |
| 24 | + return this.cortexUsecases |
| 25 | + .startCortex(host, port) |
| 26 | + .then((e) => console.log(e)); |
| 27 | + case 'stop': |
| 28 | + return this.cortexUsecases |
| 29 | + .stopCortex(defaultCortexJsHost, defaultCortexJsPort) |
| 30 | + .then((e) => console.log(e)); |
34 | 31 | default: |
35 | 32 | console.error(`Command ${command} is not supported`); |
36 | 33 | return; |
37 | 34 | } |
38 | 35 | } |
39 | 36 |
|
40 | | - private async startCortex(): Promise<void> { |
41 | | - const host = '127.0.0.1'; |
42 | | - const port = '3928'; |
43 | | - const result = await this.cortexUsecases.startCortex(host, port); |
44 | | - console.log(result); |
| 37 | + @Option({ |
| 38 | + flags: '--host <host>', |
| 39 | + description: 'Host to serve the application', |
| 40 | + }) |
| 41 | + parseHost(value: string) { |
| 42 | + return value; |
45 | 43 | } |
46 | 44 |
|
47 | | - private async loadModel(input: string[]): Promise<void> { |
48 | | - if (input.length < 2) { |
49 | | - return Promise.reject('Model ID is required'); |
50 | | - } |
51 | | - const settings = { |
52 | | - cpu_threads: 10, |
53 | | - ctx_len: 2048, |
54 | | - embedding: false, |
55 | | - prompt_template: |
56 | | - '{system_message}\n### Instruction: {prompt}\n### Response:', |
57 | | - system_prompt: '', |
58 | | - user_prompt: '\n### Instruction: ', |
59 | | - ai_prompt: '\n### Response:', |
60 | | - ngl: 100, |
61 | | - }; |
62 | | - const loadModelDto: LoadModelDto = { modelId: input[1], settings }; |
63 | | - await this.modelsUsecases |
64 | | - .loadModel(loadModelDto) |
65 | | - .then((e) => console.log(e)); |
| 45 | + @Option({ |
| 46 | + flags: '--port <port>', |
| 47 | + description: 'Port to serve the application', |
| 48 | + }) |
| 49 | + parsePort(value: string) { |
| 50 | + return parseInt(value, 10); |
66 | 51 | } |
67 | 52 | } |
0 commit comments