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

Commit aaa639a

Browse files
committed
update
Signed-off-by: James <namnh0122@gmail.com>
1 parent 0459e08 commit aaa639a

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,21 @@ export class ModelsController {
196196
@ApiOperation({
197197
summary: 'Update model',
198198
description: "Updates a model instance defined by a model's `id`.",
199+
parameters: [
200+
{
201+
in: 'path',
202+
name: 'model',
203+
required: true,
204+
description: 'The unique identifier of the model.',
205+
},
206+
],
199207
})
200-
@ApiParam({
201-
name: 'id',
202-
required: true,
203-
description: 'The unique identifier of the model.',
204-
})
205-
@Patch(':id(*)')
206-
update(@Param('id') id: string, @Body() updateModelDto: UpdateModelDto) {
207-
return this.modelsUsecases.update(id, updateModelDto);
208+
@Post(':model(*)/config')
209+
async update(
210+
@Param('model') model: string,
211+
@Body() updateModelDto: UpdateModelDto,
212+
) {
213+
return this.modelsUsecases.update(model, updateModelDto);
208214
}
209215

210216
@ApiResponse({
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { HttpException, HttpStatus } from '@nestjs/common';
2+
3+
export class DuplicateAssistantException extends HttpException {
4+
constructor(assistantId: string) {
5+
super(
6+
`Assistant with the id ${assistantId} is already exists.`,
7+
HttpStatus.CONFLICT,
8+
);
9+
}
10+
}

cortex-js/src/usecases/assistants/assistants.usecases.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Inject, Injectable } from '@nestjs/common';
22
import { AssistantEntity } from '@/infrastructure/entities/assistant.entity';
3-
import { Repository } from 'typeorm';
3+
import { QueryFailedError, Repository } from 'typeorm';
44
import { CreateAssistantDto } from '@/infrastructure/dtos/assistants/create-assistant.dto';
55
import { Assistant } from '@/domain/models/assistant.interface';
66
import { PageDto } from '@/infrastructure/dtos/page.dto';
77
import { ModelRepository } from '@/domain/repositories/model.interface';
88
import { ModelNotFoundException } from '@/infrastructure/exception/model-not-found.exception';
9+
import { DuplicateAssistantException } from '@/infrastructure/exception/duplicate-assistant.exception';
910

1011
@Injectable()
1112
export class AssistantsUsecases {
@@ -16,7 +17,7 @@ export class AssistantsUsecases {
1617
) {}
1718

1819
async create(createAssistantDto: CreateAssistantDto) {
19-
const { top_p, temperature, model } = createAssistantDto;
20+
const { top_p, temperature, model, id } = createAssistantDto;
2021
if (model !== '*') {
2122
const modelEntity = await this.modelRepository.findOne(model);
2223
if (!modelEntity) {
@@ -33,7 +34,18 @@ export class AssistantsUsecases {
3334
top_p: top_p ?? null,
3435
temperature: temperature ?? null,
3536
};
36-
await this.assistantRepository.insert(assistant);
37+
38+
try {
39+
await this.assistantRepository.insert(assistant);
40+
} catch (err) {
41+
if (err instanceof QueryFailedError) {
42+
if (err.driverError.code === 'SQLITE_CONSTRAINT')
43+
throw new DuplicateAssistantException(id);
44+
}
45+
46+
throw err;
47+
}
48+
3749
return this.findOne(assistant.id);
3850
}
3951

0 commit comments

Comments
 (0)