From aa95ceafd2c801be2cd473580af6ff868e85f392 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Sun, 24 Nov 2024 20:39:15 -0800 Subject: [PATCH] proxy to node appears to work!! --- .../react/src/sidebar-tsx/SidebarChat.tsx | 4 +-- .../browser/react/src/util/sendLLMMessage.tsx | 7 ++-- .../contrib/void/browser/registerSidebar.ts | 3 ++ .../services/void/browser/sendLLMMessage.ts | 31 ++--------------- .../services/void/common/sendLLMMessage.ts | 33 +++++++++++++++++-- 5 files changed, 43 insertions(+), 35 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index 888a3357..a3b8d35a 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -179,7 +179,7 @@ export const SidebarChat = () => { const [latestError, setLatestError] = useState(null) - + const sendLLMMessageService = useService('sendLLMMessageService') const isDisabled = !instructions @@ -210,7 +210,7 @@ export const SidebarChat = () => { // send message to LLM - sendLLMMessage({ + sendLLMMessageService.sendLLMMessage({ logging: { loggingName: 'Chat' }, messages: [...(currentThread?.messages ?? []).map(m => ({ role: m.role, content: m.content })),], onText: (newText, fullText) => setMessageStream(fullText), diff --git a/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx b/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx index 7430db42..3f37ca94 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/util/sendLLMMessage.tsx @@ -4,7 +4,8 @@ import { Ollama } from 'ollama/browser' import { Content, GoogleGenerativeAI, GoogleGenerativeAIFetchError } from '@google/generative-ai'; import { posthog } from 'posthog-js' import type { VoidConfig } from '../../../registerConfig.js'; -import type { LLMMessage, LLMMessageOnText, OnFinalMessage, SendLLMMessageFnType, } from '../../../../../../services/void/browser/sendLLMMessage.js'; +import type { LLMMessage, LLMMessageOnText, OnFinalMessage, } from '../../../../../../services/void/common/sendLLMMessage.js'; +import { SendLLMMessageParams } from '../../../../../../services/void/common/sendLLMMessage.js'; type SendLLMMessageFnTypeInternal = (params: { messages: LLMMessage[]; @@ -275,7 +276,7 @@ const sendGreptileMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFin -export const sendLLMMessage: SendLLMMessageFnType = ({ +export const sendLLMMessage = ({ messages, onText: onText_, onFinalMessage: onFinalMessage_, @@ -283,7 +284,7 @@ export const sendLLMMessage: SendLLMMessageFnType = ({ abortRef: abortRef_, voidConfig, logging: { loggingName } -}) => { +}: SendLLMMessageParams) => { if (!voidConfig) return; // trim message content (Anthropic and other providers give an error if there is trailing whitespace) diff --git a/src/vs/workbench/contrib/void/browser/registerSidebar.ts b/src/vs/workbench/contrib/void/browser/registerSidebar.ts index f3b53d82..f5447ba2 100644 --- a/src/vs/workbench/contrib/void/browser/registerSidebar.ts +++ b/src/vs/workbench/contrib/void/browser/registerSidebar.ts @@ -47,6 +47,7 @@ import { IVoidConfigStateService } from './registerConfig.js'; import { IFileService } from '../../../../platform/files/common/files.js'; import { IInlineDiffsService } from './registerInlineDiffs.js'; import { IModelService } from '../../../../editor/common/services/model.js'; +import { ISendLLMMessageService } from '../../../services/void/common/sendLLMMessage.js'; // import { IClipboardService } from '../../../../platform/clipboard/common/clipboardService.js'; @@ -65,6 +66,7 @@ export type ReactServicesType = { fileService: IFileService; modelService: IModelService; inlineDiffService: IInlineDiffsService; + sendLLMMessageService: ISendLLMMessageService; } // ---------- Define viewpane ---------- @@ -109,6 +111,7 @@ class VoidSidebarViewPane extends ViewPane { fileService: accessor.get(IFileService), modelService: accessor.get(IModelService), inlineDiffService: accessor.get(IInlineDiffsService), + sendLLMMessageService: accessor.get(ISendLLMMessageService), } mountFn(root, services); }); diff --git a/src/vs/workbench/services/void/browser/sendLLMMessage.ts b/src/vs/workbench/services/void/browser/sendLLMMessage.ts index 44b12b83..6b7cf2f9 100644 --- a/src/vs/workbench/services/void/browser/sendLLMMessage.ts +++ b/src/vs/workbench/services/void/browser/sendLLMMessage.ts @@ -3,36 +3,11 @@ * Void Editor additions licensed under the AGPLv3 License. *--------------------------------------------------------------------------------------------*/ -import { VoidConfig } from '../../../contrib/void/browser/registerConfig.js'; -import { ISendLLMMessageService } from '../common/sendLLMMessage.js'; +import { ISendLLMMessageService, SendLLMMessageParams } from '../common/sendLLMMessage.js'; import { ProxyChannel } from '../../../../base/parts/ipc/common/ipc.js'; import { IMainProcessService } from '../../../../platform/ipc/common/mainProcessService.js'; import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js'; -export type LLMMessageAbortRef = { current: (() => void) | null } - -export type LLMMessageOnText = (newText: string, fullText: string) => void - -export type OnFinalMessage = (input: string) => void - -export type LLMMessage = { - role: 'system' | 'user' | 'assistant'; - content: string; -} - -export type SendLLMMessageFnType = (params: { - messages: LLMMessage[]; - onText: LLMMessageOnText; - onFinalMessage: (fullText: string) => void; - onError: (error: Error | string) => void; - voidConfig: VoidConfig | null; - abortRef: LLMMessageAbortRef; - - logging: { - loggingName: string, - }; -}) => void - // BROWSER IMPLEMENTATION OF SENDLLMMESSAGE // Uses a proxy to the actual Node implementation of SendLLMMessageService @@ -50,8 +25,8 @@ export class SendLLMMessageService implements ISendLLMMessageService { this._proxySendLLMService = ProxyChannel.toService(mainProcessService.getChannel('sendLLMMessage')); } - sendLLMMessage(data: any): Promise { - return this._proxySendLLMService.sendLLMMessage(data); + sendLLMMessage(params: SendLLMMessageParams) { + this._proxySendLLMService.sendLLMMessage(params); } } diff --git a/src/vs/workbench/services/void/common/sendLLMMessage.ts b/src/vs/workbench/services/void/common/sendLLMMessage.ts index c4c45605..f50f4611 100644 --- a/src/vs/workbench/services/void/common/sendLLMMessage.ts +++ b/src/vs/workbench/services/void/common/sendLLMMessage.ts @@ -1,6 +1,35 @@ // void/common/sendLLMMessage.ts import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js'; +import { VoidConfig } from '../../../contrib/void/browser/registerConfig.js'; + + + +export type LLMMessageAbortRef = { current: (() => void) | null } + +export type LLMMessageOnText = (newText: string, fullText: string) => void + +export type OnFinalMessage = (input: string) => void + +export type LLMMessage = { + role: 'system' | 'user' | 'assistant'; + content: string; +} + +export type SendLLMMessageParams = { + messages: LLMMessage[]; + onText: LLMMessageOnText; + onFinalMessage: (fullText: string) => void; + onError: (error: Error | string) => void; + voidConfig: VoidConfig | null; + abortRef: LLMMessageAbortRef; + + logging: { + loggingName: string, + }; +} + + export const ISendLLMMessageService = createDecorator('sendLLMMessageService'); @@ -8,7 +37,7 @@ export const ISendLLMMessageService = createDecorator('s export interface ISendLLMMessageService { readonly _serviceBrand: undefined; - sendLLMMessage(data: any): Promise; + sendLLMMessage: (params: SendLLMMessageParams) => void; + } -