proxy to node appears to work!!

This commit is contained in:
Andrew Pareles 2024-11-24 20:39:15 -08:00
parent 9ef1aa2c60
commit aa95ceafd2
5 changed files with 43 additions and 35 deletions

View file

@ -179,7 +179,7 @@ export const SidebarChat = () => {
const [latestError, setLatestError] = useState<Error | string | null>(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),

View file

@ -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)

View file

@ -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);
});

View file

@ -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<ISendLLMMessageService>(mainProcessService.getChannel('sendLLMMessage'));
}
sendLLMMessage(data: any): Promise<any> {
return this._proxySendLLMService.sendLLMMessage(data);
sendLLMMessage(params: SendLLMMessageParams) {
this._proxySendLLMService.sendLLMMessage(params);
}
}

View file

@ -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<ISendLLMMessageService>('sendLLMMessageService');
@ -8,7 +37,7 @@ export const ISendLLMMessageService = createDecorator<ISendLLMMessageService>('s
export interface ISendLLMMessageService {
readonly _serviceBrand: undefined;
sendLLMMessage(data: any): Promise<any>;
sendLLMMessage: (params: SendLLMMessageParams) => void;
}