From de562ecaedadcfa53a7dea7b176aea4eef7bb852 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 21 Nov 2023 13:47:30 +0700 Subject: [PATCH] chore: add stopping inference interface --- core/src/plugins/inference.ts | 9 +++++++-- plugins/inference-plugin/src/index.ts | 20 ++++++++++++++------ web/hooks/useSendChatMessage.ts | 8 ++++---- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/core/src/plugins/inference.ts b/core/src/plugins/inference.ts index 663d0b258..6fc93ed37 100644 --- a/core/src/plugins/inference.ts +++ b/core/src/plugins/inference.ts @@ -1,4 +1,4 @@ -import { MessageRequest } from "../index"; +import { MessageRequest, ThreadMessage } from "../index"; import { JanPlugin } from "../plugin"; /** @@ -16,10 +16,15 @@ export abstract class InferencePlugin extends JanPlugin { */ abstract stopModel(): Promise; + /** + * Stops the streaming inference. + */ + abstract stopInference(): Promise; + /** * Processes an inference request. * @param data - The data for the inference request. * @returns The result of the inference request. */ - abstract inferenceRequest(data: MessageRequest): Promise; + abstract inferenceRequest(data: MessageRequest): Promise; } diff --git a/plugins/inference-plugin/src/index.ts b/plugins/inference-plugin/src/index.ts index 8cabf0343..0a02d4de0 100644 --- a/plugins/inference-plugin/src/index.ts +++ b/plugins/inference-plugin/src/index.ts @@ -70,23 +70,31 @@ export default class JanInferencePlugin implements InferencePlugin { return executeOnMain(MODULE, "killSubprocess"); } + /** + * Stops streaming inference. + * @returns {Promise} A promise that resolves when the streaming is stopped. + */ + async stopInference(): Promise { + // TODO: Implementation + } + /** * Makes a single response inference request. * @param {MessageRequest} data - The data for the inference request. * @returns {Promise} A promise that resolves with the inference response. */ - async inferenceRequest(data: MessageRequest): Promise { - const message = { - ...data, - message: "", - user: "assistant", + async inferenceRequest(data: MessageRequest): Promise { + const message: ThreadMessage = { + threadId: data.threadId, + content: "", createdAt: new Date().toISOString(), + status: MessageStatus.Ready, }; return new Promise(async (resolve, reject) => { requestInference(data.messages ?? []).subscribe({ next: (content) => { - message.message = content; + message.content = content; }, complete: async () => { resolve(message); diff --git a/web/hooks/useSendChatMessage.ts b/web/hooks/useSendChatMessage.ts index 12f54abd0..7a3b71ea5 100644 --- a/web/hooks/useSendChatMessage.ts +++ b/web/hooks/useSendChatMessage.ts @@ -63,13 +63,13 @@ export default function useSendChatMessage() { if ( currentConvo && currentConvo.id === newMessage.threadId && - result?.message && - result?.message?.trim().length > 0 && - result.message.split(' ').length <= 10 + result?.content && + result?.content?.trim().length > 0 && + result.content.split(' ').length <= 10 ) { const updatedConv = { ...currentConvo, - summary: result.message, + summary: result.content, } updateConversation(updatedConv) pluginManager