Skip to content

Commit

Permalink
fix: log llm completition in edit command
Browse files Browse the repository at this point in the history
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
  • Loading branch information
davidbrai committed Nov 1, 2024
1 parent b1cf2cd commit 3094180
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions core/llm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3094180

Please sign in to comment.