Skip to content

Commit

Permalink
refactor: model plugin to follow new specs
Browse files Browse the repository at this point in the history
Signed-off-by: James <james@jan.ai>
  • Loading branch information
James committed Nov 28, 2023
1 parent 9bf39cb commit edb4661
Show file tree
Hide file tree
Showing 61 changed files with 1,884 additions and 991 deletions.
20 changes: 20 additions & 0 deletions core/src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ const rmdir: (path: string) => Promise<any> = (path) =>
const deleteFile: (path: string) => Promise<any> = (path) =>
window.coreAPI?.deleteFile(path) ?? window.electronAPI?.deleteFile(path);

/**
* Appends data to a file at the specified path.
* @param path path to the file
* @param data data to append
*/
const appendFile: (path: string, data: string) => Promise<any> = (path, data) =>
window.coreAPI?.appendFile(path, data) ??
window.electronAPI?.appendFile(path, data);

const readLineByLine: (path: string) => Promise<any> = (path) =>
window.coreAPI?.readLineByLine(path) ??
window.electronAPI?.readLineByLine(path);

const openFileExplorer: (path: string) => Promise<any> = (path) =>
window.coreAPI?.openFileExplorer(path) ??
window.electronAPI?.openFileExplorer(path);

export const fs = {
isDirectory,
writeFile,
Expand All @@ -63,4 +80,7 @@ export const fs = {
mkdir,
rmdir,
deleteFile,
appendFile,
readLineByLine,
openFileExplorer,
};
1 change: 1 addition & 0 deletions core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum PluginType {
Preference = "preference",
SystemMonitoring = "systemMonitoring",
Model = "model",
Assistant = "assistant",
}

export abstract class JanPlugin {
Expand Down
14 changes: 14 additions & 0 deletions core/src/plugins/assistant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Assistant } from "../index";
import { JanPlugin } from "../plugin";

/**
* Abstract class for assistant plugins.
* @extends JanPlugin
*/
export abstract class AssistantPlugin extends JanPlugin {
abstract createAssistant(assistant: Assistant): Promise<void>;

abstract deleteAssistant(assistant: Assistant): Promise<void>;

abstract getAssistants(): Promise<Assistant[]>;
}
30 changes: 17 additions & 13 deletions core/src/plugins/conversational.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
import { Thread } from "../index";
import { Thread, ThreadMessage } from "../index";
import { JanPlugin } from "../plugin";

/**
* Abstract class for conversational plugins.
* Abstract class for Thread plugins.
* @abstract
* @extends JanPlugin
*/
export abstract class ConversationalPlugin extends JanPlugin {
/**
* Returns a list of conversations.
* Returns a list of thread.
* @abstract
* @returns {Promise<any[]>} A promise that resolves to an array of conversations.
* @returns {Promise<Thread[]>} A promise that resolves to an array of threads.
*/
abstract getConversations(): Promise<any[]>;
abstract getThreads(): Promise<Thread[]>;

/**
* Saves a conversation.
* Saves a thread.
* @abstract
* @param {Thread} conversation - The conversation to save.
* @returns {Promise<void>} A promise that resolves when the conversation is saved.
* @param {Thread} thread - The thread to save.
* @returns {Promise<void>} A promise that resolves when the thread is saved.
*/
abstract saveConversation(conversation: Thread): Promise<void>;
abstract saveThread(thread: Thread): Promise<void>;

/**
* Deletes a conversation.
* Deletes a thread.
* @abstract
* @param {string} conversationId - The ID of the conversation to delete.
* @returns {Promise<void>} A promise that resolves when the conversation is deleted.
* @param {string} threadId - The ID of the thread to delete.
* @returns {Promise<void>} A promise that resolves when the thread is deleted.
*/
abstract deleteConversation(conversationId: string): Promise<void>;
abstract deleteThread(threadId: string): Promise<void>;

abstract addNewMessage(message: ThreadMessage): Promise<void>;

abstract getAllMessages(threadId: string): Promise<ThreadMessage[]>;
}
5 changes: 5 additions & 0 deletions core/src/plugins/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export { InferencePlugin } from "./inference";
*/
export { MonitoringPlugin } from "./monitoring";

/**
* Assistant plugin for managing assistants.
*/
export { AssistantPlugin } from "./assistant";

/**
* Model plugin for managing models.
*/
Expand Down
6 changes: 3 additions & 3 deletions core/src/plugins/inference.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MessageRequest, ThreadMessage } from "../index";
import { MessageRequest, ModelSettingParams, ThreadMessage } from "../index";
import { JanPlugin } from "../plugin";

/**
Expand All @@ -7,9 +7,9 @@ import { JanPlugin } from "../plugin";
export abstract class InferencePlugin extends JanPlugin {
/**
* Initializes the model for the plugin.
* @param modelFileName - The name of the file containing the model.
* @param modelId - The ID of the model to initialize.
*/
abstract initModel(modelFileName: string): Promise<void>;
abstract initModel(modelId: string, settings?: ModelSettingParams): Promise<void>;

/**
* Stops the model for the plugin.
Expand Down
4 changes: 2 additions & 2 deletions core/src/plugins/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export abstract class ModelPlugin extends JanPlugin {

/**
* Deletes a model.
* @param filePath - The file path of the model to delete.
* @param modelId - The ID of the model to delete.
* @returns A Promise that resolves when the model has been deleted.
*/
abstract deleteModel(filePath: string): Promise<void>;
abstract deleteModel(modelId: string): Promise<void>;

/**
* Saves a model.
Expand Down
Loading

0 comments on commit edb4661

Please sign in to comment.