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

chore: group system apis #924

Merged
merged 8 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/cortex.js": "^0.1.2",
"@cortexso/cortex.js": "^0.1.3",
"cpu-instructions": "^0.0.11",
"decompress": "^4.2.1",
"js-yaml": "^4.1.0",
Expand Down
8 changes: 2 additions & 6 deletions cortex-js/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import { TelemetryModule } from './usecases/telemetry/telemetry.module';
import { APP_FILTER } from '@nestjs/core';
import { GlobalExceptionFilter } from './infrastructure/exception/global.exception';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { EventsController } from './infrastructure/controllers/events.controller';
import { AssistantsController } from './infrastructure/controllers/assistants.controller';
import { ChatController } from './infrastructure/controllers/chat.controller';
import { EmbeddingsController } from './infrastructure/controllers/embeddings.controller';
import { ModelsController } from './infrastructure/controllers/models.controller';
import { ThreadsController } from './infrastructure/controllers/threads.controller';
import { StatusController } from './infrastructure/controllers/status.controller';
import { ProcessController } from './infrastructure/controllers/process.controller';
import { SystemController } from './infrastructure/controllers/system.controller';
import { DownloadManagerModule } from './infrastructure/services/download-manager/download-manager.module';
import { ContextModule } from './infrastructure/services/context/context.module';
import { ExtensionsModule } from './extensions/extensions.module';
Expand Down Expand Up @@ -66,9 +64,7 @@ import { ResourceManagerModule } from './infrastructure/services/resources-manag
EmbeddingsController,
ModelsController,
ThreadsController,
StatusController,
ProcessController,
EventsController,
SystemController,
EnginesController,
],
providers: [
Expand Down
6 changes: 3 additions & 3 deletions cortex-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
CORTEX_JS_STOP_API_SERVER_URL,
CORTEX_JS_SYSTEM_URL,
defaultCortexJsHost,
defaultCortexJsPort,
} from '@/infrastructure/constants/cortex';
Expand Down Expand Up @@ -33,8 +33,8 @@ export async function start(host?: string, port?: number) {
* Stop the API server
* @returns
*/
export async function stop() {
return fetch(CORTEX_JS_STOP_API_SERVER_URL(), {
export async function stop(host?: string, port?: number) {
return fetch(CORTEX_JS_SYSTEM_URL(host, port), {
method: 'DELETE',
}).catch(() => {});
}
11 changes: 3 additions & 8 deletions cortex-js/src/infrastructure/constants/cortex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,13 @@ export const CORTEX_CPP_MODELS_URL = (
port: number = defaultCortexCppPort,
) => `http://${host}:${port}/inferences/server/models`;

export const CORTEX_JS_HEALTH_URL = (
export const CORTEX_JS_SYSTEM_URL = (
host: string = defaultCortexJsHost,
port: number = defaultCortexJsPort,
) => `http://${host}:${port}/v1/health`;
) => `http://${host}:${port}/v1/system`;

export const CORTEX_JS_HEALTH_URL_WITH_API_PATH = (apiUrl: string) =>
`${apiUrl}/v1/health`;

export const CORTEX_JS_STOP_API_SERVER_URL = (
host: string = defaultCortexJsHost,
port: number = defaultCortexJsPort,
) => `http://${host}:${port}/v1/process`;
`${apiUrl}/v1/system`;

// INITIALIZATION
export const CORTEX_RELEASES_URL =
Expand Down
17 changes: 0 additions & 17 deletions cortex-js/src/infrastructure/controllers/process.controller.ts

This file was deleted.

22 changes: 0 additions & 22 deletions cortex-js/src/infrastructure/controllers/status.controller.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from '@/domain/models/model.event';
import { DownloadManagerService } from '@/infrastructure/services/download-manager/download-manager.service';
import { ModelsUsecases } from '@/usecases/models/models.usecases';
import { Controller, Sse } from '@nestjs/common';
import { Controller, Delete, Get, HttpCode, Sse } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import {
Observable,
catchError,
Expand All @@ -31,21 +31,44 @@ import {
import { ResourcesManagerService } from '../services/resources-manager/resources-manager.service';
import { ResourceEvent } from '@/domain/models/resource.interface';

@ApiTags('Events')
@Controller('events')
export class EventsController {
@ApiTags('System')
@Controller('system')
export class SystemController {
constructor(
private readonly downloadManagerService: DownloadManagerService,
private readonly modelsUsecases: ModelsUsecases,
private readonly eventEmitter: EventEmitter2,
private readonly resourcesManagerService: ResourcesManagerService,
) {}

@ApiOperation({
summary: 'Terminate api server',
description: 'Terminates the Cortex API endpoint server for the detached mode.',
})
@Delete()
async delete() {
process.exit(0);
}

@ApiOperation({
summary: "Get health status",
description: "Retrieves the health status of your Cortex's system.",
})
@HttpCode(200)
@ApiResponse({
status: 200,
description: 'Ok',
})
@Get()
async get() {
return 'OK';
}

@ApiOperation({
summary: 'Get download status',
description: "Retrieves the model's download status.",
})
@Sse('download')
@Sse('events/download')
downloadEvent(): Observable<DownloadStateEvent> {
const latestDownloadState$: Observable<DownloadStateEvent> = of({
data: this.downloadManagerService.getDownloadStates(),
Expand All @@ -65,7 +88,7 @@ export class EventsController {
summary: 'Get model status',
description: 'Retrieves all the available model statuses within Cortex.',
})
@Sse('model')
@Sse('events/model')
modelEvent(): Observable<ModelStatusAndEvent> {
const latestModelStatus$: Observable<Record<ModelId, ModelStatus>> = of(
this.modelsUsecases.getModelStatuses(),
Expand All @@ -85,7 +108,7 @@ export class EventsController {
summary: 'Get resources status',
description: 'Retrieves the resources status of the system.',
})
@Sse('resources')
@Sse('events/resources')
resourcesEvent(): Observable<ResourceEvent> {
const initialData$ = from(
this.resourcesManagerService.getResourceStatuses(),
Expand Down
9 changes: 4 additions & 5 deletions cortex-js/src/usecases/cortex/cortex.usecases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { FileManagerService } from '@/infrastructure/services/file-manager/file-
import {
CORTEX_CPP_HEALTH_Z_URL,
CORTEX_CPP_PROCESS_DESTROY_URL,
CORTEX_JS_HEALTH_URL,
CORTEX_JS_STOP_API_SERVER_URL,
CORTEX_JS_SYSTEM_URL,
defaultCortexJsHost,
defaultCortexJsPort,
} from '@/infrastructure/constants/cortex';
Expand Down Expand Up @@ -120,7 +119,7 @@ export class CortexUsecases {
* @returns
*/
async stopServe(): Promise<void> {
return fetch(CORTEX_JS_STOP_API_SERVER_URL(), {
return fetch(CORTEX_JS_SYSTEM_URL(), {
method: 'DELETE',
})
.then(() => {})
Expand Down Expand Up @@ -195,7 +194,7 @@ export class CortexUsecases {
const apiServerHost = host || configApiServerHost || defaultCortexJsHost;
const apiServerPort = port || configApiServerPort || defaultCortexJsPort;
return firstValueFrom(
this.httpService.get(CORTEX_JS_HEALTH_URL(apiServerHost, apiServerPort)),
this.httpService.get(CORTEX_JS_SYSTEM_URL(apiServerHost, apiServerPort)),
)
.then((res) => res.status === HttpStatus.OK)
.catch(() => false);
Expand All @@ -211,7 +210,7 @@ export class CortexUsecases {
const apiServerHost = configApiServerHost || defaultCortexJsHost;
const apiServerPort = configApiServerPort || defaultCortexJsPort;
await this.stopCortex();
return fetch(CORTEX_JS_STOP_API_SERVER_URL(apiServerHost, apiServerPort), {
return fetch(CORTEX_JS_SYSTEM_URL(apiServerHost, apiServerPort), {
method: 'DELETE',
}).catch(() => {});
}
Expand Down
Loading