refactor: change types and interfaces only
This commit is contained in:
parent
89d73e7f30
commit
db2ccc112b
@ -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.
|
||||
*/
|
||||
export enum EventName {
|
||||
/** The `OnMessageSent` event is emitted when a message is sent. */
|
||||
OnMessageSent = "OnMessageSent",
|
||||
OnMessageSent = 'OnMessageSent',
|
||||
/** The `OnMessageResponse` event is emitted when a message is received. */
|
||||
OnMessageResponse = "OnMessageResponse",
|
||||
OnMessageResponse = 'OnMessageResponse',
|
||||
/** The `OnMessageUpdate` event is emitted when a message is updated. */
|
||||
OnMessageUpdate = "OnMessageUpdate",
|
||||
OnMessageUpdate = 'OnMessageUpdate',
|
||||
/** The `OnModelInit` event is emitted when a model inits. */
|
||||
OnModelInit = "OnModelInit",
|
||||
OnModelInit = 'OnModelInit',
|
||||
/** The `OnModelReady` event is emitted when a model ready. */
|
||||
OnModelReady = "OnModelReady",
|
||||
OnModelReady = 'OnModelReady',
|
||||
/** 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. */
|
||||
OnModelStop = "OnModelStop",
|
||||
OnModelStop = 'OnModelStop',
|
||||
/** The `OnModelStopped` event is emitted when a model stopped ok. */
|
||||
OnModelStopped = "OnModelStopped",
|
||||
OnModelStopped = 'OnModelStopped',
|
||||
/** 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 handler The handler function to call when the event is observed.
|
||||
*/
|
||||
const on: (eventName: string, handler: Function) => void = (
|
||||
eventName,
|
||||
handler
|
||||
) => {
|
||||
global.core?.events?.on(eventName, handler);
|
||||
};
|
||||
const on: (eventName: string, handler: Function) => void = (eventName, handler) => {
|
||||
global.core?.events?.on(eventName, handler)
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 handler The handler function to call when the event is observed.
|
||||
*/
|
||||
const off: (eventName: string, handler: Function) => void = (
|
||||
eventName,
|
||||
handler
|
||||
) => {
|
||||
global.core?.events?.off(eventName, handler);
|
||||
};
|
||||
const off: (eventName: string, handler: Function) => void = (eventName, handler) => {
|
||||
global.core?.events?.off(eventName, handler)
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits an event.
|
||||
@ -55,11 +50,11 @@ const off: (eventName: string, handler: Function) => void = (
|
||||
* @param object The object to pass to the event callback.
|
||||
*/
|
||||
const emit: (eventName: string, object: any) => void = (eventName, object) => {
|
||||
global.core?.events?.emit(eventName, object);
|
||||
};
|
||||
global.core?.events?.emit(eventName, object)
|
||||
}
|
||||
|
||||
export const events = {
|
||||
on,
|
||||
off,
|
||||
emit,
|
||||
};
|
||||
}
|
||||
|
||||
@ -1,28 +1,12 @@
|
||||
import { Assistant } from "../index";
|
||||
import { BaseExtension } from "../extension";
|
||||
import { Assistant, AssistantInterface } from '../index'
|
||||
import { BaseExtension } from '../extension'
|
||||
|
||||
/**
|
||||
* Assistant extension for managing assistants.
|
||||
* @extends BaseExtension
|
||||
*/
|
||||
export abstract class AssistantExtension extends BaseExtension {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
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[]>;
|
||||
export abstract class AssistantExtension extends BaseExtension implements AssistantInterface {
|
||||
abstract createAssistant(assistant: Assistant): Promise<void>
|
||||
abstract deleteAssistant(assistant: Assistant): Promise<void>
|
||||
abstract getAssistants(): Promise<Assistant[]>
|
||||
}
|
||||
|
||||
@ -1,57 +1,19 @@
|
||||
import { Thread, ThreadMessage } from "../index";
|
||||
import { BaseExtension } from "../extension";
|
||||
import { Thread, ThreadInterface, ThreadMessage, MessageInterface } from '../index'
|
||||
import { BaseExtension } from '../extension'
|
||||
|
||||
/**
|
||||
* Conversational extension. Persists and retrieves conversations.
|
||||
* @abstract
|
||||
* @extends BaseExtension
|
||||
*/
|
||||
export abstract class ConversationalExtension extends BaseExtension {
|
||||
/**
|
||||
* Returns a list of thread.
|
||||
* @abstract
|
||||
* @returns {Promise<Thread[]>} A promise that resolves to an array of threads.
|
||||
*/
|
||||
abstract 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.
|
||||
*/
|
||||
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[]>;
|
||||
export abstract class ConversationalExtension
|
||||
extends BaseExtension
|
||||
implements ThreadInterface, MessageInterface
|
||||
{
|
||||
abstract getThreads(): Promise<Thread[]>
|
||||
abstract saveThread(thread: Thread): Promise<void>
|
||||
abstract deleteThread(threadId: string): Promise<void>
|
||||
abstract addNewMessage(message: ThreadMessage): Promise<void>
|
||||
abstract writeMessages(threadId: string, messages: ThreadMessage[]): Promise<void>
|
||||
abstract getAllMessages(threadId: string): Promise<ThreadMessage[]>
|
||||
}
|
||||
|
||||
@ -1,14 +1,9 @@
|
||||
import { MessageRequest, ModelSettingParams, ThreadMessage } from "../index";
|
||||
import { BaseExtension } from "../extension";
|
||||
import { InferenceInterface, MessageRequest, ThreadMessage } from '../index'
|
||||
import { BaseExtension } from '../extension'
|
||||
|
||||
/**
|
||||
* Inference extension. Start, stop and inference models.
|
||||
*/
|
||||
export abstract class InferenceExtension extends BaseExtension {
|
||||
/**
|
||||
* 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>;
|
||||
export abstract class InferenceExtension extends BaseExtension implements InferenceInterface {
|
||||
abstract inference(data: MessageRequest): Promise<ThreadMessage>
|
||||
}
|
||||
|
||||
@ -1,47 +1,14 @@
|
||||
import { BaseExtension } from "../extension";
|
||||
import { Model } from "../types/index";
|
||||
import { BaseExtension } from '../extension'
|
||||
import { Model, ModelInterface } from '../index'
|
||||
|
||||
/**
|
||||
* Model extension for managing models.
|
||||
*/
|
||||
export abstract class ModelExtension extends BaseExtension {
|
||||
/**
|
||||
* Downloads a model.
|
||||
* @param model - The model to download.
|
||||
* @returns A Promise that resolves when the model has been downloaded.
|
||||
*/
|
||||
abstract 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.
|
||||
*/
|
||||
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[]>;
|
||||
export abstract class ModelExtension extends BaseExtension implements ModelInterface {
|
||||
abstract downloadModel(model: Model): Promise<void>
|
||||
abstract cancelModelDownload(modelId: string): Promise<void>
|
||||
abstract deleteModel(modelId: string): Promise<void>
|
||||
abstract saveModel(model: Model): Promise<void>
|
||||
abstract getDownloadedModels(): Promise<Model[]>
|
||||
abstract getConfiguredModels(): Promise<Model[]>
|
||||
}
|
||||
|
||||
@ -1,19 +1,11 @@
|
||||
import { BaseExtension } from "../extension";
|
||||
import { BaseExtension } from '../extension'
|
||||
import { MonitoringInterface } from '../index'
|
||||
|
||||
/**
|
||||
* Monitoring extension for system monitoring.
|
||||
* @extends BaseExtension
|
||||
*/
|
||||
export abstract class MonitoringExtension extends BaseExtension {
|
||||
/**
|
||||
* Returns information about the system resources.
|
||||
* @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>;
|
||||
export abstract class MonitoringExtension extends BaseExtension implements MonitoringInterface {
|
||||
abstract getResourcesInfo(): Promise<any>
|
||||
abstract getCurrentLoad(): Promise<any>
|
||||
}
|
||||
|
||||
30
core/src/types/assistant/assistantEntity.ts
Normal file
30
core/src/types/assistant/assistantEntity.ts
Normal 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>
|
||||
}
|
||||
26
core/src/types/assistant/assistantInterface.ts
Normal file
26
core/src/types/assistant/assistantInterface.ts
Normal 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[]>
|
||||
}
|
||||
2
core/src/types/assistant/index.ts
Normal file
2
core/src/types/assistant/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './assistantEntity'
|
||||
export * from './assistantInterface'
|
||||
@ -1,328 +1,6 @@
|
||||
/**
|
||||
* Message Request and Response
|
||||
* ============================
|
||||
* */
|
||||
|
||||
/**
|
||||
* 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>;
|
||||
};
|
||||
export * from './assistant'
|
||||
export * from './model'
|
||||
export * from './thread'
|
||||
export * from './message'
|
||||
export * from './inference'
|
||||
export * from './monitoring'
|
||||
|
||||
3
core/src/types/inference/index.ts
Normal file
3
core/src/types/inference/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './inferenceEntity'
|
||||
export * from './inferenceInterface'
|
||||
export * from './inferenceEvent'
|
||||
19
core/src/types/inference/inferenceEntity.ts
Normal file
19
core/src/types/inference/inferenceEntity.ts
Normal 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
|
||||
}
|
||||
7
core/src/types/inference/inferenceEvent.ts
Normal file
7
core/src/types/inference/inferenceEvent.ts
Normal 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',
|
||||
}
|
||||
13
core/src/types/inference/inferenceInterface.ts
Normal file
13
core/src/types/inference/inferenceInterface.ts
Normal 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>
|
||||
}
|
||||
3
core/src/types/message/index.ts
Normal file
3
core/src/types/message/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './messageEntity'
|
||||
export * from './messageInterface'
|
||||
export * from './messageEvent'
|
||||
88
core/src/types/message/messageEntity.ts
Normal file
88
core/src/types/message/messageEntity.ts
Normal 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
|
||||
}
|
||||
8
core/src/types/message/messageEvent.ts
Normal file
8
core/src/types/message/messageEvent.ts
Normal 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',
|
||||
}
|
||||
30
core/src/types/message/messageInterface.ts
Normal file
30
core/src/types/message/messageInterface.ts
Normal 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[]>
|
||||
}
|
||||
3
core/src/types/model/index.ts
Normal file
3
core/src/types/model/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './modelEntity'
|
||||
export * from './modelInterface'
|
||||
export * from './modelEvent'
|
||||
140
core/src/types/model/modelEntity.ts
Normal file
140
core/src/types/model/modelEntity.ts
Normal 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
|
||||
}
|
||||
15
core/src/types/model/modelEvent.ts
Normal file
15
core/src/types/model/modelEvent.ts
Normal 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',
|
||||
}
|
||||
46
core/src/types/model/modelInterface.ts
Normal file
46
core/src/types/model/modelInterface.ts
Normal 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[]>
|
||||
}
|
||||
1
core/src/types/monitoring/index.ts
Normal file
1
core/src/types/monitoring/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './monitoringInterface'
|
||||
17
core/src/types/monitoring/monitoringInterface.ts
Normal file
17
core/src/types/monitoring/monitoringInterface.ts
Normal 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>
|
||||
}
|
||||
2
core/src/types/thread/index.ts
Normal file
2
core/src/types/thread/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './threadEntity'
|
||||
export * from './threadInterface'
|
||||
45
core/src/types/thread/threadEntity.ts
Normal file
45
core/src/types/thread/threadEntity.ts
Normal 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
|
||||
}
|
||||
31
core/src/types/thread/threadInterface.ts
Normal file
31
core/src/types/thread/threadInterface.ts
Normal 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>
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user