From 30941800b04c59b9a45375d6934a4fb79cac0141 Mon Sep 17 00:00:00 2001 From: davidbrai Date: Fri, 1 Nov 2024 11:12:48 +0100 Subject: [PATCH] fix: log llm completition in edit command currently the llm answer is not logged because the for loop never ends, it break from the caller. wrapping with a finally block to log it anyway --- core/llm/index.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/core/llm/index.ts b/core/llm/index.ts index c3680aae71..4d3f2fd6e8 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -501,15 +501,20 @@ export abstract class BaseLLM implements ILLM { } let completion = ""; - for await (const chunk of this._streamComplete(prompt, completionOptions)) { - completion += chunk; - yield chunk; - } - - this._logTokensGenerated(completionOptions.model, prompt, completion); + try { + for await (const chunk of this._streamComplete( + prompt, + completionOptions, + )) { + completion += chunk; + yield chunk; + } + } finally { + this._logTokensGenerated(completionOptions.model, prompt, completion); - if (log && this.writeLog) { - await this.writeLog(`Completion:\n\n${completion}\n\n`); + if (log && this.writeLog) { + await this.writeLog(`Completion:\n\n${completion}\n\n`); + } } return {