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

Commit 473b442

Browse files
committed
chore: update models to extends from openai
Signed-off-by: James <namnh0122@gmail.com>
1 parent cc70f5a commit 473b442

File tree

14 files changed

+149
-251
lines changed

14 files changed

+149
-251
lines changed

cortex-js/src/app.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { ExtensionModule } from './infrastructure/repositories/extensions/extens
1010
import { CortexModule } from './usecases/cortex/cortex.module';
1111
import { ConfigModule } from '@nestjs/config';
1212
import { env } from 'node:process';
13-
import { SeedService } from './usecases/seed/seed.service';
1413
import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module';
1514
import { AppLoggerMiddleware } from './infrastructure/middlewares/app.logger.middleware';
1615
import { TelemetryModule } from './usecases/telemetry/telemetry.module';
@@ -26,6 +25,7 @@ import { ModelsController } from './infrastructure/controllers/models.controller
2625
import { ThreadsController } from './infrastructure/controllers/threads.controller';
2726
import { StatusController } from './infrastructure/controllers/status.controller';
2827
import { ProcessController } from './infrastructure/controllers/process.controller';
28+
import { DownloadManagerModule } from './download-manager/download-manager.module';
2929

3030
@Module({
3131
imports: [
@@ -37,6 +37,7 @@ import { ProcessController } from './infrastructure/controllers/process.controll
3737
envFilePath: env.NODE_ENV !== 'production' ? '.env.development' : '.env',
3838
}),
3939
EventEmitterModule.forRoot(),
40+
DownloadManagerModule,
4041
DatabaseModule,
4142
MessagesModule,
4243
ThreadsModule,
@@ -60,7 +61,6 @@ import { ProcessController } from './infrastructure/controllers/process.controll
6061
EventsController,
6162
],
6263
providers: [
63-
SeedService,
6464
{
6565
provide: APP_FILTER,
6666
useClass: GlobalExceptionFilter,
Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
1-
/**
2-
* Assistant type defines the shape of an assistant object.
3-
* @stored
4-
*/
1+
import { Assistant as OpenAiAssistant } from 'openai/resources/beta/assistants';
2+
import { AssistantResponseFormatOption as OpenAIAssistantResponseFormatOption } from 'openai/resources/beta/threads/threads';
53

6-
export interface AssistantTool {
7-
type: string;
8-
enabled: boolean;
9-
settings: any;
10-
}
4+
export interface Assistant extends OpenAiAssistant {
5+
avatar?: string;
6+
7+
response_format?: AssistantResponseFormatOption;
118

12-
export interface Assistant {
13-
/** Represents the unique identifier of the object. */
14-
id: string;
15-
/** Represents the avatar of the user. */
16-
avatar: string;
17-
/** Represents the location of the thread. */
18-
thread_location?: string;
19-
/** Represents the object. */
20-
object: string;
21-
/** Represents the creation timestamp of the object. */
22-
created_at: number;
23-
/** Represents the name of the object. */
24-
name: string;
25-
/** Represents the description of the object. */
26-
description?: string;
27-
/** Represents the model of the object. */
28-
model: string;
29-
/** Represents the instructions for the object. */
30-
instructions?: string;
31-
/** Represents the tools associated with the object. */
32-
tools?: AssistantTool[];
33-
/** Represents the file identifiers associated with the object. */
34-
file_ids: string[];
35-
/** Represents the metadata of the object. */
36-
metadata?: AssistantMetadata;
9+
tool_resources?: AssistantToolResources;
3710
}
3811

39-
export interface AssistantMetadata {}
12+
export type AssistantResponseFormatOption = OpenAIAssistantResponseFormatOption;
13+
14+
export interface AssistantToolResources extends OpenAiAssistant.ToolResources {}
Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,12 @@
1-
import { AssistantTool } from './assistant.interface';
2-
import { Model } from './model.interface';
1+
import { Thread as OpenAiThread } from 'openai/resources/beta/threads/threads';
2+
import { Assistant } from './assistant.interface';
33

4-
export interface Thread {
5-
/** Unique identifier for the thread, generated by default using the ULID method. **/
6-
id: string;
4+
export interface ThreadToolResources extends OpenAiThread.ToolResources {}
75

8-
/** Object name **/
9-
object: string;
10-
11-
/** The title of this thread. **/
6+
export interface Thread extends OpenAiThread {
127
title: string;
138

14-
/** Assistants in this thread. **/
15-
assistants: ThreadAssistantInfo[];
16-
17-
/** The timestamp indicating when this thread was created, represented in ISO 8601 format. **/
18-
createdAt: number;
19-
20-
/** The timestamp indicating when this thread was updated, represented in ISO 8601 format. **/
21-
updatedAt?: number;
22-
23-
/**
24-
* The additional metadata of this thread.
25-
**/
26-
metadata?: ThreadMetadata;
27-
}
28-
29-
/**
30-
* The additional metadata of this thread.
31-
*/
32-
export interface ThreadMetadata {
33-
lastMessage?: string;
34-
}
9+
assistants: Assistant[];
3510

36-
/**
37-
* Represents the information about an assistant in a thread.
38-
* @stored
39-
*/
40-
export interface ThreadAssistantInfo {
41-
assistant_id: string;
42-
assistant_name: string;
43-
model: Partial<Model>;
44-
instructions?: string;
45-
tools?: AssistantTool[];
11+
tool_resources: ThreadToolResources | null;
4612
}

cortex-js/src/infrastructure/commanders/usecases/chat.cli.usecases.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,16 @@ export class ChatCliUsecases {
265265
if (!assistant) throw new Error('No assistant available');
266266

267267
const assistantDto: CreateThreadAssistantDto = {
268-
assistant_id: assistant.id,
269-
assistant_name: assistant.name,
270-
model: model,
268+
avatar: '',
269+
id: 'jan',
270+
object: 'assistant',
271+
created_at: Date.now(),
272+
name: 'Jan',
273+
description: 'A default assistant that can use all downloaded models',
274+
model: modelId,
275+
instructions: '',
276+
tools: [],
277+
metadata: {},
271278
};
272279

273280
const createThreadDto: CreateThreadDto = {

cortex-js/src/infrastructure/dtos/assistants/assistant-tool.dto.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
1-
import { Type } from 'class-transformer';
2-
import { IsArray, IsOptional, IsString, ValidateNested } from 'class-validator';
3-
import {
4-
Assistant,
5-
AssistantMetadata,
6-
} from '@/domain/models/assistant.interface';
7-
import { AssistantToolDto } from './assistant-tool.dto';
1+
import { IsArray, IsOptional, IsString } from 'class-validator';
2+
import { Assistant } from '@/domain/models/assistant.interface';
83
import { ApiProperty } from '@nestjs/swagger';
94

105
export class CreateAssistantDto implements Partial<Assistant> {
116
@ApiProperty({
127
description: 'The unique identifier of the assistant.',
8+
example: 'jan',
9+
default: 'jan',
1310
})
1411
@IsString()
1512
id: string;
1613

1714
@ApiProperty({
1815
description: 'The avatar of the assistant.',
16+
example: '',
17+
default: '',
1918
})
19+
@IsOptional()
2020
@IsString()
21-
avatar: string;
21+
avatar?: string;
2222

2323
@ApiProperty({
2424
description: 'The name of the assistant.',
25+
example: 'Jan',
26+
default: 'Jan',
2527
})
2628
@IsString()
2729
name: string;
2830

2931
@ApiProperty({
3032
description: 'The description of the assistant.',
33+
example: 'A default assistant that can use all downloaded models',
34+
default: 'A default assistant that can use all downloaded models',
3135
})
3236
@IsString()
3337
description: string;
@@ -40,29 +44,23 @@ export class CreateAssistantDto implements Partial<Assistant> {
4044

4145
@ApiProperty({
4246
description: 'The instructions for the assistant.',
47+
example: '',
48+
default: '',
4349
})
4450
@IsString()
4551
instructions: string;
4652

4753
@ApiProperty({
4854
description: 'The tools associated with the assistant.',
55+
example: [],
56+
default: [],
4957
})
5058
@IsArray()
51-
@ValidateNested({ each: true })
52-
@Type(() => AssistantToolDto)
53-
tools: AssistantToolDto[];
54-
55-
@ApiProperty({
56-
description:
57-
'The identifiers of the files that have been uploaded to the thread.',
58-
})
59-
@IsArray()
60-
@IsOptional()
61-
file_ids: string[];
59+
tools: any[];
6260

6361
@ApiProperty({
6462
description: 'The metadata of the assistant.',
6563
})
6664
@IsOptional()
67-
metadata?: AssistantMetadata;
65+
metadata: unknown | null;
6866
}
Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,73 @@
1-
import { IsArray, IsOptional, IsString, ValidateNested } from 'class-validator';
2-
import { ThreadAssistantInfo } from '@/domain/models/thread.interface';
3-
import { AssistantToolDto } from '@/infrastructure/dtos/assistants/assistant-tool.dto';
4-
import { Type } from 'class-transformer';
1+
import { IsArray, IsNumber, IsOptional, IsString } from 'class-validator';
52
import { ApiProperty } from '@nestjs/swagger';
6-
import { CreateModelDto } from '../models/create-model.dto';
3+
import {
4+
Assistant,
5+
AssistantToolResources,
6+
} from '@/domain/models/assistant.interface';
7+
import { AssistantResponseFormatOption } from 'openai/resources/beta/threads/threads';
78

8-
export class CreateThreadAssistantDto implements ThreadAssistantInfo {
9-
@ApiProperty({ description: 'The unique identifier of the assistant.' })
9+
export class CreateThreadAssistantDto implements Assistant {
10+
@ApiProperty({
11+
description: 'The unique identifier of the assistant.',
12+
type: 'string',
13+
})
14+
@IsString()
15+
id: string;
16+
17+
@ApiProperty()
18+
@IsOptional()
1019
@IsString()
11-
assistant_id: string;
20+
avatar?: string;
1221

1322
@ApiProperty({ description: 'The name of the assistant.' })
1423
@IsString()
15-
assistant_name: string;
24+
name: string;
1625

1726
@ApiProperty({ description: "The model's unique identifier and settings." })
18-
@ValidateNested()
19-
model: CreateModelDto;
27+
@IsString()
28+
model: string;
2029

2130
@ApiProperty({ description: "The assistant's specific instructions." })
22-
@IsOptional()
2331
@IsString()
24-
instructions?: string;
32+
instructions: string;
2533

2634
@ApiProperty({
2735
description: "The thread's tool(Knowledge Retrieval) configurations.",
2836
})
2937
@IsOptional()
3038
@IsArray()
31-
@ValidateNested({ each: true })
32-
@Type(() => AssistantToolDto)
33-
tools?: AssistantToolDto[];
39+
tools: any;
40+
41+
@ApiProperty()
42+
@IsString()
43+
@IsOptional()
44+
description: string | null;
45+
46+
@ApiProperty()
47+
@IsOptional()
48+
metadata: Record<string, unknown> | null;
49+
50+
@ApiProperty()
51+
object: 'assistant';
52+
53+
@ApiProperty()
54+
@IsNumber()
55+
@IsOptional()
56+
temperature?: number | null;
57+
58+
@ApiProperty()
59+
@IsNumber()
60+
@IsOptional()
61+
top_p?: number | null;
62+
63+
@ApiProperty()
64+
created_at: number;
65+
66+
@ApiProperty()
67+
@IsOptional()
68+
response_format?: AssistantResponseFormatOption;
69+
70+
@ApiProperty()
71+
@IsOptional()
72+
tool_resources?: AssistantToolResources;
3473
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import { IsArray, ValidateNested } from 'class-validator';
1+
import { IsArray } from 'class-validator';
22
import { Thread } from '@/domain/models/thread.interface';
33
import { CreateThreadAssistantDto } from './create-thread-assistant.dto';
4-
import { Type } from 'class-transformer';
54
import { ApiProperty } from '@nestjs/swagger';
65

76
export class CreateThreadDto implements Partial<Thread> {
87
@ApiProperty({ description: "The details of the thread's settings." })
98
@IsArray()
10-
@ValidateNested({ each: true })
11-
@Type(() => CreateThreadAssistantDto)
129
assistants: CreateThreadAssistantDto[];
1310
}

0 commit comments

Comments
 (0)