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

Commit 08d6682

Browse files
authored
Merge pull request #591 from janhq/api-update
API: added the API reference decorator
2 parents 4c229d2 + acdf444 commit 08d6682

40 files changed

+11777
-40
lines changed

cortex-js/package-lock.json

Lines changed: 11047 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cortex-js/src/infrastructure/controllers/assistants.controller.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ import {
99
} from '@nestjs/common';
1010
import { AssistantsUsecases } from '@/usecases/assistants/assistants.usecases';
1111
import { CreateAssistantDto } from '@/infrastructure/dtos/assistants/create-assistant.dto';
12-
import { ApiTags } from '@nestjs/swagger';
12+
import { DeleteAssistantResponseDto } from '@/infrastructure/dtos/assistants/delete-assistant.dto';
13+
import {
14+
ApiCreatedResponse,
15+
ApiOkResponse,
16+
ApiOperation,
17+
ApiParam,
18+
ApiTags,
19+
ApiResponse
20+
} from '@nestjs/swagger';
21+
import { AssistantEntity } from '../entities/assistant.entity';
1322
import { TransformInterceptor } from '../interceptors/transform.interceptor';
1423

1524
@ApiTags('Assistants')
@@ -18,21 +27,55 @@ import { TransformInterceptor } from '../interceptors/transform.interceptor';
1827
export class AssistantsController {
1928
constructor(private readonly assistantsService: AssistantsUsecases) {}
2029

30+
@ApiOperation({
31+
summary: 'Create assistant',
32+
description: 'Creates a new assistant.',
33+
})
34+
@ApiCreatedResponse({
35+
description: 'The assistant has been successfully created.',
36+
})
2137
@Post()
2238
create(@Body() createAssistantDto: CreateAssistantDto) {
2339
return this.assistantsService.create(createAssistantDto);
2440
}
2541

42+
@ApiOperation({
43+
summary: 'List assistants',
44+
description: 'Retrieves all the available assistants along with their settings.',
45+
})
46+
@ApiOkResponse({
47+
description: 'Ok',
48+
type: [AssistantEntity],
49+
})
2650
@Get()
2751
findAll() {
2852
return this.assistantsService.findAll();
2953
}
3054

55+
@ApiOperation({
56+
summary: 'Get assistant',
57+
description: "Retrieves a specific assistant defined by an assistant's `id`.",
58+
})
59+
@ApiOkResponse({
60+
description: 'Ok',
61+
type: AssistantEntity,
62+
})
63+
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." })
3164
@Get(':id')
3265
findOne(@Param('id') id: string) {
3366
return this.assistantsService.findOne(id);
3467
}
3568

69+
@ApiOperation({
70+
summary: 'Delete assistant',
71+
description: "Deletes a specific assistant defined by an assistant's `id`.",
72+
})
73+
@ApiResponse({
74+
status: 200,
75+
description: 'The assistant has been successfully deleted.',
76+
type: DeleteAssistantResponseDto,
77+
})
78+
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." })
3679
@Delete(':id')
3780
remove(@Param('id') id: string) {
3881
return this.assistantsService.remove(id);

cortex-js/src/infrastructure/controllers/chat.controller.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ import { Body, Controller, Post, Headers, Res, HttpCode } from '@nestjs/common';
22
import { CreateChatCompletionDto } from '@/infrastructure/dtos/chat/create-chat-completion.dto';
33
import { ChatUsecases } from '@/usecases/chat/chat.usecases';
44
import { Response } from 'express';
5-
import { ApiResponse, ApiTags } from '@nestjs/swagger';
5+
import {
6+
ApiCreatedResponse,
7+
ApiExtraModels,
8+
ApiOperation,
9+
ApiTags,
10+
getSchemaPath,
11+
ApiResponse
12+
} from '@nestjs/swagger';
613
import { ChatCompletionResponseDto } from '../dtos/chat/chat-completion-response.dto';
714

815
@ApiTags('Inference')
@@ -13,7 +20,7 @@ export class ChatController {
1320
@HttpCode(200)
1421
@ApiResponse({
1522
status: 200,
16-
description: 'Chat completion response successfully',
23+
description: 'Ok',
1724
type: ChatCompletionResponseDto,
1825
})
1926
@Post('completions')

cortex-js/src/infrastructure/controllers/cortex.controller.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Body, Controller, HttpCode, Post } from '@nestjs/common';
2-
import { ApiResponse, ApiTags } from '@nestjs/swagger';
2+
import { ApiResponse, ApiTags, ApiOperation } from '@nestjs/swagger';
33
import { StartCortexDto } from '@/infrastructure/dtos/cortex/start-cortex.dto';
44
import { CortexOperationSuccessfullyDto } from '../dtos/cortex/cortex-operation-successfully.dto';
55
import { CortexUsecases } from '@/usecases/cortex/cortex.usecases';
@@ -15,6 +15,10 @@ export class CortexController {
1515
description: 'Start Cortex successfully',
1616
type: CortexOperationSuccessfullyDto,
1717
})
18+
@ApiOperation({
19+
summary: 'Start cortex',
20+
description: 'Starts the cortex operation.',
21+
})
1822
@Post('start')
1923
startCortex(@Body() startCortexDto: StartCortexDto) {
2024
return this.cortexUsecases.startCortex(
@@ -29,6 +33,10 @@ export class CortexController {
2933
description: 'Stop Cortex successfully',
3034
type: CortexOperationSuccessfullyDto,
3135
})
36+
@ApiOperation({
37+
summary: 'Stop cortex',
38+
description: 'Stops the cortex operation.',
39+
})
3240
@Post('stop')
3341
stopCortex() {
3442
return this.cortexUsecases.stopCortex();

cortex-js/src/infrastructure/controllers/messages.controller.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ import {
55
Body,
66
Patch,
77
Param,
8+
HttpCode,
89
Delete,
910
UseInterceptors,
1011
} from '@nestjs/common';
1112
import { MessagesUsecases } from '@/usecases/messages/messages.usecases';
1213
import { CreateMessageDto } from '@/infrastructure/dtos/messages/create-message.dto';
1314
import { UpdateMessageDto } from '@/infrastructure/dtos/messages/update-message.dto';
14-
import { ApiTags } from '@nestjs/swagger';
15+
import { ListMessagesResponseDto } from '@/infrastructure/dtos/messages/list-message.dto';
16+
import { GetMessageResponseDto } from '@/infrastructure/dtos/messages/get-message.dto';
17+
import { DeleteMessageResponseDto } from '@/infrastructure/dtos/messages/delete-message.dto';
18+
import {
19+
ApiCreatedResponse,
20+
ApiOkResponse,
21+
ApiOperation,
22+
ApiParam,
23+
ApiTags,
24+
ApiResponse
25+
} from '@nestjs/swagger';
1526
import { TransformInterceptor } from '../interceptors/transform.interceptor';
1627

1728
@ApiTags('Messages')
@@ -20,26 +31,64 @@ import { TransformInterceptor } from '../interceptors/transform.interceptor';
2031
export class MessagesController {
2132
constructor(private readonly messagesUsecases: MessagesUsecases) {}
2233

34+
@HttpCode(201)
35+
@ApiResponse({
36+
status: 201,
37+
description: 'The message has been successfully created.',
38+
type: CreateMessageDto,
39+
})
40+
@ApiOperation({ summary: 'Create message', description: "Creates a message in a thread." })
2341
@Post()
2442
create(@Body() createMessageDto: CreateMessageDto) {
2543
return this.messagesUsecases.create(createMessageDto);
2644
}
2745

46+
@HttpCode(200)
47+
@ApiResponse({
48+
status: 200,
49+
description: 'Ok',
50+
type: ListMessagesResponseDto,
51+
})
52+
@ApiOperation({ summary: 'List messages', description: "Retrieves all the messages in a thread." })
2853
@Get()
2954
findAll() {
3055
return this.messagesUsecases.findAll();
3156
}
3257

58+
@HttpCode(200)
59+
@ApiResponse({
60+
status: 200,
61+
description: 'Ok',
62+
type: GetMessageResponseDto,
63+
})
64+
@ApiOperation({ summary: 'Retrieve message', description: "Retrieves a specific message defined by a message's `id`." })
65+
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." })
3366
@Get(':id')
3467
findOne(@Param('id') id: string) {
3568
return this.messagesUsecases.findOne(id);
3669
}
3770

71+
@HttpCode(200)
72+
@ApiResponse({
73+
status: 200,
74+
description: 'The message has been successfully updated.',
75+
type: UpdateMessageDto,
76+
})
77+
@ApiOperation({ summary: 'Update message', description: "Updates a specific message defined by a message's `id`." })
78+
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." })
3879
@Patch(':id')
3980
update(@Param('id') id: string, @Body() updateMessageDto: UpdateMessageDto) {
4081
return this.messagesUsecases.update(id, updateMessageDto);
4182
}
4283

84+
@HttpCode(200)
85+
@ApiResponse({
86+
status: 200,
87+
description: 'Successfully deleted the message.',
88+
type: DeleteMessageResponseDto,
89+
})
90+
@ApiOperation({ summary: 'Delete message', description: "Deletes a specific message defined by a message's `id`." })
91+
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the message." })
4392
@Delete(':id')
4493
remove(@Param('id') id: string) {
4594
return this.messagesUsecases.remove(id);

cortex-js/src/infrastructure/controllers/models.controller.ts

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ import {
1212
import { ModelsUsecases } from '@/usecases/models/models.usecases';
1313
import { CreateModelDto } from '@/infrastructure/dtos/models/create-model.dto';
1414
import { UpdateModelDto } from '@/infrastructure/dtos/models/update-model.dto';
15-
import { ApiResponse, ApiTags } from '@nestjs/swagger';
15+
import { ModelDto } from '@/infrastructure/dtos/models/model-successfully-created.dto';
16+
import { ListModelsResponseDto } from '@/infrastructure/dtos/models/list-model-response.dto';
17+
import { DeleteModelResponseDto } from '@/infrastructure/dtos/models/delete-model.dto';
18+
import { DownloadModelResponseDto } from '@/infrastructure/dtos/models/download-model.dto';
19+
import {
20+
ApiCreatedResponse,
21+
ApiOkResponse,
22+
ApiOperation,
23+
ApiParam,
24+
ApiTags,
25+
ApiResponse
26+
} from '@nestjs/swagger';
1627
import { StartModelSuccessDto } from '@/infrastructure/dtos/models/start-model-success.dto';
1728
import { ModelSettingParamsDto } from '../dtos/models/model-setting-params.dto';
1829
import { TransformInterceptor } from '../interceptors/transform.interceptor';
@@ -23,6 +34,13 @@ import { TransformInterceptor } from '../interceptors/transform.interceptor';
2334
export class ModelsController {
2435
constructor(private readonly modelsUsecases: ModelsUsecases) {}
2536

37+
@HttpCode(201)
38+
@ApiResponse({
39+
status: 201,
40+
description: 'The model has been successfully created.',
41+
type: StartModelSuccessDto,
42+
})
43+
@ApiOperation({ summary: 'Create model', description: "Creates a model `.json` instance file manually." })
2644
@Post()
2745
create(@Body() createModelDto: CreateModelDto) {
2846
return this.modelsUsecases.create(createModelDto);
@@ -31,9 +49,11 @@ export class ModelsController {
3149
@HttpCode(200)
3250
@ApiResponse({
3351
status: 200,
34-
description: 'The model has been started successfully.',
52+
description: 'The model has been successfully started.',
3553
type: StartModelSuccessDto,
3654
})
55+
@ApiOperation({ summary: 'Start model', description: "Starts a model operation defined by a model `id`." })
56+
@ApiParam({ name: 'modelId', required: true, description: "The unique identifier of the model." })
3757
@Post(':modelId/start')
3858
startModel(
3959
@Param('modelId') modelId: string,
@@ -45,34 +65,74 @@ export class ModelsController {
4565
@HttpCode(200)
4666
@ApiResponse({
4767
status: 200,
48-
description: 'The model has been stopped successfully.',
68+
description: 'The model has been successfully stopped.',
4969
type: StartModelSuccessDto,
5070
})
71+
@ApiOperation({ summary: 'Stop model', description: "Stops a model operation defined by a model `id`." })
72+
@ApiParam({ name: 'modelId', required: true, description: "The unique identifier of the model." })
5173
@Post(':modelId/stop')
5274
stopModel(@Param('modelId') modelId: string) {
5375
return this.modelsUsecases.stopModel(modelId);
5476
}
5577

78+
@HttpCode(200)
79+
@ApiResponse({
80+
status: 200,
81+
description: 'Ok',
82+
type: DownloadModelResponseDto,
83+
})
84+
@ApiOperation({ summary: 'Download model', description: "Downloads a specific model instance." })
85+
@ApiParam({ name: 'modelId', required: true, description: "The unique identifier of the model." })
5686
@Get('download/:modelId')
5787
downloadModel(@Param('modelId') modelId: string) {
5888
return this.modelsUsecases.downloadModel(modelId);
5989
}
6090

91+
@HttpCode(200)
92+
@ApiResponse({
93+
status: 200,
94+
description: 'Ok',
95+
type: ListModelsResponseDto,
96+
})
97+
@ApiOperation({ summary: 'List models', description: "Lists the currently available models, and provides basic information about each one such as the owner and availability. [Equivalent to OpenAI's list model](https://platform.openai.com/docs/api-reference/models/list)." })
6198
@Get()
6299
findAll() {
63100
return this.modelsUsecases.findAll();
64101
}
65102

103+
@HttpCode(200)
104+
@ApiResponse({
105+
status: 200,
106+
description: 'Ok',
107+
type: ModelDto,
108+
})
109+
@ApiOperation({ summary: 'Get model', description: "Retrieves a model instance, providing basic information about the model such as the owner and permissions. [Equivalent to OpenAI's list model](https://platform.openai.com/docs/api-reference/models/retrieve)." })
110+
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the model." })
66111
@Get(':id')
67112
findOne(@Param('id') id: string) {
68113
return this.modelsUsecases.findOne(id);
69114
}
70115

116+
@HttpCode(200)
117+
@ApiResponse({
118+
status: 200,
119+
description: 'The model has been successfully updated.',
120+
type: UpdateModelDto,
121+
})
122+
@ApiOperation({ summary: 'Update model', description: "Updates a model instance defined by a model's `id`." })
123+
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the model." })
71124
@Patch(':id')
72125
update(@Param('id') id: string, @Body() updateModelDto: UpdateModelDto) {
73126
return this.modelsUsecases.update(id, updateModelDto);
74127
}
75128

129+
@ApiResponse({
130+
status: 200,
131+
description: 'The model has been successfully deleted.',
132+
type: DeleteModelResponseDto,
133+
})
134+
@ApiOperation({ summary: 'Delete model', description: "Deletes a model. [Equivalent to OpenAI's delete model](https://platform.openai.com/docs/api-reference/models/delete)." })
135+
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the model." })
76136
@Delete(':id')
77137
remove(@Param('id') id: string) {
78138
return this.modelsUsecases.remove(id);

0 commit comments

Comments
 (0)