mirror of
https://github.com/voideditor/void
synced 2026-05-23 09:28:23 +00:00
prepare retry loop
This commit is contained in:
parent
ef52ebfdc2
commit
7a739e567c
3 changed files with 38 additions and 13 deletions
|
|
@ -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<EventLLMMessageOnTextParams>)(e => { this.llmMessageHooks.onText[e.requestId]?.(e) }))
|
||||
this._register((this.channel.listen('onFinalMessage_sendLLMMessage') satisfies Event<EventLLMMessageOnFinalMessageParams>)(e => { this.llmMessageHooks.onFinalMessage[e.requestId]?.(e); this._clearChannelHooks(e.requestId) }))
|
||||
this._register((this.channel.listen('onError_sendLLMMessage') satisfies Event<EventLLMMessageOnErrorParams>)(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<EventModelListOnSuccessParams<OllamaModelResponse>>)(e => { this.listHooks.ollama.success[e.requestId]?.(e) }))
|
||||
this._register((this.channel.listen('onError_list_ollama') satisfies Event<EventModelListOnErrorParams<OllamaModelResponse>>)(e => { this.listHooks.ollama.error[e.requestId]?.(e) }))
|
||||
this._register((this.channel.listen('onSuccess_list_openAICompatible') satisfies Event<EventModelListOnSuccessParams<OpenaiCompatibleModelResponse>>)(e => { this.listHooks.openAICompat.success[e.requestId]?.(e) }))
|
||||
this._register((this.channel.listen('onError_list_openAICompatible') satisfies Event<EventModelListOnErrorParams<OpenaiCompatibleModelResponse>>)(e => { this.listHooks.openAICompat.error[e.requestId]?.(e) }))
|
||||
this._register((this.channel.listen('onText_sendLLMMessage') satisfies Event<EventLLMMessageOnTextParams>)(e => {
|
||||
this.llmMessageHooks.onText[e.requestId]?.(e)
|
||||
}))
|
||||
this._register((this.channel.listen('onFinalMessage_sendLLMMessage') satisfies Event<EventLLMMessageOnFinalMessageParams>)(e => {
|
||||
this.llmMessageHooks.onFinalMessage[e.requestId]?.(e);
|
||||
this._clearChannelHooks(e.requestId)
|
||||
}))
|
||||
this._register((this.channel.listen('onError_sendLLMMessage') satisfies Event<EventLLMMessageOnErrorParams>)(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<EventModelListOnSuccessParams<OllamaModelResponse>>)(e => {
|
||||
this.listHooks.ollama.success[e.requestId]?.(e)
|
||||
}))
|
||||
this._register((this.channel.listen('onError_list_ollama') satisfies Event<EventModelListOnErrorParams<OllamaModelResponse>>)(e => {
|
||||
this.listHooks.ollama.error[e.requestId]?.(e)
|
||||
}))
|
||||
this._register((this.channel.listen('onSuccess_list_openAICompatible') satisfies Event<EventModelListOnSuccessParams<OpenaiCompatibleModelResponse>>)(e => {
|
||||
this.listHooks.openAICompat.success[e.requestId]?.(e)
|
||||
}))
|
||||
this._register((this.channel.listen('onError_list_openAICompatible') satisfies Event<EventModelListOnErrorParams<OpenaiCompatibleModelResponse>>)(e => {
|
||||
this.listHooks.openAICompat.error[e.requestId]?.(e)
|
||||
}))
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +177,7 @@ export class LLMMessageService extends Disposable implements ILLMMessageService
|
|||
} satisfies MainModelListParams<OpenaiCompatibleModelResponse>)
|
||||
}
|
||||
|
||||
_clearChannelHooks(requestId: string) {
|
||||
private _clearChannelHooks(requestId: string) {
|
||||
delete this.llmMessageHooks.onText[requestId]
|
||||
delete this.llmMessageHooks.onFinalMessage[requestId]
|
||||
delete this.llmMessageHooks.onError[requestId]
|
||||
|
|
|
|||
|
|
@ -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('')
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue