Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 4165a06

Browse files
fix: can not chat with remote model (#907)
1 parent 4b36aa1 commit 4165a06

File tree

7 files changed

+35
-9
lines changed

7 files changed

+35
-9
lines changed

cortex-js/src/extensions/anthropic.engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default class AnthropicEngineExtension extends OAIEngineExtension {
9393
return {
9494
choices: [
9595
{
96-
delta: {
96+
message: {
9797
content: data.content[0].text,
9898
},
9999
},

cortex-js/src/infrastructure/commanders/chat.command.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ import { Engines } from './types/engine.interface';
1919
import { join } from 'path';
2020
import { EnginesUsecases } from '@/usecases/engines/engines.usecase';
2121
import { FileManagerService } from '../services/file-manager/file-manager.service';
22-
import { isLocalModel } from '@/utils/normalize-model-id';
22+
import { isLocalModel, isRemoteEngine } from '@/utils/normalize-model-id';
2323

2424
type ChatOptions = {
2525
threadId?: string;
2626
message?: string;
2727
attach: boolean;
28+
preset?: string;
2829
};
2930

3031
@SubCommand({
@@ -89,6 +90,7 @@ export class ChatCommand extends BaseCommand {
8990
const engine = existingModel.engine || Engines.llamaCPP;
9091
// Pull engine if not exist
9192
if (
93+
!isRemoteEngine(engine) &&
9294
!existsSync(join(await this.fileService.getCortexCppEnginePath(), engine))
9395
) {
9496
await this.initUsecases.installEngine(undefined, 'latest', engine);
@@ -106,7 +108,7 @@ export class ChatCommand extends BaseCommand {
106108
);
107109
return this.cortexUsecases
108110
.startCortex()
109-
.then(() => this.modelsCliUsecases.startModel(modelId))
111+
.then(() => this.modelsCliUsecases.startModel(modelId, options.preset))
110112
.then(() =>
111113
this.chatCliUsecases.chat(
112114
modelId,
@@ -156,4 +158,12 @@ export class ChatCommand extends BaseCommand {
156158
parseAttach() {
157159
return true;
158160
}
161+
162+
@Option({
163+
flags: '-p, --preset <preset>',
164+
description: 'Apply a chat preset to the chat session',
165+
})
166+
parsePreset(value: string) {
167+
return value;
168+
}
159169
}

cortex-js/src/infrastructure/commanders/cortex-command.commander.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export class CortexCommand extends CommandRunner {
5959
const port = options?.port || defaultCortexJsPort;
6060
const showLogs = options?.logs || false;
6161
const dataFolderPath = options?.dataFolder;
62-
6362
return this.startServer(host, port, showLogs, dataFolderPath);
6463
}
6564

@@ -114,13 +113,15 @@ export class CortexCommand extends CommandRunner {
114113
apiServerPort: port,
115114
dataFolderPath: dataFolderPath || config.dataFolderPath,
116115
});
116+
process.exit(1);
117117
} catch (e) {
118118
console.error(e);
119119
// revert the data folder path if it was set
120120
await this.fileManagerService.writeConfigFile({
121121
...config,
122122
});
123123
console.error(`Failed to start server. Is port ${port} in use?`);
124+
process.exit(0);
124125
}
125126
}
126127

cortex-js/src/infrastructure/commanders/models/model-start.command.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Engines } from '../types/engine.interface';
1212
import { checkModelCompatibility } from '@/utils/model-check';
1313
import { EnginesUsecases } from '@/usecases/engines/engines.usecase';
1414
import { BaseCommand } from '../base.command';
15+
import { isRemoteEngine } from '@/utils/normalize-model-id';
1516

1617
type ModelStartOptions = {
1718
attach: boolean;
@@ -72,6 +73,7 @@ export class ModelStartCommand extends BaseCommand {
7273
const engine = existingModel.engine || Engines.llamaCPP;
7374
// Pull engine if not exist
7475
if (
76+
!isRemoteEngine(engine) &&
7577
!existsSync(join(await this.fileService.getCortexCppEnginePath(), engine))
7678
) {
7779
await this.initUsecases.installEngine(undefined, 'latest', engine);

cortex-js/src/infrastructure/commanders/shortcuts/run.command.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { Engines } from '../types/engine.interface';
1212
import { checkModelCompatibility } from '@/utils/model-check';
1313
import { EnginesUsecases } from '@/usecases/engines/engines.usecase';
1414
import { BaseCommand } from '../base.command';
15+
import { isLocalModel, isRemoteEngine } from '@/utils/normalize-model-id';
1516

1617
type RunOptions = {
1718
threadId?: string;
@@ -69,11 +70,7 @@ export class RunCommand extends BaseCommand {
6970

7071
// Second check if model is available
7172
const existingModel = await this.modelsCliUsecases.getModel(modelId);
72-
if (
73-
!existingModel ||
74-
!Array.isArray(existingModel.files) ||
75-
/^(http|https):\/\/[^/]+\/.*/.test(existingModel.files[0])
76-
) {
73+
if (!existingModel || !isLocalModel(existingModel.files)) {
7774
checkingSpinner.fail(`Model is not available`);
7875
process.exit(1);
7976
}
@@ -82,6 +79,7 @@ export class RunCommand extends BaseCommand {
8279
const engine = existingModel.engine || Engines.llamaCPP;
8380
// Pull engine if not exist
8481
if (
82+
!isRemoteEngine(engine) &&
8583
!existsSync(join(await this.fileService.getCortexCppEnginePath(), engine))
8684
) {
8785
await this.initUsecases.installEngine(undefined, 'latest', engine);

cortex-js/src/infrastructure/commanders/types/engine.interface.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ export const EngineNamesMap: {
1717
[Engines.onnx]: 'onnx',
1818
[Engines.tensorrtLLM]: 'tensorrt-llm',
1919
};
20+
21+
export const RemoteEngines: Engines[] = [
22+
Engines.groq,
23+
Engines.mistral,
24+
Engines.openai,
25+
Engines.anthropic,
26+
];

cortex-js/src/utils/normalize-model-id.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { ModelArtifact } from '@/domain/models/model.interface';
22
import { getGpuInfo } from './cuda';
3+
import {
4+
Engines,
5+
RemoteEngines,
6+
} from '@/infrastructure/commanders/types/engine.interface';
37

48
export const normalizeModelId = (modelId: string): string => {
59
return modelId.replace(':main', '').replace(/[:/]/g, '-');
@@ -15,6 +19,10 @@ export const isLocalModel = (
1519
);
1620
};
1721

22+
export const isRemoteEngine = (engine: string): boolean => {
23+
return RemoteEngines.includes(engine as Engines);
24+
};
25+
1826
/**
1927
* Parse the model hub engine branch
2028
* @param branch

0 commit comments

Comments
 (0)