Skip to content

Conversation

@louis-jan
Copy link
Contributor

@louis-jan louis-jan commented Nov 15, 2023

Overview

This PR introduces a comprehensive refactor of the exported entities within our core module. The primary focus of these changes is to eliminate redundancy and duplication, as well as to improve the naming conventions used throughout our codebase.

NOTES: This is only to reduce the confusion of the entities currently present in the codebase, eliminating unnecessary attributes to facilitate easier updates for the upcoming API revamp

Changes

  • ChatCompletionRole: now clearly indicates the role of the author in a completion message.
  • ChatCompletionMessage: has been updated to define the shape of a new message request object. This is particularly used by assistants to structure message requests to the inference service.
  • MessageRequest: is redefined for clarity, representing the shape of a new message request object sent by the app to assistants.
  • ThreadMessage: A new struct for the message widely used in the app. Assistants send this object to the app for presentation, and the app persists it to the thread file.
  • Thread:A struct to represent the thread entity.
  • Model: This struct now represents a downloaded model and its version.
  • ModelCatalog & ModelVersion: These represent a remote model manifest. A model catalog contains many versions, providing a clearer structure for model management.

Notes:

  • The references and logic will be updated after the changes have been aligned
/**
 * Message Request and Response
 * ============================
 * */

/**
 * The role of the author of this message.
 * @data_transfer_object
 */
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;
  /** Messages for constructing a chat completion request **/
  messages?: ChatCompletionMessage[];
};

/**
 * 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;
  /** Thread id, default is a ulid. **/
  threadId?: string;
  /** The role of the author of this message. **/
  role?: ChatCompletionRole;
  /** The content of this message. **/
  content?: string;
  /** The status of this message. **/
  status: MessageStatus;
  /** The timestamp indicating when this message was created, represented in ISO 8601 format. **/
  createdAt?: 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;
  /** The summary of this thread. **/
  summary?: string;
  /** The messages of this thread. **/
  messages: ThreadMessage[];
  /** The timestamp indicating when this thread was created, represented in ISO 8601 format. **/
  createdAt?: string;
  /** The timestamp indicating when this thread was updated, represented in ISO 8601 format. **/
  updatedAt?: string;

  /**
   * @deprecated This field is deprecated and should not be used.
   * Read from model file instead.
   */
  modelId?: string;
}

/**
 * Model type defines the shape of a model object.
 * @stored
 */
export interface Model {
  /** Combination of owner and model name.*/
  id: string;
  /** The name of the model.*/
  name: string;
  /** Quantization method name.*/
  quantizationName: string;
  /** The the number of bits represents a number.*/
  bits: number;
  /** The size of the model file in bytes.*/
  size: number;
  /** The maximum RAM required to run the model in bytes.*/
  maxRamRequired: number;
  /** The use case of the model.*/
  usecase: string;
  /** The download link of the model.*/
  downloadLink: string;
  /** The short description of the model.*/
  shortDescription: string;
  /** The long description of the model.*/
  longDescription: string;
  /** The avatar url of the model.*/
  avatarUrl: string;
  /** The author name of the model.*/
  author: string;
  /** The version of the model.*/
  version: string;
  /** The origin url of the model repo.*/
  modelUrl: string;
  /** The timestamp indicating when this model was released.*/
  releaseDate: number;
  /** The tags attached to the model description */
  tags: string[];
}

/**
 * Model type of the presentation object which will be presented to the user
 * @data_transfer_object
 */
export interface ModelCatalog {
  /** The unique id of the model.*/
  id: string;
  /** The name of the model.*/
  name: string;
  /** The avatar url of the model.*/
  avatarUrl: string;
  /** The short description of the model.*/
  shortDescription: string;
  /** The long description of the model.*/
  longDescription: string;
  /** The author name of the model.*/
  author: string;
  /** The version of the model.*/
  version: string;
  /** The origin url of the model repo.*/
  modelUrl: string;
  /** The timestamp indicating when this model was released.*/
  releaseDate: number;
  /** The tags attached to the model description **/
  tags: string[];

  /** The available versions of this model to download. */
  availableVersions: ModelVersion[];
}
/**
 * Model type which will be present a version of ModelCatalog
 * @data_transfer_object
 */
export type ModelVersion = {
  /** The name of this model version.*/
  name: string;
  /** The quantization method name.*/
  quantizationName: string;
  /** The the number of bits represents a number.*/
  bits: number;
  /** The size of the model file in bytes.*/
  size: number;
  /** The maximum RAM required to run the model in bytes.*/
  maxRamRequired: number;
  /** The use case of the model.*/
  usecase: string;
  /** The download link of the model.*/
  downloadLink: string;
};

Removed:

  • MessageRequest:
    • user
    • avata
    • message
    • createdAt
    • updatedAt
  • ThreadMessage (MessageResponse):
    • user
    • avatar
    • updatedAt
  • Thread(Conversation):
    • botId
    • name
    • message
    • lastMessage
  • Model:
    • modelFile
    • startDownloadAt
    • finishDownloadAt
    • productId
    • productName
    • createdAt
    • updatedAt
    • status
  • ModelCatalog:
    • createdAt
    • updatedAt
    • status
  • ModelVersion:
    • id
    • productId
    • startDownloadAt
    • finishDownloadAt
  • MessageType { * }

Fixes: #614

@louis-jan louis-jan force-pushed the chore/614-refactor-entities branch from 6dcbd2d to d48c3aa Compare November 15, 2023 09:42
@louis-jan louis-jan requested review from a team, namchuai and urmauur November 15, 2023 09:43
@namchuai namchuai force-pushed the feat/move-files-to-jan-root branch 3 times, most recently from 4472ef2 to 8c3d17e Compare November 15, 2023 15:40
@louis-jan louis-jan force-pushed the chore/614-refactor-entities branch from d48c3aa to 26c83c7 Compare November 16, 2023 02:41
Base automatically changed from feat/move-files-to-jan-root to main November 16, 2023 05:09
@louis-jan louis-jan force-pushed the chore/614-refactor-entities branch from 26c83c7 to 38c591f Compare November 16, 2023 05:48
@louis-jan louis-jan marked this pull request as ready for review November 16, 2023 13:16
@louis-jan louis-jan changed the title refactor: exported entities in core module refactor: refactor app entities Nov 16, 2023
@louis-jan louis-jan merged commit b60978b into main Nov 16, 2023
@louis-jan louis-jan deleted the chore/614-refactor-entities branch November 16, 2023 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

chore: refactor data structure

4 participants