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

Commit e70700f

Browse files
authored
Merge pull request #709 from janhq/fix/extends-from-open-ai
chore: update models to extends from openai
2 parents 5ca2bde + cceeb06 commit e70700f

33 files changed

+703
-602
lines changed

cortex-js/src/app.module.ts

Lines changed: 1 addition & 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';
@@ -38,6 +37,7 @@ import { DownloadManagerModule } from './infrastructure/services/download-manage
3837
envFilePath: env.NODE_ENV !== 'production' ? '.env.development' : '.env',
3938
}),
4039
EventEmitterModule.forRoot(),
40+
DownloadManagerModule,
4141
DatabaseModule,
4242
MessagesModule,
4343
ThreadsModule,
@@ -62,7 +62,6 @@ import { DownloadManagerModule } from './infrastructure/services/download-manage
6262
EventsController,
6363
],
6464
providers: [
65-
SeedService,
6665
{
6766
provide: APP_FILTER,
6867
useClass: GlobalExceptionFilter,
Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,10 @@
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;
4+
export interface Assistant extends OpenAiAssistant {
5+
avatar?: string;
106
}
117

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;
37-
}
8+
export type AssistantResponseFormatOption = OpenAIAssistantResponseFormatOption;
389

39-
export interface AssistantMetadata {}
10+
export interface AssistantToolResources extends OpenAiAssistant.ToolResources {}
Lines changed: 11 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,16 @@
1-
export enum ChatCompletionRole {
2-
System = 'system',
3-
Assistant = 'assistant',
4-
User = 'user',
5-
}
1+
import {
2+
Message as OpenAiMessage,
3+
MessageContent as OpenAiMessageContent,
4+
TextContentBlock as OpenAiTextContentBlock,
5+
} from 'openai/resources/beta/threads/messages';
66

7-
export enum ContentType {
8-
Text = 'text',
9-
Image = 'image',
10-
Pdf = 'pdf',
11-
}
7+
export interface Message extends OpenAiMessage {}
128

13-
export interface ContentValue {
14-
value: string;
15-
annotations: string[];
16-
name?: string;
17-
size?: number;
18-
}
9+
export type MessageContent = OpenAiMessageContent;
1910

20-
export interface ThreadContent {
21-
type: ContentType;
22-
text: ContentValue;
23-
}
11+
export type TextContentBlock = OpenAiTextContentBlock;
2412

25-
/**
26-
* The status of the message.
27-
* @data_transfer_object
28-
*/
29-
export enum MessageStatus {
30-
/** Message is fully loaded. **/
31-
Ready = 'ready',
32-
/** Message is not fully loaded. **/
33-
Pending = 'pending',
34-
/** Message loaded with error. **/
35-
Error = 'error',
36-
/** Message is cancelled streaming */
37-
Stopped = 'stopped',
38-
}
13+
export interface MessageIncompleteDetails
14+
extends OpenAiMessage.IncompleteDetails {}
3915

40-
/**
41-
* The error code which explain what error type. Used in conjunction with MessageStatus.Error
42-
*/
43-
export enum ErrorCode {
44-
InvalidApiKey = 'invalid_api_key',
45-
46-
InsufficientQuota = 'insufficient_quota',
47-
48-
InvalidRequestError = 'invalid_request_error',
49-
50-
Unknown = 'unknown',
51-
}
52-
53-
export interface Message {
54-
/** Unique identifier for the message, generated by default using the ULID method. **/
55-
id: string;
56-
/** Object name **/
57-
object: string;
58-
/** Thread id, default is a ulid. **/
59-
thread_id: string;
60-
/** The assistant id of this thread. **/
61-
assistant_id?: string;
62-
/** The role of the author of this message. **/
63-
role: ChatCompletionRole;
64-
/** The content of this message. **/
65-
content: ThreadContent[];
66-
/** The status of this message. **/
67-
status: MessageStatus;
68-
/** The timestamp indicating when this message was created. Represented in Unix time. **/
69-
created: number;
70-
/** The timestamp indicating when this message was updated. Represented in Unix time. **/
71-
updated?: number;
72-
/** The additional metadata of this message. **/
73-
metadata?: MessageMetadata;
74-
/** The error code which explain what error type. Used in conjunction with MessageStatus.Error */
75-
error_code?: ErrorCode;
76-
}
77-
78-
/**
79-
* The additional metadata of this message.
80-
*/
81-
export interface MessageMetadata {}
16+
export interface MessageAttachment extends OpenAiMessage.Attachment {}

cortex-js/src/domain/models/model.interface.ts

Lines changed: 56 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
/**
2-
* Model type defines the shape of a model object.
3-
* @stored
4-
*/
5-
export interface Model {
1+
import { Model as OpenAiModel } from 'openai/resources/models';
2+
3+
export interface Model
4+
extends OpenAiModel,
5+
ModelSettingParams,
6+
ModelRuntimeParams {
67
/**
78
* Model identifier.
89
*/
@@ -23,57 +24,23 @@ export interface Model {
2324
*/
2425
files: string[] | ModelArtifact;
2526

26-
/**
27-
* GGUF metadata: tokenizer.chat_template
28-
*/
29-
prompt_template?: string;
30-
31-
/**
32-
* Defines specific tokens or phrases at which the model will stop generating further output.
33-
*/
34-
stop?: string[];
35-
36-
/// Inferencing
37-
/**
38-
* Set probability threshold for more relevant outputs.
39-
*/
40-
top_p?: number;
41-
42-
/**
43-
* Controls the randomness of the model’s output.
44-
*/
45-
temperature?: number;
46-
47-
/**
48-
* Adjusts the likelihood of the model repeating words or phrases in its output.
49-
*/
50-
frequency_penalty?: number;
51-
52-
/**
53-
* Influences the generation of new and varied concepts in the model’s output.
54-
*/
55-
presence_penalty?: number;
27+
metadata?: Record<string, any>;
28+
}
5629

57-
/// Engines
30+
/**
31+
* The available model settings.
32+
*/
33+
export interface ModelSettingParams {
5834
/**
5935
* The context length for model operations varies; the maximum depends on the specific model used.
6036
*/
6137
ctx_len?: number;
6238

63-
/**
64-
* Enable real-time data processing for faster predictions.
65-
*/
66-
stream?: boolean;
67-
68-
/*
69-
* The maximum number of tokens the model will generate in a single response.
70-
*/
71-
max_tokens?: number;
72-
7339
/**
7440
* The number of layers to load onto the GPU for acceleration.
7541
*/
7642
ngl?: number;
43+
embedding?: boolean;
7744

7845
/**
7946
* Number of parallel sequences to decode
@@ -85,6 +52,22 @@ export interface Model {
8552
*/
8653
cpu_threads?: number;
8754

55+
/**
56+
* GGUF metadata: tokenizer.chat_template
57+
*/
58+
prompt_template?: string;
59+
system_prompt?: string;
60+
ai_prompt?: string;
61+
user_prompt?: string;
62+
llama_model_path?: string;
63+
mmproj?: string;
64+
cont_batching?: boolean;
65+
66+
/**
67+
* The model engine.
68+
*/
69+
engine?: string;
70+
8871
/**
8972
* The prompt to use for internal configuration
9073
*/
@@ -134,59 +117,48 @@ export interface Model {
134117
* To enable mmap, default is true
135118
*/
136119
use_mmap?: boolean;
137-
138-
/**
139-
* The model engine.
140-
*/
141-
engine?: string;
142-
}
143-
144-
/**
145-
* The available model settings.
146-
*/
147-
export interface ModelSettingParams {
148-
ctx_len?: number;
149-
ngl?: number;
150-
embedding?: boolean;
151-
n_parallel?: number;
152-
cpu_threads?: number;
153-
prompt_template?: string;
154-
system_prompt?: string;
155-
ai_prompt?: string;
156-
user_prompt?: string;
157-
llama_model_path?: string;
158-
mmproj?: string;
159-
cont_batching?: boolean;
160-
engine?: string;
161-
stop?: string[];
162-
pre_prompt?: string;
163-
n_batch?: number;
164-
caching_enabled?: boolean;
165-
grp_attn_n?: number;
166-
grp_attn_w?: number;
167-
mlock?: boolean;
168-
grammar_file?: string;
169-
model_type?: string;
170-
model_alias?: string;
171-
flash_attn?: boolean;
172-
cache_type?: string;
173-
use_mmap?: boolean;
174120
}
175121

176122
/**
177123
* The available model runtime parameters.
178124
*/
179125
export interface ModelRuntimeParams {
126+
/**
127+
* Controls the randomness of the model’s output.
128+
*/
180129
temperature?: number;
181130
token_limit?: number;
182131
top_k?: number;
132+
133+
/**
134+
* Set probability threshold for more relevant outputs.
135+
*/
183136
top_p?: number;
137+
138+
/**
139+
* Enable real-time data processing for faster predictions.
140+
*/
184141
stream?: boolean;
142+
143+
/*
144+
* The maximum number of tokens the model will generate in a single response.
145+
*/
185146
max_tokens?: number;
147+
148+
/**
149+
* Defines specific tokens or phrases at which the model will stop generating further output.
150+
*/
186151
stop?: string[];
152+
153+
/**
154+
* Adjusts the likelihood of the model repeating words or phrases in its output.
155+
*/
187156
frequency_penalty?: number;
157+
158+
/**
159+
* Influences the generation of new and varied concepts in the model’s output.
160+
*/
188161
presence_penalty?: number;
189-
engine?: string;
190162
}
191163

192164
/**

0 commit comments

Comments
 (0)