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

refactor: cortex cli as client - communicate with API server via cortexjs #906

Merged
merged 35 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1f97696
refactor: cortex cli as client - communicate with API server via cort…
louis-jan Jul 23, 2024
7e1febc
refactor: deprecate models CLI use cases
louis-jan Jul 23, 2024
01416eb
refactor: embeddings
louis-jan Jul 23, 2024
56fe722
refactor: move out run command
louis-jan Jul 23, 2024
6252a6a
refactor: there is no need to start cortex instance since it should b…
louis-jan Jul 23, 2024
dd245c1
refactor engine commands
marknguyen1302 Jul 23, 2024
845b7cb
fix: cortex preset on chat
louis-jan Jul 24, 2024
3d32815
chore: update threads and messages
louis-jan Jul 24, 2024
cfe41f7
refactor: chat client
louis-jan Jul 24, 2024
42d1a71
use engine api to install engine
marknguyen1302 Jul 24, 2024
b5fe6c7
chore: refactor cortex entities
louis-jan Jul 24, 2024
2cb510e
fix: remove engine dependency
louis-jan Jul 24, 2024
e4d88aa
fix: engine list
louis-jan Jul 24, 2024
189e328
chore: deprecate cli use cases
louis-jan Jul 24, 2024
55ff151
chore: deprecate database module - decouple telemetry
louis-jan Jul 24, 2024
9c1cac3
chore: bump latest engine update
louis-jan Jul 24, 2024
d8a58f5
fix: do not exit on attach
louis-jan Jul 24, 2024
de70eb3
chore: refactor pull command
marknguyen1302 Jul 25, 2024
336debf
chore: fix missing downloaded state
louis-jan Jul 25, 2024
06780ea
fix: wrong download stream
louis-jan Jul 25, 2024
3a77baf
fix: download issues
louis-jan Jul 25, 2024
01218b4
fix: engine state not update after updated config
louis-jan Jul 25, 2024
c5c4b1e
add init engine progress
marknguyen1302 Jul 25, 2024
6c5d5dc
change even method
marknguyen1302 Jul 25, 2024
8539591
change rest endpoint
marknguyen1302 Jul 25, 2024
b2157d3
change method
marknguyen1302 Jul 25, 2024
914b240
add progress to run command
marknguyen1302 Jul 25, 2024
428abf4
chore: stop model indicator
louis-jan Jul 25, 2024
b9cc7f5
chore: remove redundant input check
louis-jan Jul 25, 2024
345a8c5
add init engine progress in commands
marknguyen1302 Jul 25, 2024
a7c7bc2
add log
marknguyen1302 Jul 25, 2024
1399bc6
change cortexjs package name
marknguyen1302 Jul 25, 2024
8001801
change package in package.json
marknguyen1302 Jul 26, 2024
c19d0f3
fix wrong version
marknguyen1302 Jul 26, 2024
8113757
chore: disable outdated test cases
louis-jan Jul 26, 2024
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
2 changes: 1 addition & 1 deletion cortex-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"class-validator": "^0.14.1",
"cli-progress": "^3.12.0",
"cortex-cpp": "0.4.34",
"cortexso-node": "^0.0.4",
"@cortexso/cortex.js": "^0.1.1",
"cpu-instructions": "^0.0.11",
"decompress": "^4.2.1",
"js-yaml": "^4.1.0",
Expand Down
26 changes: 2 additions & 24 deletions cortex-js/src/command.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Module } from '@nestjs/common';
import { ModelsModule } from './usecases/models/models.module';
import { DatabaseModule } from './infrastructure/database/database.module';
import { ConfigModule } from '@nestjs/config';
import { CortexModule } from './usecases/cortex/cortex.module';
import { ModelsCommand } from './infrastructure/commanders/models.command';
import { ExtensionModule } from './infrastructure/repositories/extensions/extension.module';
import { HttpModule } from '@nestjs/axios';
import { InitRunModeQuestions } from './infrastructure/commanders/questions/init.questions';
import { ModelListCommand } from './infrastructure/commanders/models/model-list.command';
Expand All @@ -15,26 +12,18 @@ import { ModelStartCommand } from './infrastructure/commanders/models/model-star
import { ModelStopCommand } from './infrastructure/commanders/models/model-stop.command';
import { ModelGetCommand } from './infrastructure/commanders/models/model-get.command';
import { ModelRemoveCommand } from './infrastructure/commanders/models/model-remove.command';
import { RunCommand } from './infrastructure/commanders/shortcuts/run.command';
import { RunCommand } from './infrastructure/commanders/run.command';
import { ModelUpdateCommand } from './infrastructure/commanders/models/model-update.command';
import { AssistantsModule } from './usecases/assistants/assistants.module';
import { MessagesModule } from './usecases/messages/messages.module';
import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module';
import { PSCommand } from './infrastructure/commanders/ps.command';
import { PresetCommand } from './infrastructure/commanders/presets.command';
import { TelemetryModule } from './usecases/telemetry/telemetry.module';
import { TelemetryCommand } from './infrastructure/commanders/telemetry.command';
import { EmbeddingCommand } from './infrastructure/commanders/embeddings.command';
import { BenchmarkCommand } from './infrastructure/commanders/benchmark.command';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module';
import { ServeStopCommand } from './infrastructure/commanders/sub-commands/serve-stop.command';
import { ServeStopCommand } from './infrastructure/commanders/serve-stop.command';
import { ContextModule } from './infrastructure/services/context/context.module';
import { CliUsecasesModule } from './infrastructure/commanders/usecases/cli.usecases.module';
import { ExtensionsModule } from './extensions/extensions.module';
import { EnginesCommand } from './infrastructure/commanders/engines.command';
import { ConfigsModule } from './usecases/configs/configs.module';
import { EnginesModule } from './usecases/engines/engines.module';
import { EnginesListCommand } from './infrastructure/commanders/engines/engines-list.command';
import { EnginesGetCommand } from './infrastructure/commanders/engines/engines-get.command';
import { EnginesInitCommand } from './infrastructure/commanders/engines/engines-init.command';
Expand All @@ -47,22 +36,11 @@ import { EnginesSetCommand } from './infrastructure/commanders/engines/engines-s
envFilePath:
process.env.NODE_ENV !== 'production' ? '.env.development' : '.env',
}),
EventEmitterModule.forRoot(),
DatabaseModule,
ModelsModule,
CortexModule,
ExtensionModule,
HttpModule,
CliUsecasesModule,
AssistantsModule,
MessagesModule,
FileManagerModule,
TelemetryModule,
ContextModule,
DownloadManagerModule,
ExtensionsModule,
ConfigsModule,
EnginesModule,
],
providers: [
CortexCommand,
Expand Down
12 changes: 7 additions & 5 deletions cortex-js/src/domain/models/assistant.interface.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Assistant as OpenAiAssistant } from 'cortexso-node/resources/beta/assistants';
import { AssistantResponseFormatOption as OpenAIAssistantResponseFormatOption } from 'cortexso-node/resources/beta/threads/threads';
import { Cortex } from '@cortexso/cortex.js';
// TODO: Why we need to alias these?

