Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
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
5 changes: 4 additions & 1 deletion cortex-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"@/(.*)$": "<rootDir>/$1"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AssistantsController } from './assistants.controller';
import { AssistantsUsecases } from '@/usecases/assistants/assistants.usecases';
import { DatabaseModule } from '../database/database.module';

describe('AssistantsController', () => {
let controller: AssistantsController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [DatabaseModule],
controllers: [AssistantsController],
providers: [AssistantsUsecases],
exports: [AssistantsUsecases],
}).compile();

controller = module.get<AssistantsController>(AssistantsController);
Expand Down
20 changes: 15 additions & 5 deletions cortex-js/src/infrastructure/controllers/assistants.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ApiOperation,
ApiParam,
ApiTags,
ApiResponse
ApiResponse,
} from '@nestjs/swagger';
import { AssistantEntity } from '../entities/assistant.entity';
import { TransformInterceptor } from '../interceptors/transform.interceptor';
Expand All @@ -41,7 +41,8 @@ export class AssistantsController {

@ApiOperation({
summary: 'List assistants',
description: 'Retrieves all the available assistants along with their settings.',
description:
'Retrieves all the available assistants along with their settings.',
})
@ApiOkResponse({
description: 'Ok',
Expand All @@ -54,13 +55,18 @@ export class AssistantsController {

@ApiOperation({
summary: 'Get assistant',
description: "Retrieves a specific assistant defined by an assistant's `id`.",
description:
"Retrieves a specific assistant defined by an assistant's `id`.",
})
@ApiOkResponse({
description: 'Ok',
type: AssistantEntity,
})
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." })
@ApiParam({
name: 'id',
required: true,
description: 'The unique identifier of the assistant.',
})
@Get(':id')
findOne(@Param('id') id: string) {
return this.assistantsService.findOne(id);
Expand All @@ -75,7 +81,11 @@ export class AssistantsController {
description: 'The assistant has been successfully deleted.',
type: DeleteAssistantResponseDto,
})
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." })
@ApiParam({
name: 'id',
required: true,
description: 'The unique identifier of the assistant.',
})
@Delete(':id')
remove(@Param('id') id: string) {
return this.assistantsService.remove(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ChatController } from './chat.controller';
import { ChatUsecases } from '@/usecases/chat/chat.usecases';
import { DatabaseModule } from '../database/database.module';
import { ExtensionModule } from '../repositories/extensions/extension.module';

describe('ChatController', () => {
let controller: ChatController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [DatabaseModule, ExtensionModule],
controllers: [ChatController],
providers: [ChatUsecases],
}).compile();

controller = module.get<ChatController>(ChatController);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Test, TestingModule } from '@nestjs/testing';
import { MessagesController } from './messages.controller';
import { MessagesUsecases } from '@/usecases/messages/messages.usecases';
import { DatabaseModule } from '../database/database.module';

describe('MessagesController', () => {
let controller: MessagesController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [DatabaseModule],
controllers: [MessagesController],
providers: [MessagesUsecases],
exports: [MessagesUsecases],
}).compile();

controller = module.get<MessagesController>(MessagesController);
Expand Down
52 changes: 36 additions & 16 deletions cortex-js/src/infrastructure/controllers/messages.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ import { UpdateMessageDto } from '@/infrastructure/dtos/messages/update-message.
import { ListMessagesResponseDto } from '@/infrastructure/dtos/messages/list-message.dto';
import { GetMessageResponseDto } from '@/infrastructure/dtos/messages/get-message.dto';
import { DeleteMessageResponseDto } from '@/infrastructure/dtos/messages/delete-message.dto';
import {
ApiCreatedResponse,
ApiOkResponse,
ApiOperation,
ApiParam,
ApiTags,
ApiResponse
} from '@nestjs/swagger';
import { ApiOperation, ApiParam, ApiTags, ApiResponse } from '@nestjs/swagger';
import { TransformInterceptor } from '../interceptors/transform.interceptor';

@ApiTags('Messages')
Expand All @@ -37,7 +30,10 @@ export class MessagesController {
description: 'The message has been successfully created.',
type: CreateMessageDto,
})
@ApiOperation({ summary: 'Create message', description: "Creates a message in a thread." })
@ApiOperation({
summary: 'Create message',
description: 'Creates a message in a thread.',
})
@Post()
create(@Body() createMessageDto: CreateMessageDto) {
return this.messagesUsecases.create(createMessageDto);
Expand All @@ -49,7 +45,10 @@ export class MessagesController {
description: 'Ok',
type: ListMessagesResponseDto,
})
@ApiOperation({ summary: 'List messages', description: "Retrieves all the messages in a thread." })
@ApiOperation({
summary: 'List messages',
description: 'Retrieves all the messages in a thread.',
})
@Get()
findAll() {
return this.messagesUsecases.findAll();
Expand All @@ -61,8 +60,15 @@ export class MessagesController {
description: 'Ok',
type: GetMessageResponseDto,
})
@ApiOperation({ summary: 'Retrieve message', description: "Retrieves a specific message defined by a message's `id`." })
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." })
@ApiOperation({
summary: 'Retrieve message',
description: "Retrieves a specific message defined by a message's `id`.",
})
@ApiParam({
name: 'id',
required: true,
description: 'The unique identifier of the message.',
})
@Get(':id')
findOne(@Param('id') id: string) {
return this.messagesUsecases.findOne(id);
Expand All @@ -74,8 +80,15 @@ export class MessagesController {
description: 'The message has been successfully updated.',
type: UpdateMessageDto,
})
@ApiOperation({ summary: 'Update message', description: "Updates a specific message defined by a message's `id`." })
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." })
@ApiOperation({
summary: 'Update message',
description: "Updates a specific message defined by a message's `id`.",
})
@ApiParam({
name: 'id',
required: true,
description: 'The unique identifier of the message.',
})
@Patch(':id')
update(@Param('id') id: string, @Body() updateMessageDto: UpdateMessageDto) {
return this.messagesUsecases.update(id, updateMessageDto);
Expand All @@ -87,8 +100,15 @@ export class MessagesController {
description: 'Successfully deleted the message.',
type: DeleteMessageResponseDto,
})
@ApiOperation({ summary: 'Delete message', description: "Deletes a specific message defined by a message's `id`." })
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." })
@ApiOperation({
summary: 'Delete message',
description: "Deletes a specific message defined by a message's `id`.",
})
@ApiParam({
name: 'id',
required: true,
description: 'The unique identifier of the message.',
})
@Delete(':id')
remove(@Param('id') id: string) {
return this.messagesUsecases.remove(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ModelsController } from './models.controller';
import { ModelsUsecases } from '@/usecases/models/models.usecases';
import { DatabaseModule } from '../database/database.module';
import { ExtensionModule } from '../repositories/extensions/extension.module';
import { FileManagerModule } from '@/file-manager/file-manager.module';
import { HttpModule } from '@nestjs/axios';
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';

describe('ModelsController', () => {
let controller: ModelsController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [DatabaseModule, ExtensionModule, FileManagerModule, HttpModule],
controllers: [ModelsController],
providers: [ModelsUsecases],
providers: [ModelsUsecases, CortexUsecases],
exports: [ModelsUsecases],
}).compile();

controller = module.get<ModelsController>(ModelsController);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ThreadsController } from './threads.controller';
import { ThreadsUsecases } from '@/usecases/threads/threads.usecases';
import { DatabaseModule } from '../database/database.module';

describe('ThreadsController', () => {
let controller: ThreadsController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [DatabaseModule],
controllers: [ThreadsController],
providers: [ThreadsUsecases],
}).compile();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileManagerService } from '@/file-manager/file-manager.service';
import { databaseFile } from 'constant';
import { databaseFile } from '@/../constant';
import { join } from 'path';
import { DataSource } from 'typeorm';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,50 @@ export class CreateChatCompletionDto {
@IsString()
model: string;

@ApiProperty({description: "Determines the format for output generation. If set to `true`, the output is generated continuously, allowing for real-time streaming of responses. If set to `false`, the output is delivered in a single JSON file."})
@ApiProperty({
description:
'Determines the format for output generation. If set to `true`, the output is generated continuously, allowing for real-time streaming of responses. If set to `false`, the output is delivered in a single JSON file.',
})
@IsBoolean()
stream: boolean;

@ApiProperty({description: "Sets the upper limit on the number of tokens the model can generate in a single output."})
@ApiProperty({
description:
'Sets the upper limit on the number of tokens the model can generate in a single output.',
})
@IsNumber()
max_tokens: number;

@ApiProperty({description: "Defines specific tokens or phrases that signal the model to stop producing further output."})
@ApiProperty({
description:
'Defines specific tokens or phrases that signal the model to stop producing further output.',
})
@IsArray()
stop: string[];

@ApiProperty({description: "Modifies the likelihood of the model repeating the same words or phrases within a single output."})
@ApiProperty({
description:
'Modifies the likelihood of the model repeating the same words or phrases within a single output.',
})
@IsNumber()
frequency_penalty: number;

@ApiProperty({description: "Reduces the likelihood of repeating tokens, promoting novelty in the output."})
@ApiProperty({
description:
'Reduces the likelihood of repeating tokens, promoting novelty in the output.',
})
@IsNumber()
presence_penalty: number;

@ApiProperty({description: "Influences the randomness of the model's output."})
@ApiProperty({
description: "Influences the randomness of the model's output.",
})
@IsNumber()
temperature: number;

@ApiProperty({description: "Sets probability threshold for more relevant outputs."})
@ApiProperty({
description: 'Sets probability threshold for more relevant outputs.',
})
@IsNumber()
top_p: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PromptTemplate } from '@/domain/models/prompt-template.interface';
import { join } from 'path';
import { Model, ModelSettingParams } from '@/domain/models/model.interface';
import { HttpService } from '@nestjs/axios';
import { defaultCortexCppHost, defaultCortexCppPort } from 'constant';
import { defaultCortexCppHost, defaultCortexCppPort } from '@/../constant';
import { readdirSync } from 'node:fs';
import { normalizeModelId } from '@/infrastructure/commanders/utils/normalize-model-id';
import { firstValueFrom } from 'rxjs';
Expand Down
29 changes: 23 additions & 6 deletions cortex-js/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,30 @@ async function bootstrap() {

const config = new DocumentBuilder()
.setTitle('Cortex API')
.setDescription('Cortex API provides a command-line interface (CLI) for seamless interaction with large language models (LLMs). Fully compatible with the [OpenAI API](https://platform.openai.com/docs/api-reference), it enables straightforward command execution and management of LLM interactions.')
.setDescription(
'Cortex API provides a command-line interface (CLI) for seamless interaction with large language models (LLMs). Fully compatible with the [OpenAI API](https://platform.openai.com/docs/api-reference), it enables straightforward command execution and management of LLM interactions.',
)
.setVersion('1.0')
.addTag('Inference', 'This endpoint initiates interaction with a Language Learning Model (LLM).')
.addTag('Assistants', 'These endpoints manage the lifecycle of an Assistant within a conversation thread.')
.addTag('Models', 'These endpoints provide a list and descriptions of all available models within the Cortex framework.')
.addTag('Messages', "These endpoints manage the retrieval and storage of conversation content, including responses from LLMs and other metadata related to chat interactions.")
.addTag('Threads', 'These endpoints handle the creation, retrieval, updating, and deletion of conversation threads.')
.addTag(
'Inference',
'This endpoint initiates interaction with a Language Learning Model (LLM).',
)
.addTag(
'Assistants',
'These endpoints manage the lifecycle of an Assistant within a conversation thread.',
)
.addTag(
'Models',
'These endpoints provide a list and descriptions of all available models within the Cortex framework.',
)
.addTag(
'Messages',
'These endpoints manage the retrieval and storage of conversation content, including responses from LLMs and other metadata related to chat interactions.',
)
.addTag(
'Threads',
'These endpoints handle the creation, retrieval, updating, and deletion of conversation threads.',
)
.addServer('http://localhost:1337')
.addServer('http://localhost:1337/v1')
.build();
Expand Down
3 changes: 3 additions & 0 deletions cortex-js/src/usecases/assistants/assistants.usecases.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AssistantsUsecases } from './assistants.usecases';
import { DatabaseModule } from '@/infrastructure/database/database.module';

describe('AssistantsService', () => {
let service: AssistantsUsecases;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [DatabaseModule],
exports: [AssistantsUsecases],
providers: [AssistantsUsecases],
}).compile();

Expand Down
4 changes: 4 additions & 0 deletions cortex-js/src/usecases/chat/chat.usecases.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ChatUsecases } from './chat.usecases';
import { DatabaseModule } from '@/infrastructure/database/database.module';
import { ExtensionModule } from '@/infrastructure/repositories/extensions/extension.module';

describe('ChatService', () => {
let service: ChatUsecases;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [DatabaseModule, ExtensionModule],
providers: [ChatUsecases],
exports: [ChatUsecases],
}).compile();

service = module.get<ChatUsecases>(ChatUsecases);
Expand Down
Loading