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

Commit d870261

Browse files
committed
API: added the endpoint responses
1 parent 0a2b3f4 commit d870261

File tree

7 files changed

+259
-12
lines changed

7 files changed

+259
-12
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class AssistantsController {
2020
description: 'Creates a new assistant.',
2121
})
2222
@ApiCreatedResponse({
23-
description: 'Assistant created successfully.',
23+
description: 'The assistant has been successfully created.',
2424
})
2525
@Post()
2626
create(@Body() createAssistantDto: CreateAssistantDto) {
@@ -32,7 +32,7 @@ export class AssistantsController {
3232
description: 'Retrieves all the available assistants along with their settings.',
3333
})
3434
@ApiOkResponse({
35-
description: 'Return an array of assistants',
35+
description: 'Ok',
3636
type: [AssistantEntity],
3737
})
3838
@Get()
@@ -45,7 +45,7 @@ export class AssistantsController {
4545
description: "Retrieves a specific assistant defined by an assistant's `id`.",
4646
})
4747
@ApiOkResponse({
48-
description: 'Return an assistant object',
48+
description: 'Ok',
4949
type: AssistantEntity,
5050
})
5151
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." })
@@ -59,7 +59,7 @@ export class AssistantsController {
5959
description: "Deletes a specific assistant defined by an assistant's `id`.",
6060
})
6161
@ApiOkResponse({
62-
description: 'Successfully deleted the assistant.',
62+
description: 'The assistant has been successfully deleted.',
6363
})
6464
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the assistant." })
6565
@Delete(':id')

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Body, Controller, Post, Headers, Res } from '@nestjs/common';
1+
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';
@@ -8,8 +8,13 @@ import {
88
ApiOperation,
99
ApiTags,
1010
getSchemaPath,
11+
ApiResponse
1112
} from '@nestjs/swagger';
1213
import { ChatStreamEvent } from '@/domain/abstracts/oai.abstract';
14+
import {
15+
ChatCompletionChunkedResponse,
16+
ChatCompletionResponse,
17+
} from '../dtos/chat/chat-completion-response.dto';
1318

