refactor: change types and interfaces only

This commit is contained in:
0xSage 2023-12-13 15:12:02 +08:00
parent 89d73e7f30
commit db2ccc112b
27 changed files with 590 additions and 488 deletions

View File

@ -1,25 +1,26 @@
// TODO: refactor EventName to use the events defined in /types
/** /**
* The `EventName` enumeration contains the names of all the available events in the Jan platform. * The `EventName` enumeration contains the names of all the available events in the Jan platform.
*/ */
export enum EventName { export enum EventName {
/** The `OnMessageSent` event is emitted when a message is sent. */ /** The `OnMessageSent` event is emitted when a message is sent. */
OnMessageSent = "OnMessageSent", OnMessageSent = 'OnMessageSent',
/** The `OnMessageResponse` event is emitted when a message is received. */ /** The `OnMessageResponse` event is emitted when a message is received. */
OnMessageResponse = "OnMessageResponse", OnMessageResponse = 'OnMessageResponse',
/** The `OnMessageUpdate` event is emitted when a message is updated. */ /** The `OnMessageUpdate` event is emitted when a message is updated. */
OnMessageUpdate = "OnMessageUpdate", OnMessageUpdate = 'OnMessageUpdate',
/** The `OnModelInit` event is emitted when a model inits. */ /** The `OnModelInit` event is emitted when a model inits. */
OnModelInit = "OnModelInit", OnModelInit = 'OnModelInit',
/** The `OnModelReady` event is emitted when a model ready. */ /** The `OnModelReady` event is emitted when a model ready. */
OnModelReady = "OnModelReady", OnModelReady = 'OnModelReady',
/** The `OnModelFail` event is emitted when a model fails loading. */ /** The `OnModelFail` event is emitted when a model fails loading. */
OnModelFail = "OnModelFail", OnModelFail = 'OnModelFail',
/** The `OnModelStop` event is emitted when a model start to stop. */ /** The `OnModelStop` event is emitted when a model start to stop. */
OnModelStop = "OnModelStop", OnModelStop = 'OnModelStop',
/** The `OnModelStopped` event is emitted when a model stopped ok. */ /** The `OnModelStopped` event is emitted when a model stopped ok. */
OnModelStopped = "OnModelStopped", OnModelStopped = 'OnModelStopped',
/** The `OnInferenceStopped` event is emitted when a inference is stopped. */ /** The `OnInferenceStopped` event is emitted when a inference is stopped. */
OnInferenceStopped = "OnInferenceStopped", OnInferenceStopped = 'OnInferenceStopped',
} }
/** /**
@ -28,12 +29,9 @@ export enum EventName {
* @param eventName The name of the event to observe. * @param eventName The name of the event to observe.
* @param handler The handler function to call when the event is observed. * @param handler The handler function to call when the event is observed.
*/ */
const on: (eventName: string, handler: Function) => void = ( const on: (eventName: string, handler: Function) => void = (eventName, handler) => {
eventName, global.core?.events?.on(eventName, handler)
handler }
) => {
global.core?.events?.on(eventName, handler);
};
/** /**
* Removes an observer for an event. * Removes an observer for an event.
@ -41,12 +39,9 @@ const on: (eventName: string, handler: Function) => void = (
* @param eventName The name of the event to stop observing. * @param eventName The name of the event to stop observing.
* @param handler The handler function to call when the event is observed. * @param handler The handler function to call when the event is observed.
*/ */
const off: (eventName: string, handler: Function) => void = ( const off: (eventName: string, handler: Function) => void = (eventName, handler) => {
eventName, global.core?.events?.off(eventName, handler)
handler }
) => {
global.core?.events?.off(eventName, handler);
};
/** /**
* Emits an event. * Emits an event.
@ -55,11 +50,11 @@ const off: (eventName: string, handler: Function) => void = (
* @param object The object to pass to the event callback. * @param object The object to pass to the event callback.
*/ */
const emit: (eventName: string, object: any) => void = (eventName, object) => { const emit: (eventName: string, object: any) => void = (eventName, object) => {
global.core?.events?.emit(eventName, object); global.core?.events?.emit(eventName, object)
}; }
export const events = { export const events = {
on, on,
off, off,
emit, emit,
}; }

View File

