-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
386 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
cortex-js/src/infrastructure/controllers/configs.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { DatabaseModule } from '../database/database.module'; | ||
import { ExtensionModule } from '../repositories/extensions/extension.module'; | ||
import { ModelRepositoryModule } from '../repositories/models/model.module'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module'; | ||
import { EventEmitterModule } from '@nestjs/event-emitter'; | ||
import { TelemetryModule } from '@/usecases/telemetry/telemetry.module'; | ||
import { FileManagerModule } from '../services/file-manager/file-manager.module'; | ||
import { ConfigsController } from './configs.controller'; | ||
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase'; | ||
import { ConfigsModule } from '@/usecases/configs/configs.module'; | ||
|
||
describe('ConfigsController', () => { | ||
let controller: ConfigsController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [ | ||
EventEmitterModule.forRoot(), | ||
DatabaseModule, | ||
ExtensionModule, | ||
ModelRepositoryModule, | ||
HttpModule, | ||
DownloadManagerModule, | ||
EventEmitterModule.forRoot(), | ||
TelemetryModule, | ||
FileManagerModule, | ||
ConfigsModule, | ||
], | ||
controllers: [ConfigsController], | ||
providers: [ConfigsUsecases], | ||
}).compile(); | ||
|
||
controller = module.get<ConfigsController>(ConfigsController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
81 changes: 81 additions & 0 deletions
81
cortex-js/src/infrastructure/controllers/configs.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Post, | ||
Body, | ||
Param, | ||
HttpCode, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { ApiOperation, ApiParam, ApiTags, ApiResponse } from '@nestjs/swagger'; | ||
import { TransformInterceptor } from '../interceptors/transform.interceptor'; | ||
import { ConfigsUsecases } from '@/usecases/configs/configs.usecase'; | ||
import { ConfigUpdateDto } from '../dtos/configs/config-update.dto'; | ||
import { CommonResponseDto } from '../dtos/common/common-response.dto'; | ||
|
||
@ApiTags('Configurations') | ||
@Controller('configs') | ||
@UseInterceptors(TransformInterceptor) | ||
export class ConfigsController { | ||
constructor(private readonly configsUsecases: ConfigsUsecases) {} | ||
|
||
@HttpCode(200) | ||
@ApiResponse({ | ||
status: 200, | ||
description: 'Ok', | ||
type: [Object], | ||
}) | ||
@ApiOperation({ | ||
summary: 'List configs', | ||
description: | ||
'Lists the currently available configs, including the default and user-defined configurations', | ||
}) | ||
@Get() | ||
findAll() { | ||
return this.configsUsecases.getConfigs(); | ||
} | ||
|
||
@HttpCode(200) | ||
@ApiResponse({ | ||
status: 200, | ||
description: 'Ok', | ||
type: Object, | ||
}) | ||
@ApiOperation({ | ||
summary: 'Get a config', | ||
description: | ||
'Retrieves a config instance, providing basic information about the config', | ||
}) | ||
@ApiParam({ | ||
name: 'name', | ||
required: true, | ||
description: 'The unique identifier of the config.', | ||
}) | ||
@Get(':name(*)') | ||
findOne(@Param('name') name: string) { | ||
return this.configsUsecases.getGroupConfigs(name); | ||
} | ||
|
||
@HttpCode(200) | ||
@ApiResponse({ | ||
status: 200, | ||
description: 'The config has been successfully updated.', | ||
type: CommonResponseDto, | ||
}) | ||
@ApiOperation({ | ||
summary: 'Configure a model', | ||
description: "Updates a config by it's group and key", | ||
parameters: [ | ||
{ | ||
in: 'path', | ||
name: 'model', | ||
required: true, | ||
description: 'The unique identifier of the model.', | ||
}, | ||
], | ||
}) | ||
@Post(':name(*)') | ||
async update(@Param('name') name: string, @Body() configs: ConfigUpdateDto) { | ||
return this.configsUsecases.saveConfig(configs.key, configs.value, name); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
cortex-js/src/infrastructure/controllers/engines.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { DatabaseModule } from '../database/database.module'; | ||
import { ExtensionModule } from '../repositories/extensions/extension.module'; | ||
import { ModelRepositoryModule } from '../repositories/models/model.module'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { DownloadManagerModule } from '@/infrastructure/services/download-manager/download-manager.module'; | ||
import { EventEmitterModule } from '@nestjs/event-emitter'; | ||
import { TelemetryModule } from '@/usecases/telemetry/telemetry.module'; | ||
import { FileManagerModule } from '../services/file-manager/file-manager.module'; | ||
import { EnginesController } from './engines.controller'; | ||
import { EnginesUsecases } from '@/usecases/engines/engines.usecase'; | ||
import { EnginesModule } from '@/usecases/engines/engines.module'; | ||
|
||
describe('ConfigsController', () => { | ||
let controller: EnginesController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [ | ||
EventEmitterModule.forRoot(), | ||
DatabaseModule, | ||
ExtensionModule, | ||
ModelRepositoryModule, | ||
HttpModule, | ||
DownloadManagerModule, | ||
EventEmitterModule.forRoot(), | ||
TelemetryModule, | ||
FileManagerModule, | ||
EnginesModule, | ||
], | ||
controllers: [EnginesController], | ||
providers: [EnginesUsecases], | ||
}).compile(); | ||
|
||
controller = module.get<EnginesController>(EnginesController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
55 changes: 55 additions & 0 deletions
55
cortex-js/src/infrastructure/controllers/engines.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Param, | ||
HttpCode, | ||
UseInterceptors, | ||
} from '@nestjs/common'; | ||
import { ApiOperation, ApiParam, ApiTags, ApiResponse } from '@nestjs/swagger'; | ||
import { TransformInterceptor } from '../interceptors/transform.interceptor'; | ||
import { EnginesUsecases } from '@/usecases/engines/engines.usecase'; | ||
import { EngineDto } from '../dtos/engines/engines.dto'; | ||
|
||
@ApiTags('Engines') | ||
@Controller('engines') | ||
@UseInterceptors(TransformInterceptor) | ||
export class EnginesController { | ||
constructor(private readonly enginesUsecases: EnginesUsecases) {} | ||
|
||
@HttpCode(200) | ||
@ApiResponse({ | ||
status: 200, | ||
description: 'Ok', | ||
type: [EngineDto], | ||
}) | ||
@ApiOperation({ | ||
summary: 'List available engines', | ||
description: | ||
'Lists the currently available engines, including local and remote engines', | ||
}) | ||
@Get() | ||
findAll() { | ||
return this.enginesUsecases.getEngines(); | ||
} | ||
|
||
@HttpCode(200) | ||
@ApiResponse({ | ||
status: 200, | ||
description: 'Ok', | ||
type: EngineDto, | ||
}) | ||
@ApiOperation({ | ||
summary: 'Get an engine', | ||
description: | ||
'Retrieves an engine instance, providing basic information about the engine', | ||
}) | ||
@ApiParam({ | ||
name: 'name', | ||
required: true, | ||
description: 'The unique identifier of the engine.', | ||
}) | ||
@Get(':name(*)') | ||
findOne(@Param('name') name: string) { | ||
return this.enginesUsecases.getEngine(name); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
cortex-js/src/infrastructure/dtos/common/common-response.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsString } from 'class-validator'; | ||
|
||
export class CommonResponseDto { | ||
@ApiProperty({ | ||
description: 'The success or error message', | ||
}) | ||
@IsString() | ||
message: string; | ||
} |
31 changes: 31 additions & 0 deletions
31
cortex-js/src/infrastructure/dtos/configs/config-update.dto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsOptional, IsString } from 'class-validator'; | ||
|
||
export class ConfigUpdateDto { | ||
@ApiProperty({ | ||
example: 'apiKey', | ||
description: 'The configuration key.', | ||
}) | ||
@IsString() | ||
@IsOptional() | ||
key: string; | ||
|
||
// Prompt Settings | ||
@ApiProperty({ | ||
type: String, | ||
example: 'sk-xxxxxx', | ||
description: 'The value of the configuration.', | ||
}) | ||
@IsString() | ||
@IsOptional() | ||
value: string; | ||
|
||
@ApiProperty({ | ||
type: String, | ||
example: 'openai', | ||
description: 'The configuration name.', | ||
}) | ||
@IsString() | ||
@IsOptional() | ||
name?: string; | ||
} |
Oops, something went wrong.