export interface Assistant extends OpenAiAssistant {
export interface Assistant extends Cortex.Beta.Assistant {
avatar?: string;
}

export type AssistantResponseFormatOption = OpenAIAssistantResponseFormatOption;
export type AssistantResponseFormatOption =
Cortex.Beta.Threads.AssistantResponseFormatOption;

export interface AssistantToolResources extends OpenAiAssistant.ToolResources {}
export interface AssistantToolResources
extends Cortex.Beta.Assistant.ToolResources {}
9 changes: 8 additions & 1 deletion cortex-js/src/domain/models/download.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export class DownloadState {
*/
error?: string;

/**
* The progress of the download. It is a number between 0 and 100.
*/
progress: number;

/**
* The actual downloads. [DownloadState] is just a group to supporting for download multiple files.
*/
Expand Down Expand Up @@ -53,6 +58,8 @@ export class DownloadItem {
transferred: number;
};

progress: number;

checksum?: string;

status: DownloadStatus;
Expand All @@ -69,5 +76,5 @@ export interface DownloadStateEvent {
export enum DownloadType {
Model = 'model',
Miscelanous = 'miscelanous',
Engine = 'engine'
Engine = 'engine',
}
17 changes: 7 additions & 10 deletions cortex-js/src/domain/models/message.interface.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import {
Message as OpenAiMessage,
MessageContent as OpenAiMessageContent,
TextContentBlock as OpenAiTextContentBlock,
} from 'cortexso-node/resources/beta/threads/messages';
import { Cortex } from '@cortexso/cortex.js';

export interface Message extends OpenAiMessage {}
export interface Message extends Cortex.Beta.Threads.Message {}

export type MessageContent = OpenAiMessageContent;
export type MessageContent = Cortex.Beta.Threads.MessageContent;

export type TextContentBlock = OpenAiTextContentBlock;
export type TextContentBlock = Cortex.Beta.Threads.TextContentBlock;

export interface MessageIncompleteDetails
extends OpenAiMessage.IncompleteDetails {}
extends Cortex.Beta.Threads.Message.IncompleteDetails {}

export interface MessageAttachment extends OpenAiMessage.Attachment {}
export interface MessageAttachment
extends Cortex.Beta.Threads.Message.Attachment {}
4 changes: 2 additions & 2 deletions cortex-js/src/domain/models/model.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Model as OpenAiModel } from 'cortexso-node/resources/models';
import { Cortex } from '@cortexso/cortex.js';

export interface Model
extends OpenAiModel,
extends Cortex.Model,
ModelSettingParams,
ModelRuntimeParams {
/**
Expand Down
7 changes: 4 additions & 3 deletions cortex-js/src/domain/models/thread.interface.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Thread as OpenAiThread } from 'cortexso-node/resources/beta/threads/threads';
import { Assistant } from './assistant.interface';
import { Cortex } from '@cortexso/cortex.js';

export interface ThreadToolResources extends OpenAiThread.ToolResources {}
export interface ThreadToolResources
extends Cortex.Beta.Threads.Thread.ToolResources {}

export interface Thread extends OpenAiThread {
export interface Thread extends Cortex.Beta.Threads.Thread {
title: string;

assistants: Assistant[];
Expand Down
2 changes: 1 addition & 1 deletion cortex-js/src/domain/repositories/telemetry.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export abstract class TelemetryRepository {
hardware: BenchmarkHardware;
results: any;
metrics: any;
model: ModelStat;
model: any;
sessionId: string;
}): Promise<void>;
}
20 changes: 20 additions & 0 deletions cortex-js/src/infrastructure/commanders/base.command.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
import { CommandRunner } from 'nest-commander';
import { Injectable } from '@nestjs/common';
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
import Cortex from '@cortexso/cortex.js';
import ora from 'ora';
import { FileManagerService } from '../services/file-manager/file-manager.service';
import { cortexNamespace, cortexServerAPI } from '../constants/cortex';

@Injectable()
export abstract class BaseCommand extends CommandRunner {
// Cortex client instance to communicate with cortex API server
cortex: Cortex;
serverConfigs: { host: string; port: number };

constructor(readonly cortexUseCases: CortexUsecases) {
super();
// No need to inject services, since there is no nested dependencies
const fileManagerService: FileManagerService = new FileManagerService();
this.serverConfigs = fileManagerService.getServerConfig();

// Instantiate cortex client, it will be use throughout the command
this.cortex = new Cortex({
apiKey: cortexNamespace,
baseURL: cortexServerAPI(
this.serverConfigs.host,
this.serverConfigs.port,
),
timeout: 20 * 1000,
});
}
protected abstract runCommand(
passedParam: string[],
Expand Down
Loading
Loading