1419
@ApiTags('Inference')
1520
@Controller('chat')
@@ -21,6 +26,12 @@ export class ChatController {
2126
description:
2227
"Creates a model response for the given chat conversation. The API limits stop words to a maximum of 4. If more are specified, only the first four will be accepted. [Equivalent to OpenAI's create chat completion](https://platform.openai.com/docs/api-reference/chat/create).",
2328
})
29+
@HttpCode(200)
30+
@ApiResponse({
31+
status: 200,
32+
description: 'Ok',
33+
type: ChatCompletionChunkedResponse,
34+
})
2435
@Post('completions')
2536
async create(
2637
@Headers() headers: Record<string, string>,

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {
1111
import { ModelsUsecases } from '@/usecases/models/models.usecases';
1212
import { CreateModelDto } from '@/infrastructure/dtos/models/create-model.dto';
1313
import { UpdateModelDto } from '@/infrastructure/dtos/models/update-model.dto';
14+
import { ModelDto } from '@/infrastructure/dtos/models/model-successfully-created.dto';
15+
import { ListModelsResponseDto } from '@/infrastructure/dtos/models/list-model-response.dto';
16+
import { DeleteModelResponseDto } from '@/infrastructure/dtos/models/delete-model.dto';
1417
import {
1518
ApiCreatedResponse,
1619
ApiOkResponse,
@@ -28,11 +31,6 @@ export class ModelsController {
2831
constructor(private readonly modelsUsecases: ModelsUsecases) {}
2932

3033
@ApiOperation({ summary: 'Create model', description: "Creates a model `.json` instance file manually." })
31-
@HttpCode(200)
32-
@ApiResponse({
33-
status: 200,
34-
description: 'The model has been successfully created.'
35-
})
3634
@Post()
3735
create(@Body() createModelDto: CreateModelDto) {
3836
return this.modelsUsecases.create(createModelDto);
@@ -74,12 +72,24 @@ export class ModelsController {
7472
return this.modelsUsecases.downloadModel(modelId);
7573
}
7674

75+
@HttpCode(200)
76+
@ApiResponse({
77+
status: 200,
78+
description: 'Ok',
79+
type: ListModelsResponseDto,
80+
})
7781
@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)." })
7882
@Get()
7983
findAll() {
8084
return this.modelsUsecases.findAll();
8185
}
8286

87+
@HttpCode(200)
88+
@ApiResponse({
89+
status: 200,
90+
description: 'Ok',
91+
type: ModelDto,
92+
})
8393
@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)." })
8494
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the model." })
8595
@Get(':id')
@@ -93,7 +103,7 @@ export class ModelsController {
93103
description: 'The model has been successfully updated.',
94104
type: UpdateModelDto,
95105
})
96-
@ApiOperation({ summary: 'Update model', description: "Updates a model instance defined by a mode;'s `id`." })
106+
@ApiOperation({ summary: 'Update model', description: "Updates a model instance defined by a model's `id`." })
97107
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the model." })
98108
@Patch(':id')
99109
update(@Param('id') id: string, @Body() updateModelDto: UpdateModelDto) {
@@ -102,7 +112,8 @@ export class ModelsController {
102112

103113
@ApiResponse({
104114
status: 200,
105-
description: 'The model has been successfully deleted.'
115+
description: 'The model has been successfully deleted.',
116+
type: DeleteModelResponseDto,
106117
})
107118
@ApiOperation({ summary: 'Delete model', description: "Deletes a model. [Equivalent to OpenAI's delete model](https://platform.openai.com/docs/api-reference/models/delete)." })
108119
@ApiParam({ name: 'id', required: true, description: "The unique identifier of the model." })
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
3+
class Usage {
4+
@ApiProperty({
5+
type: Number,
6+
description: 'Number of tokens in the generated completion.',
7+
})
8+
completion_tokens: number;
9+
10+
@ApiProperty({ type: Number, description: 'Number of tokens in the prompt.' })
11+
prompt_tokens: number;
12+
13+
@ApiProperty({
14+
type: Number,
15+
description:
16+
'Total number of tokens used in the request (prompt + completion).',
17+
})
18+
total_tokens: number;
19+
}
20+
21+
class Choice {
22+
@ApiProperty({ type: String, description: 'The text of the completion.' })
23+
text: string;
24+
25+
@ApiProperty({ type: Number, description: 'Index of the choice.' })
26+
index: number;
27+
28+
@ApiProperty({
29+
type: String,
30+
description: 'Reason for finishing the completion.',
31+
})
32+
finish_reason: string;
33+
}
34+
35+
export class ChatCompletionResponse {
36+
@ApiProperty({
37+
type: String,
38+
description: 'A unique identifier for the chat completion.',
39+
})
40+
id: string;
41+
42+
@ApiProperty({
43+
type: [Choice],
44+
description: 'A list of chat completion choices.',
45+
})
46+
choices: Choice[];
47+
48+
@ApiProperty({
49+
type: Number,
50+
description:
51+
'The Unix timestamp (in seconds) of when the chat completion was created.',
52+
})
53+
created: number;
54+
55+
@ApiProperty({
56+
type: String,
57+
description: 'The model used for the chat completion.',
58+
})
59+
model: string;
60+
61+
@ApiProperty({
62+
type: String,
63+
description:
64+
'The system fingerprint representing the backend configuration.',
65+
})
66+
system_fingerprint: string;
67+
68+
@ApiProperty({
69+
type: String,
70+
description: 'The object type, which is always chat.completion.',
71+
})
72+
object: string;
73+
74+
@ApiProperty({
75+
type: Usage,
76+
description: 'Usage statistics for the completion request.',
77+
})
78+
usage: Usage;
79+
}
80+
81+
export class ChatCompletionChunkedResponse {
82+
@ApiProperty({
83+
type: String,
84+
description:
85+
'A unique identifier for the chat completion. Each chunk has the same ID.',
86+
})
87+
id: string;
88+
89+
@ApiProperty({
90+
type: [Choice],
91+
description: 'A list of chat completion choices.',
92+
})
93+
choices: Choice[];
94+
95+
@ApiProperty({
96+
type: Number,
97+
description:
98+
'The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp.',
99+
})
100+
created: number;
101+
102+
@ApiProperty({
103+
type: String,
104+
description: 'The model used to generate the completion.',
105+
})
106+
model: string;
107+
108+
@ApiProperty({
109+
type: String,
110+
description:
111+
'The system fingerprint representing the backend configuration.',
112+
})
113+
system_fingerprint: string;
114+
115+
@ApiProperty({
116+
type: String,
117+
description: 'The object type, which is always chat.completion.chunk.',
118+
})
119+
object: string;
120+
121+
@ApiProperty({
122+
type: Usage,
123+
required: false,
124+
description: 'Usage statistics for the completion request.',
125+
})
126+
usage?: Usage;
127+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
3+
export class DeleteModelResponseDto {
4+
@ApiProperty({
5+
example: 'mistral-ins-7b-q4',
6+
description: 'The identifier of the model that was deleted.'
7+
})
8+
id: string;
9+
10+
@ApiProperty({
11+
example: 'model',
12+
description: 'Type of the object, indicating it\'s a model.',
13+
default: 'model'
14+
})
15+
object: string;
16+
17+
@ApiProperty({
18+
example: true,
19+
description: 'Indicates whether the model was successfully deleted.'
20+
})
21+
deleted: boolean;
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { ModelDto } from './model-successfully-created.dto'; // Import the ModelDto class
3+
4+
export class ListModelsResponseDto {
5+
@ApiProperty({ example: 'list', enum: ['list'] })
6+
object: string;
7+
8+
@ApiProperty({ type: [ModelDto], description: 'List of models' })
9+
data: ModelDto[];
10+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
3+
export class ModelDto {
4+
@ApiProperty({ example: 'https://huggingface.co/janhq/trinity-v1.2-GGUF/resolve/main/trinity-v1.2.Q4_K_M.gguf', description: 'URL to the source of the model.' })
5+
source_url: string;
6+
7+
@ApiProperty({ example: 'trinity-v1.2-7b', description: 'Unique identifier used in chat-completions model_name, matches folder name.' })
8+
id: string;
9+
10+
@ApiProperty({ example: 'model' })
11+
object: string;
12+
13+
@ApiProperty({ example: 'Trinity-v1.2 7B Q4', description: 'Name of the model.' })
14+
name: string;
15+
16+
@ApiProperty({ default: '1.0', description: 'The version number of the model.' })
17+
version: string;
18+
19+
@ApiProperty({ example: 'Trinity is an experimental model merge using the Slerp method. Recommended for daily assistance purposes.', description: 'Description of the model.' })
20+
description: string;
21+
22+
@ApiProperty({ example: 'gguf', description: 'State format of the model, distinct from the engine.' })
23+
format: string;
24+
25+
@ApiProperty({ description: 'Context length.', example: 4096 })
26+
ctx_len: number;
27+
28+
@ApiProperty({ example: 'system\n{system_message}\nuser\n{prompt}\nassistant' })
29+
prompt_template: string;
30+
31+
@ApiProperty({ example: 0.7 })
32+
temperature: number;
33+
34+
@ApiProperty({ example: 0.95 })
35+
top_p: number;
36+
37+
@ApiProperty({ example: true })
38+
stream: boolean;
39+
40+
@ApiProperty({ example: 4096 })
41+
max_tokens: number;
42+
43+
@ApiProperty({ type: [String], example: [] })
44+
stop: string[];
45+
46+
@ApiProperty({ example: 0 })
47+
frequency_penalty: number;
48+
49+
@ApiProperty({ example: 0 })
50+
presence_penalty: number;
51+
52+
@ApiProperty({ example: 'Jan' })
53+
author: string;
54+
55+
@ApiProperty({ type: [String], example: ['7B', 'Merged', 'Featured'] })
56+
tags: string[];
57+
58+
@ApiProperty({ example: 4370000000 })
59+
size: number;
60+
61+
@ApiProperty({ example: 'https://raw.githubusercontent.com/janhq/jan/main/models/trinity-v1.2-7b/cover.png' })
62+
cover: string;
63+
64+
@ApiProperty({ example: 'nitro' })
65+
engine: string;
66+
}

0 commit comments

Comments
 (0)