@ -1,28 +1,12 @@
import { Assistant } from "../index"; import { Assistant, AssistantInterface } from '../index'
import { BaseExtension } from "../extension"; import { BaseExtension } from '../extension'
/** /**
* Assistant extension for managing assistants. * Assistant extension for managing assistants.
* @extends BaseExtension * @extends BaseExtension
*/ */
export abstract class AssistantExtension extends BaseExtension { export abstract class AssistantExtension extends BaseExtension implements AssistantInterface {
/** abstract createAssistant(assistant: Assistant): Promise<void>
* Creates a new assistant. abstract deleteAssistant(assistant: Assistant): Promise<void>
* @param {Assistant} assistant - The assistant object to be created. abstract getAssistants(): Promise<Assistant[]>
* @returns {Promise<void>} A promise that resolves when the assistant has been created.
*/
abstract createAssistant(assistant: Assistant): Promise<void>;
/**
* Deletes an existing assistant.
* @param {Assistant} assistant - The assistant object to be deleted.
* @returns {Promise<void>} A promise that resolves when the assistant has been deleted.
*/
abstract deleteAssistant(assistant: Assistant): Promise<void>;
/**
* Retrieves all existing assistants.
* @returns {Promise<Assistant[]>} A promise that resolves to an array of all assistants.
*/
abstract getAssistants(): Promise<Assistant[]>;
} }

View File

@ -1,57 +1,19 @@
import { Thread, ThreadMessage } from "../index"; import { Thread, ThreadInterface, ThreadMessage, MessageInterface } from '../index'
import { BaseExtension } from "../extension"; import { BaseExtension } from '../extension'
/** /**
* Conversational extension. Persists and retrieves conversations. * Conversational extension. Persists and retrieves conversations.
* @abstract * @abstract
* @extends BaseExtension * @extends BaseExtension
*/ */
export abstract class ConversationalExtension extends BaseExtension { export abstract class ConversationalExtension
/** extends BaseExtension
* Returns a list of thread. implements ThreadInterface, MessageInterface
* @abstract {
* @returns {Promise<Thread[]>} A promise that resolves to an array of threads. abstract getThreads(): Promise<Thread[]>
*/ abstract saveThread(thread: Thread): Promise<void>
abstract getThreads(): Promise<Thread[]>; abstract deleteThread(threadId: string): Promise<void>
abstract addNewMessage(message: ThreadMessage): Promise<void>
/** abstract writeMessages(threadId: string, messages: ThreadMessage[]): Promise<void>
* Saves a thread. abstract getAllMessages(threadId: string): Promise<ThreadMessage[]>
* @abstract
* @param {Thread} thread - The thread to save.
* @returns {Promise<void>} A promise that resolves when the thread is saved.
*/
abstract saveThread(thread: Thread): Promise<void>;
/**
* Deletes a thread.
* @abstract
* @param {string} threadId - The ID of the thread to delete.
* @returns {Promise<void>} A promise that resolves when the thread is deleted.
*/
abstract deleteThread(threadId: string): Promise<void>;
/**
* Adds a new message to the thread.
* @param {ThreadMessage} message - The message to be added.
* @returns {Promise<void>} A promise that resolves when the message has been added.
*/
abstract addNewMessage(message: ThreadMessage): Promise<void>;
/**
* Writes an array of messages to a specific thread.
* @param {string} threadId - The ID of the thread to write the messages to.
* @param {ThreadMessage[]} messages - The array of messages to be written.
* @returns {Promise<void>} A promise that resolves when the messages have been written.
*/
abstract writeMessages(
threadId: string,
messages: ThreadMessage[]
): Promise<void>;
/**
* Retrieves all messages from a specific thread.
* @param {string} threadId - The ID of the thread to retrieve the messages from.
* @returns {Promise<ThreadMessage[]>} A promise that resolves to an array of messages from the thread.
*/
abstract getAllMessages(threadId: string): Promise<ThreadMessage[]>;
} }

View File

@ -1,14 +1,9 @@
import { MessageRequest, ModelSettingParams, ThreadMessage } from "../index"; import { InferenceInterface, MessageRequest, ThreadMessage } from '../index'
import { BaseExtension } from "../extension"; import { BaseExtension } from '../extension'
/** /**
* Inference extension. Start, stop and inference models. * Inference extension. Start, stop and inference models.
*/ */
export abstract class InferenceExtension extends BaseExtension { export abstract class InferenceExtension extends BaseExtension implements InferenceInterface {
/** abstract inference(data: MessageRequest): Promise<ThreadMessage>
* Processes an inference request.
* @param data - The data for the inference request.
* @returns The result of the inference request.
*/
abstract inference(data: MessageRequest): Promise<ThreadMessage>;
} }

