Skip to content

Commit

Permalink
proxy to node appears to work!!
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpareles committed Nov 25, 2024
1 parent 9ef1aa2 commit aa95cea
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const SidebarChat = () => {

const [latestError, setLatestError] = useState<Error | string | null>(null)


const sendLLMMessageService = useService('sendLLMMessageService')

const isDisabled = !instructions

Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -275,15 +276,15 @@ const sendGreptileMsg: SendLLMMessageFnTypeInternal = ({ messages, onText, onFin



export const sendLLMMessage: SendLLMMessageFnType = ({
export const sendLLMMessage = ({
messages,
onText: onText_,
onFinalMessage: onFinalMessage_,
onError: onError_,
abortRef: abortRef_,
voidConfig,
logging: { loggingName }
}) => {
}: SendLLMMessageParams) => {
if (!voidConfig) return;

// trim message content (Anthropic and other providers give an error if there is trailing whitespace)
Expand Down
3 changes: 3 additions & 0 deletions src/vs/workbench/contrib/void/browser/registerSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';


Expand All @@ -65,6 +66,7 @@ export type ReactServicesType = {
fileService: IFileService;
modelService: IModelService;
inlineDiffService: IInlineDiffsService;
sendLLMMessageService: ISendLLMMessageService;
}

// ---------- Define viewpane ----------
Expand Down Expand Up @@ -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);
});
Expand Down
31 changes: 3 additions & 28 deletions src/vs/workbench/services/void/browser/sendLLMMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -50,8 +25,8 @@ export class SendLLMMessageService implements ISendLLMMessageService {
this._proxySendLLMService = ProxyChannel.toService<ISendLLMMessageService>(mainProcessService.getChannel('sendLLMMessage'));
}

sendLLMMessage(data: any): Promise<any> {
return this._proxySendLLMService.sendLLMMessage(data);
sendLLMMessage(params: SendLLMMessageParams) {
this._proxySendLLMService.sendLLMMessage(params);
}
}

Expand Down
33 changes: 31 additions & 2 deletions src/vs/workbench/services/void/common/sendLLMMessage.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
// 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<ISendLLMMessageService>('sendLLMMessageService');

// defines an interface that node/ creates and browser/ uses
export interface ISendLLMMessageService {
readonly _serviceBrand: undefined;

sendLLMMessage(data: any): Promise<any>;
}
sendLLMMessage: (params: SendLLMMessageParams) => void;

}

0 comments on commit aa95cea

Please sign in to comment.