Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cortex-js/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ExtensionModule } from './infrastructure/repositories/extensions/extens
import { CortexModule } from './usecases/cortex/cortex.module';
import { ConfigModule } from '@nestjs/config';
import { env } from 'node:process';
import { SeedService } from './usecases/seed/seed.service';
import { FileManagerModule } from './infrastructure/services/file-manager/file-manager.module';
import { AppLoggerMiddleware } from './infrastructure/middlewares/app.logger.middleware';
import { TelemetryModule } from './usecases/telemetry/telemetry.module';
Expand Down Expand Up @@ -38,6 +37,7 @@ import { DownloadManagerModule } from './infrastructure/services/download-manage
envFilePath: env.NODE_ENV !== 'production' ? '.env.development' : '.env',
}),
EventEmitterModule.forRoot(),
DownloadManagerModule,
DatabaseModule,
MessagesModule,
ThreadsModule,
Expand All @@ -62,7 +62,6 @@ import { DownloadManagerModule } from './infrastructure/services/download-manage
EventsController,
],
providers: [
SeedService,
{
provide: APP_FILTER,
useClass: GlobalExceptionFilter,
Expand Down
41 changes: 6 additions & 35 deletions cortex-js/src/domain/models/assistant.interface.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
/**
* Assistant type defines the shape of an assistant object.
* @stored
*/
import { Assistant as OpenAiAssistant } from 'openai/resources/beta/assistants';
import { AssistantResponseFormatOption as OpenAIAssistantResponseFormatOption } from 'openai/resources/beta/threads/threads';

export interface AssistantTool {
type: string;
enabled: boolean;
settings: any;
export interface Assistant extends OpenAiAssistant {
avatar?: string;
}

export interface Assistant {
/** Represents the unique identifier of the object. */
id: string;
/** Represents the avatar of the user. */
avatar: string;
/** Represents the location of the thread. */
thread_location?: string;
/** Represents the object. */
object: string;
/** Represents the creation timestamp of the object. */
created_at: number;
/** Represents the name of the object. */
name: string;
/** Represents the description of the object. */
description?: string;
/** Represents the model of the object. */
model: string;
/** Represents the instructions for the object. */
instructions?: string;
/** Represents the tools associated with the object. */
tools?: AssistantTool[];
/** Represents the file identifiers associated with the object. */
file_ids: string[];
/** Represents the metadata of the object. */
metadata?: AssistantMetadata;
}
export type AssistantResponseFormatOption = OpenAIAssistantResponseFormatOption;

export interface AssistantMetadata {}
export interface AssistantToolResources extends OpenAiAssistant.ToolResources {}
87 changes: 11 additions & 76 deletions cortex-js/src/domain/models/message.interface.ts
Original file line number Diff line number Diff line change
@@ -1,81 +1,16 @@
export enum ChatCompletionRole {
System = 'system',
Assistant = 'assistant',
User = 'user',
}
import {
Message as OpenAiMessage,
MessageContent as OpenAiMessageContent,
TextContentBlock as OpenAiTextContentBlock,
} from 'openai/resources/beta/threads/messages';

export enum ContentType {
Text = 'text',
Image = 'image',
Pdf = 'pdf',
}
export interface Message extends OpenAiMessage {}

export interface ContentValue {
value: string;
annotations: string[];
name?: string;
size?: number;
}
export type MessageContent = OpenAiMessageContent;

export interface ThreadContent {
type: ContentType;
text: ContentValue;
}
export type TextContentBlock = OpenAiTextContentBlock;

/**
* The status of the message.
* @data_transfer_object
*/
export enum MessageStatus {
/** Message is fully loaded. **/
Ready = 'ready',
/** Message is not fully loaded. **/
Pending = 'pending',
/** Message loaded with error. **/
Error = 'error',
/** Message is cancelled streaming */
Stopped = 'stopped',
}
export interface MessageIncompleteDetails
extends OpenAiMessage.IncompleteDetails {}

/**
* The error code which explain what error type. Used in conjunction with MessageStatus.Error
*/
export enum ErrorCode {
InvalidApiKey = 'invalid_api_key',

InsufficientQuota = 'insufficient_quota',

InvalidRequestError = 'invalid_request_error',

Unknown = 'unknown',
}

export interface Message {
/** Unique identifier for the message, generated by default using the ULID method. **/
id: string;
/** Object name **/
object: string;
/** Thread id, default is a ulid. **/
thread_id: string;
/** The assistant id of this thread. **/
assistant_id?: string;
/** The role of the author of this message. **/
role: ChatCompletionRole;
/** The content of this message. **/
content: ThreadContent[];
/** The status of this message. **/
status: MessageStatus;
/** The timestamp indicating when this message was created. Represented in Unix time. **/
created: number;
/** The timestamp indicating when this message was updated. Represented in Unix time. **/
updated?: number;
/** The additional metadata of this message. **/
metadata?: MessageMetadata;
/** The error code which explain what error type. Used in conjunction with MessageStatus.Error */
error_code?: ErrorCode;
}

/**
* The additional metadata of this message.
*/
export interface MessageMetadata {}
export interface MessageAttachment extends OpenAiMessage.Attachment {}
140 changes: 56 additions & 84 deletions cortex-js/src/domain/models/model.interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* Model type defines the shape of a model object.
* @stored
*/
export interface Model {
import { Model as OpenAiModel } from 'openai/resources/models';

export interface Model
extends OpenAiModel,
ModelSettingParams,
ModelRuntimeParams {
/**
* Model identifier.
*/
Expand All @@ -23,57 +24,23 @@ export interface Model {
*/
files: string[] | ModelArtifact;

/**
* GGUF metadata: tokenizer.chat_template
*/
prompt_template?: string;

/**
* Defines specific tokens or phrases at which the model will stop generating further output.
*/
stop?: string[];

/// Inferencing
/**
* Set probability threshold for more relevant outputs.
*/
top_p?: number;

/**
* Controls the randomness of the model’s output.
*/
temperature?: number;

/**
* Adjusts the likelihood of the model repeating words or phrases in its output.
*/
frequency_penalty?: number;

/**
* Influences the generation of new and varied concepts in the model’s output.
*/
presence_penalty?: number;
metadata?: Record<string, any>;
}

/// Engines
/**
* The available model settings.
*/
export interface ModelSettingParams {
/**
* The context length for model operations varies; the maximum depends on the specific model used.
*/
ctx_len?: number;

/**
* Enable real-time data processing for faster predictions.
*/
stream?: boolean;

/*
* The maximum number of tokens the model will generate in a single response.
*/
max_tokens?: number;

/**
* The number of layers to load onto the GPU for acceleration.
*/
ngl?: number;
embedding?: boolean;

/**
* Number of parallel sequences to decode
Expand All @@ -85,6 +52,22 @@ export interface Model {
*/
cpu_threads?: number;

/**
* GGUF metadata: tokenizer.chat_template
*/
prompt_template?: string;
system_prompt?: string;
ai_prompt?: string;
user_prompt?: string;
llama_model_path?: string;
mmproj?: string;
cont_batching?: boolean;

/**
* The model engine.
*/
engine?: string;

/**
* The prompt to use for internal configuration
*/
Expand Down Expand Up @@ -134,59 +117,48 @@ export interface Model {
* To enable mmap, default is true
*/
use_mmap?: boolean;

/**
* The model engine.
*/
engine?: string;
}

/**
* The available model settings.
*/
export interface ModelSettingParams {
ctx_len?: number;
ngl?: number;
embedding?: boolean;
n_parallel?: number;
cpu_threads?: number;
prompt_template?: string;
system_prompt?: string;
ai_prompt?: string;
user_prompt?: string;
llama_model_path?: string;
mmproj?: string;
cont_batching?: boolean;
engine?: string;
stop?: string[];
pre_prompt?: string;
n_batch?: number;
caching_enabled?: boolean;
grp_attn_n?: number;
grp_attn_w?: number;
mlock?: boolean;
grammar_file?: string;
model_type?: string;
model_alias?: string;
flash_attn?: boolean;
cache_type?: string;
use_mmap?: boolean;
}

/**
* The available model runtime parameters.
*/
export interface ModelRuntimeParams {
/**
* Controls the randomness of the model’s output.
*/
temperature?: number;
token_limit?: number;
top_k?: number;

/**
* Set probability threshold for more relevant outputs.
*/
top_p?: number;

/**
* Enable real-time data processing for faster predictions.
*/
stream?: boolean;

/*
* The maximum number of tokens the model will generate in a single response.
*/
max_tokens?: number;

/**
* Defines specific tokens or phrases at which the model will stop generating further output.
*/
stop?: string[];

/**
* Adjusts the likelihood of the model repeating words or phrases in its output.
*/
frequency_penalty?: number;

/**
* Influences the generation of new and varied concepts in the model’s output.
*/
presence_penalty?: number;
engine?: string;
}

/**
Expand Down
Loading