View File

@ -1,47 +1,14 @@
import { BaseExtension } from "../extension"; import { BaseExtension } from '../extension'
import { Model } from "../types/index"; import { Model, ModelInterface } from '../index'
/** /**
* Model extension for managing models. * Model extension for managing models.
*/ */
export abstract class ModelExtension extends BaseExtension { export abstract class ModelExtension extends BaseExtension implements ModelInterface {
/** abstract downloadModel(model: Model): Promise<void>
* Downloads a model. abstract cancelModelDownload(modelId: string): Promise<void>
* @param model - The model to download. abstract deleteModel(modelId: string): Promise<void>
* @returns A Promise that resolves when the model has been downloaded. abstract saveModel(model: Model): Promise<void>
*/ abstract getDownloadedModels(): Promise<Model[]>
abstract downloadModel(model: Model): Promise<void>; abstract getConfiguredModels(): Promise<Model[]>
/**
* Cancels the download of a specific model.
* @param {string} modelId - The ID of the model to cancel the download for.
* @returns {Promise<void>} A promise that resolves when the download has been cancelled.
*/
abstract cancelModelDownload(modelId: string): Promise<void>;
/**
* Deletes a model.
* @param modelId - The ID of the model to delete.
* @returns A Promise that resolves when the model has been deleted.
*/
abstract deleteModel(modelId: string): Promise<void>;
/**
* Saves a model.
* @param model - The model to save.
* @returns A Promise that resolves when the model has been saved.
*/
abstract saveModel(model: Model): Promise<void>;
/**
* Gets a list of downloaded models.
* @returns A Promise that resolves with an array of downloaded models.
*/
abstract getDownloadedModels(): Promise<Model[]>;
/**
* Gets a list of configured models.
* @returns A Promise that resolves with an array of configured models.
*/
abstract getConfiguredModels(): Promise<Model[]>;
} }

View File

@ -1,19 +1,11 @@
import { BaseExtension } from "../extension"; import { BaseExtension } from '../extension'
import { MonitoringInterface } from '../index'
/** /**
* Monitoring extension for system monitoring. * Monitoring extension for system monitoring.
* @extends BaseExtension * @extends BaseExtension
*/ */
export abstract class MonitoringExtension extends BaseExtension { export abstract class MonitoringExtension extends BaseExtension implements MonitoringInterface {
/** abstract getResourcesInfo(): Promise<any>
* Returns information about the system resources. abstract getCurrentLoad(): Promise<any>
* @returns {Promise<any>} A promise that resolves with the system resources information.
*/
abstract getResourcesInfo(): Promise<any>;
/**
* Returns the current system load.
* @returns {Promise<any>} A promise that resolves with the current system load.
*/
abstract getCurrentLoad(): Promise<any>;
} }

View File

@ -0,0 +1,30 @@
/**
* Assistant type defines the shape of an assistant object.
* @stored
*/
export type Assistant = {
/** Represents the avatar of the user. */
avatar: string
/** Represents the location of the thread. */
thread_location: string | undefined
/** Represents the unique identifier of the object. */
id: 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?: any
/** Represents the file identifiers associated with the object. */
file_ids: string[]
/** Represents the metadata of the object. */
metadata?: Record<string, unknown>
}

View File

@ -0,0 +1,26 @@
import { Assistant } from './assistantEntity'
/**
* Assistant extension for managing assistants.
* @extends BaseExtension
*/
export interface AssistantInterface {
/**
* Creates a new assistant.
* @param {Assistant} assistant - The assistant object to be created.
* @returns {Promise<void>} A promise that resolves when the assistant has been created.
*/
createAssistant(assistant: Assistant): Promise<void>
/**
* Deletes an existing assistant.
* @param {Assistant} assistant - The assistant object to be deleted.
* @returns {Promise<void>} A promise that resolves when the assistant has been deleted.
*/
deleteAssistant(assistant: Assistant): Promise<void>
/**
* Retrieves all existing assistants.
* @returns {Promise<Assistant[]>} A promise that resolves to an array of all assistants.
*/
getAssistants(): Promise<Assistant[]>
}

