From 7a739e567c19c3371c25446c9e7a7b52b50948c9 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Fri, 18 Apr 2025 04:44:14 -0700 Subject: [PATCH] prepare retry loop --- .../void/common/sendLLMMessageService.ts | 35 ++++++++++++++----- .../llmMessage/sendLLMMessage.impl.ts | 1 + .../electron-main/sendLLMMessageChannel.ts | 15 +++++--- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/contrib/void/common/sendLLMMessageService.ts b/src/vs/workbench/contrib/void/common/sendLLMMessageService.ts index e3656f99..7579cfec 100644 --- a/src/vs/workbench/contrib/void/common/sendLLMMessageService.ts +++ b/src/vs/workbench/contrib/void/common/sendLLMMessageService.ts @@ -70,14 +70,31 @@ export class LLMMessageService extends Disposable implements ILLMMessageService // .listen sets up an IPC channel and takes a few ms, so we set up listeners immediately and add hooks to them instead // llm - this._register((this.channel.listen('onText_sendLLMMessage') satisfies Event)(e => { this.llmMessageHooks.onText[e.requestId]?.(e) })) - this._register((this.channel.listen('onFinalMessage_sendLLMMessage') satisfies Event)(e => { this.llmMessageHooks.onFinalMessage[e.requestId]?.(e); this._clearChannelHooks(e.requestId) })) - this._register((this.channel.listen('onError_sendLLMMessage') satisfies Event)(e => { this.llmMessageHooks.onError[e.requestId]?.(e); this._clearChannelHooks(e.requestId); console.error('Error in LLMMessageService:', JSON.stringify(e)) })) - // ollama .list() - this._register((this.channel.listen('onSuccess_list_ollama') satisfies Event>)(e => { this.listHooks.ollama.success[e.requestId]?.(e) })) - this._register((this.channel.listen('onError_list_ollama') satisfies Event>)(e => { this.listHooks.ollama.error[e.requestId]?.(e) })) - this._register((this.channel.listen('onSuccess_list_openAICompatible') satisfies Event>)(e => { this.listHooks.openAICompat.success[e.requestId]?.(e) })) - this._register((this.channel.listen('onError_list_openAICompatible') satisfies Event>)(e => { this.listHooks.openAICompat.error[e.requestId]?.(e) })) + this._register((this.channel.listen('onText_sendLLMMessage') satisfies Event)(e => { + this.llmMessageHooks.onText[e.requestId]?.(e) + })) + this._register((this.channel.listen('onFinalMessage_sendLLMMessage') satisfies Event)(e => { + this.llmMessageHooks.onFinalMessage[e.requestId]?.(e); + this._clearChannelHooks(e.requestId) + })) + this._register((this.channel.listen('onError_sendLLMMessage') satisfies Event)(e => { + this.llmMessageHooks.onError[e.requestId]?.(e); + this._clearChannelHooks(e.requestId); + console.error('Error in LLMMessageService:', JSON.stringify(e)) + })) + // .list() + this._register((this.channel.listen('onSuccess_list_ollama') satisfies Event>)(e => { + this.listHooks.ollama.success[e.requestId]?.(e) + })) + this._register((this.channel.listen('onError_list_ollama') satisfies Event>)(e => { + this.listHooks.ollama.error[e.requestId]?.(e) + })) + this._register((this.channel.listen('onSuccess_list_openAICompatible') satisfies Event>)(e => { + this.listHooks.openAICompat.success[e.requestId]?.(e) + })) + this._register((this.channel.listen('onError_list_openAICompatible') satisfies Event>)(e => { + this.listHooks.openAICompat.error[e.requestId]?.(e) + })) } @@ -160,7 +177,7 @@ export class LLMMessageService extends Disposable implements ILLMMessageService } satisfies MainModelListParams) } - _clearChannelHooks(requestId: string) { + private _clearChannelHooks(requestId: string) { delete this.llmMessageHooks.onText[requestId] delete this.llmMessageHooks.onFinalMessage[requestId] delete this.llmMessageHooks.onError[requestId] diff --git a/src/vs/workbench/contrib/void/electron-main/llmMessage/sendLLMMessage.impl.ts b/src/vs/workbench/contrib/void/electron-main/llmMessage/sendLLMMessage.impl.ts index 5f4e013c..6cf66205 100644 --- a/src/vs/workbench/contrib/void/electron-main/llmMessage/sendLLMMessage.impl.ts +++ b/src/vs/workbench/contrib/void/electron-main/llmMessage/sendLLMMessage.impl.ts @@ -539,6 +539,7 @@ const sendMistralFIM = ({ messages, onFinalMessage, onError, settingsOfProvider, stop: messages.stopTokens, }) .then(async response => { + // unfortunately, _setAborter() does not exist let content = response?.ok ? response.value.choices?.[0]?.message?.content ?? '' : ''; const fullText = typeof content === 'string' ? content : content.map(chunk => (chunk.type === 'text' ? chunk.text : '')).join('') diff --git a/src/vs/workbench/contrib/void/electron-main/sendLLMMessageChannel.ts b/src/vs/workbench/contrib/void/electron-main/sendLLMMessageChannel.ts index ce1b9fbe..bff528ce 100644 --- a/src/vs/workbench/contrib/void/electron-main/sendLLMMessageChannel.ts +++ b/src/vs/workbench/contrib/void/electron-main/sendLLMMessageChannel.ts @@ -90,7 +90,7 @@ export class LLMMessageChannel implements IServerChannel { } // the only place sendLLMMessage is actually called - private async _callSendLLMMessage(params: MainSendLLMMessageParams) { + private _callSendLLMMessage(params: MainSendLLMMessageParams) { const { requestId } = params; if (!(requestId in this._infoOfRunningRequest)) @@ -98,9 +98,16 @@ export class LLMMessageChannel implements IServerChannel { const mainThreadParams: SendLLMMessageParams = { ...params, - onText: (p) => { this.llmMessageEmitters.onText.fire({ requestId, ...p }); }, - onFinalMessage: (p) => { this.llmMessageEmitters.onFinalMessage.fire({ requestId, ...p }); }, - onError: (p) => { console.log('sendLLM: firing err'); this.llmMessageEmitters.onError.fire({ requestId, ...p }); }, + onText: (p) => { + this.llmMessageEmitters.onText.fire({ requestId, ...p }); + }, + onFinalMessage: (p) => { + this.llmMessageEmitters.onFinalMessage.fire({ requestId, ...p }); + }, + onError: (p) => { + console.log('sendLLM: firing err'); + this.llmMessageEmitters.onError.fire({ requestId, ...p }); + }, abortRef: this._infoOfRunningRequest[requestId].abortRef, } const p = sendLLMMessage(mainThreadParams, this.metricsService);