View File

@ -0,0 +1,2 @@
export * from './assistantEntity'
export * from './assistantInterface'

View File

@ -1,328 +1,6 @@
/** export * from './assistant'
* Message Request and Response export * from './model'
* ============================ export * from './thread'
* */ export * from './message'
export * from './inference'
/** export * from './monitoring'
* The role of the author of this message.
*/
export enum ChatCompletionRole {
System = "system",
Assistant = "assistant",
User = "user",
}
/**
* The `MessageRequest` type defines the shape of a new message request object.
* @data_transfer_object
*/
export type ChatCompletionMessage = {
/** The contents of the message. **/
content?: string;
/** The role of the author of this message. **/
role: ChatCompletionRole;
};
/**
* The `MessageRequest` type defines the shape of a new message request object.
* @data_transfer_object
*/
export type MessageRequest = {
id?: string;
/** The thread id of the message request. **/
threadId: string;
/**
* The assistant id of the message request.
*/
assistantId?: string;
/** Messages for constructing a chat completion request **/
messages?: ChatCompletionMessage[];
/** Settings for constructing a chat completion request **/
model?: ModelInfo;
};
/**
* Thread and Message
* ========================
* */
/**
* The status of the message.
* @data_transfer_object
*/
export enum MessageStatus {
/** Message is fully loaded. **/
Ready = "ready",
/** Message is not fully loaded. **/
Pending = "pending",
}
/**
* The `ThreadMessage` type defines the shape of a thread's message object.
* @stored
*/
export type ThreadMessage = {
/** 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?: Record<string, unknown>;
};
/**
* The content type of the message.
*/
export enum ContentType {
Text = "text",
Image = "image",
}
/**
* The `ThreadContent` type defines the shape of a message's content object
* @data_transfer_object
*/
export type ThreadContent = {
type: ContentType;
text: ContentValue;
};
/**
* The `ContentValue` type defines the shape of a content value object
* @data_transfer_object
*/
export type ContentValue = {
value: string;
annotations: string[];
};
/**
* The `Thread` type defines the shape of a thread object.
* @stored
*/
export interface Thread {
/** Unique identifier for the thread, generated by default using the ULID method. **/
id: string;
/** Object name **/
object: string;
/** The title of this thread. **/
title: string;
/** Assistants in this thread. **/
assistants: ThreadAssistantInfo[];
/** The timestamp indicating when this thread was created, represented in ISO 8601 format. **/
created: number;
/** The timestamp indicating when this thread was updated, represented in ISO 8601 format. **/
updated: number;
/** The additional metadata of this thread. **/
metadata?: Record<string, unknown>;
}
/**
* Represents the information about an assistant in a thread.
* @stored
*/
export type ThreadAssistantInfo = {
assistant_id: string;
assistant_name: string;
model: ModelInfo;
instructions?: string;
};
/**
* Represents the information about a model.
* @stored
*/
export type ModelInfo = {
id: string;
settings: ModelSettingParams;
parameters: ModelRuntimeParams;
engine?: InferenceEngine;
};
/**
* Represents the state of a thread.
* @stored
*/
export type ThreadState = {
hasMore: boolean;
waitingForResponse: boolean;
error?: Error;
lastMessage?: string;
isFinishInit?: boolean;
};
/**
* Represents the inference engine.
* @stored
*/
enum InferenceEngine {
nitro = "nitro",
openai = "openai",
triton_trtllm = "triton_trtllm",
hf_endpoint = "hf_endpoint",
}
/**
* Model type defines the shape of a model object.
* @stored
*/
export interface Model {
/**
* The type of the object.
* Default: "model"
*/
object: string;
/**
* The version of the model.
*/
version: number;
/**
* The format of the model.
*/
format: string;
/**
* The model download source. It can be an external url or a local filepath.
*/
source_url: string;
/**
* The model identifier, which can be referenced in the API endpoints.
*/
id: string;
/**
* Human-readable name that is used for UI.
*/
name: string;
/**
* The Unix timestamp (in seconds) for when the model was created
*/
created: number;
/**
* Default: "A cool model from Huggingface"
*/
description: string;
/**
* The model state.
* Default: "to_download"
* Enum: "to_download" "downloading" "ready" "running"
*/
state?: ModelState;
/**
* The model settings.
*/
settings: ModelSettingParams;
/**
* The model runtime parameters.
*/
parameters: ModelRuntimeParams;
/**
* Metadata of the model.
*/
metadata: ModelMetadata;
/**
* The model engine.
*/
engine: InferenceEngine;
}
export type ModelMetadata = {
author: string;
tags: string[];
size: number;
cover?: string;
};
/**
* The Model transition states.
*/
export enum ModelState {
Downloading = "downloading",
Ready = "ready",
Running = "running",
}
/**
* The available model settings.
*/
export type ModelSettingParams = {
ctx_len?: number;
ngl?: number;
embedding?: boolean;
n_parallel?: number;
cpu_threads?: number;
system_prompt?: string;
user_prompt?: string;
ai_prompt?: string;
};
/**
* The available model runtime parameters.
*/
export type ModelRuntimeParams = {
temperature?: number;
token_limit?: number;
top_k?: number;
top_p?: number;
stream?: boolean;
max_tokens?: number;
stop?: string[];
frequency_penalty?: number;
presence_penalty?: number;
};
/**
* Assistant type defines the shape of an assistant object.
* @stored
*/
export type Assistant = {
/** Represents the avatar of the user. */
avatar: string;
/** Represents the location of the thread. */
thread_location: string | undefined;
/** Represents the unique identifier of the object. */
id: 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?: any;
/** Represents the file identifiers associated with the object. */
file_ids: string[];
/** Represents the metadata of the object. */
metadata?: Record<string, unknown>;
};

View File

@ -0,0 +1,3 @@
export * from './inferenceEntity'
export * from './inferenceInterface'
export * from './inferenceEvent'

View File

@ -0,0 +1,19 @@
/**
* The role of the author of this message.
*/
export enum ChatCompletionRole {
System = 'system',
Assistant = 'assistant',
User = 'user',
}
/**
* The `MessageRequest` type defines the shape of a new message request object.
* @data_transfer_object
*/
export type ChatCompletionMessage = {
/** The contents of the message. **/
content?: string
/** The role of the author of this message. **/
role: ChatCompletionRole
}

View File

@ -0,0 +1,7 @@
/**
* The `EventName` enumeration contains the names of all the available events in the Jan platform.
*/
export enum InferenceEvent {
/** The `OnInferenceStopped` event is emitted when a inference is stopped. */
OnInferenceStopped = 'OnInferenceStopped',
}

View File

@ -0,0 +1,13 @@
import { MessageRequest, ThreadMessage } from '../message'
/**
* Inference extension. Start, stop and inference models.
*/
export interface InferenceInterface {
/**
* Processes an inference request.
* @param data - The data for the inference request.
* @returns The result of the inference request.
*/
inference(data: MessageRequest): Promise<ThreadMessage>
}

View File

@ -0,0 +1,3 @@
export * from './messageEntity'
export * from './messageInterface'
export * from './messageEvent'

View File

@ -0,0 +1,88 @@
import { ChatCompletionMessage, ChatCompletionRole } from '../inference'
import { ModelInfo } from '../model'
/**
* The `ThreadMessage` type defines the shape of a thread's message object.
* @stored
*/
export type ThreadMessage = {
/** 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?: Record<string, unknown>
}
/**
* The `MessageRequest` type defines the shape of a new message request object.
* @data_transfer_object
*/
export type MessageRequest = {
id?: string
/** The thread id of the message request. **/
threadId: string
/**
* The assistant id of the message request.
*/
assistantId?: string
/** Messages for constructing a chat completion request **/
messages?: ChatCompletionMessage[]
/** Settings for constructing a chat completion request **/
model?: ModelInfo
}
/**
* The status of the message.
* @data_transfer_object
*/
export enum MessageStatus {
/** Message is fully loaded. **/
Ready = 'ready',
/** Message is not fully loaded. **/
Pending = 'pending',
}
/**
* The content type of the message.
*/
export enum ContentType {
Text = 'text',
Image = 'image',
}
/**
* The `ContentValue` type defines the shape of a content value object
* @data_transfer_object
*/
export type ContentValue = {
value: string
annotations: string[]
}
/**
* The `ThreadContent` type defines the shape of a message's content object
* @data_transfer_object
*/
export type ThreadContent = {
type: ContentType
text: ContentValue
}

View File

@ -0,0 +1,8 @@
export enum MessageEvent {
/** The `OnMessageSent` event is emitted when a message is sent. */
OnMessageSent = 'OnMessageSent',
/** The `OnMessageResponse` event is emitted when a message is received. */
OnMessageResponse = 'OnMessageResponse',
/** The `OnMessageUpdate` event is emitted when a message is updated. */
OnMessageUpdate = 'OnMessageUpdate',
}

View File

@ -0,0 +1,30 @@
import { ThreadMessage } from './messageEntity'
/**
* Conversational extension. Persists and retrieves conversations.
* @abstract
* @extends BaseExtension
*/
export interface MessageInterface {
/**
* Adds a new message to the thread.
* @param {ThreadMessage} message - The message to be added.
* @returns {Promise<void>} A promise that resolves when the message has been added.
*/
addNewMessage(message: ThreadMessage): Promise<void>
/**
* Writes an array of messages to a specific thread.
* @param {string} threadId - The ID of the thread to write the messages to.
* @param {ThreadMessage[]} messages - The array of messages to be written.
* @returns {Promise<void>} A promise that resolves when the messages have been written.
*/
writeMessages(threadId: string, messages: ThreadMessage[]): Promise<void>
/**
* Retrieves all messages from a specific thread.
* @param {string} threadId - The ID of the thread to retrieve the messages from.
* @returns {Promise<ThreadMessage[]>} A promise that resolves to an array of messages from the thread.
*/
getAllMessages(threadId: string): Promise<ThreadMessage[]>
}

View File

@ -0,0 +1,3 @@
export * from './modelEntity'
export * from './modelInterface'
export * from './modelEvent'

View File

@ -0,0 +1,140 @@
/**
* Represents the information about a model.
* @stored
*/
export type ModelInfo = {
id: string
settings: ModelSettingParams
parameters: ModelRuntimeParams
engine?: InferenceEngine
}
/**
* Represents the inference engine.
* @stored
*/
enum InferenceEngine {
nitro = 'nitro',
openai = 'openai',
triton_trtllm = 'triton_trtllm',
hf_endpoint = 'hf_endpoint',
}
/**
* Model type defines the shape of a model object.
* @stored
*/
export type Model = {
/**
* The type of the object.
* Default: "model"
*/
object: string
/**
* The version of the model.
*/
version: number
/**
* The format of the model.
*/
format: string
/**
* The model download source. It can be an external url or a local filepath.
*/
source_url: string
/**
* The model identifier, which can be referenced in the API endpoints.
*/
id: string
/**
* Human-readable name that is used for UI.
*/
name: string
/**
* The Unix timestamp (in seconds) for when the model was created
*/
created: number
/**
* Default: "A cool model from Huggingface"
*/
description: string
/**
* The model state.
* Default: "to_download"
* Enum: "to_download" "downloading" "ready" "running"
*/
state?: ModelState
/**
* The model settings.
*/
settings: ModelSettingParams
/**
* The model runtime parameters.
*/
parameters: ModelRuntimeParams
/**
* Metadata of the model.
*/
metadata: ModelMetadata
/**
* The model engine.
*/
engine: InferenceEngine
}
export type ModelMetadata = {
author: string
tags: string[]
size: number
cover?: string
}
/**
* The Model transition states.
*/
export enum ModelState {
Downloading = 'downloading',
Ready = 'ready',
Running = 'running',
}
/**
* The available model settings.
*/
export type ModelSettingParams = {
ctx_len?: number
ngl?: number
embedding?: boolean
n_parallel?: number
cpu_threads?: number
system_prompt?: string
user_prompt?: string
ai_prompt?: string
}
/**
* The available model runtime parameters.
*/
export type ModelRuntimeParams = {
temperature?: number
token_limit?: number
top_k?: number
top_p?: number
stream?: boolean
max_tokens?: number
stop?: string[]
frequency_penalty?: number
presence_penalty?: number
}

View File

@ -0,0 +1,15 @@
/**
* The `EventName` enumeration contains the names of all the available events in the Jan platform.
*/
export enum ModelEvent {
/** The `OnModelInit` event is emitted when a model inits. */
OnModelInit = 'OnModelInit',
/** The `OnModelReady` event is emitted when a model ready. */
OnModelReady = 'OnModelReady',
/** The `OnModelFail` event is emitted when a model fails loading. */
OnModelFail = 'OnModelFail',
/** The `OnModelStop` event is emitted when a model start to stop. */
OnModelStop = 'OnModelStop',
/** The `OnModelStopped` event is emitted when a model stopped ok. */
OnModelStopped = 'OnModelStopped',
}

View File

@ -0,0 +1,46 @@
import { Model } from './modelEntity'
/**
* Model extension for managing models.
*/
export interface ModelInterface {
/**
* Downloads a model.
* @param model - The model to download.
* @returns A Promise that resolves when the model has been downloaded.
*/
downloadModel(model: Model): Promise<void>
/**
* Cancels the download of a specific model.
* @param {string} modelId - The ID of the model to cancel the download for.
* @returns {Promise<void>} A promise that resolves when the download has been cancelled.
*/
cancelModelDownload(modelId: string): Promise<void>
/**
* Deletes a model.
* @param modelId - The ID of the model to delete.
* @returns A Promise that resolves when the model has been deleted.
*/
deleteModel(modelId: string): Promise<void>
/**
* Saves a model.
* @param model - The model to save.
* @returns A Promise that resolves when the model has been saved.
*/
saveModel(model: Model): Promise<void>
/**
* Gets a list of downloaded models.
* @returns A Promise that resolves with an array of downloaded models.
*/
getDownloadedModels(): Promise<Model[]>
/**
* Gets a list of configured models.
* @returns A Promise that resolves with an array of configured models.
*/
getConfiguredModels(): Promise<Model[]>
}

View File

@ -0,0 +1 @@
export * from './monitoringInterface'

View File

@ -0,0 +1,17 @@
/**
* Monitoring extension for system monitoring.
* @extends BaseExtension
*/
export interface MonitoringInterface {
/**
* Returns information about the system resources.
* @returns {Promise<any>} A promise that resolves with the system resources information.
*/
getResourcesInfo(): Promise<any>
/**
* Returns the current system load.
* @returns {Promise<any>} A promise that resolves with the current system load.
*/
getCurrentLoad(): Promise<any>
}

View File

@ -0,0 +1,2 @@
export * from './threadEntity'
export * from './threadInterface'

View File

@ -0,0 +1,45 @@
import { ModelInfo } from '../model'
/**
* The `Thread` type defines the shape of a thread object.
* @stored
*/
export type Thread = {
/** Unique identifier for the thread, generated by default using the ULID method. **/
id: string
/** Object name **/
object: string
/** The title of this thread. **/
title: string
/** Assistants in this thread. **/
assistants: ThreadAssistantInfo[]
/** The timestamp indicating when this thread was created, represented in ISO 8601 format. **/
created: number
/** The timestamp indicating when this thread was updated, represented in ISO 8601 format. **/
updated: number
/** The additional metadata of this thread. **/
metadata?: Record<string, unknown>
}
/**
* Represents the information about an assistant in a thread.
* @stored
*/
export type ThreadAssistantInfo = {
assistant_id: string
assistant_name: string
model: ModelInfo
instructions?: string
}
/**
* Represents the state of a thread.
* @stored
*/
export type ThreadState = {
hasMore: boolean
waitingForResponse: boolean
error?: Error
lastMessage?: string
isFinishInit?: boolean
}

View File

@ -0,0 +1,31 @@
import { Thread } from './threadEntity'
/**
* Conversational extension. Persists and retrieves conversations.
* @abstract
* @extends BaseExtension
*/
export interface ThreadInterface {
/**
* Returns a list of thread.
* @abstract
* @returns {Promise<Thread[]>} A promise that resolves to an array of threads.
*/
getThreads(): Promise<Thread[]>
/**
* Saves a thread.
* @abstract
* @param {Thread} thread - The thread to save.
* @returns {Promise<void>} A promise that resolves when the thread is saved.
*/
saveThread(thread: Thread): Promise<void>
/**
* Deletes a thread.
* @abstract
* @param {string} threadId - The ID of the thread to delete.
* @returns {Promise<void>} A promise that resolves when the thread is deleted.
*/
deleteThread(threadId: string): Promise<void>
}