From 07bdae278b8be1404f514cb3e5f60085ed1f1a13 Mon Sep 17 00:00:00 2001 From: Andrea Brancaleoni Date: Wed, 20 Dec 2023 01:46:41 +0100 Subject: [PATCH] openaiExplainPatch.js: exit eagerly if patch length is none --- src/openaiExplainPatch.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/openaiExplainPatch.js b/src/openaiExplainPatch.js index 43ec50e..f72e9e7 100644 --- a/src/openaiExplainPatch.js +++ b/src/openaiExplainPatch.js @@ -117,7 +117,10 @@ Desired format: try { m = realModels[i]; let enc = encoding_for_model(m); - if (enc.encode(patchBody).length < amplification*max_tokens) + let pLen = enc.encode(patchBody).length; + if (pLen == 0) + throw new Error("The patch is empty, cannot summarize!"); + if (pLen < amplification*max_tokens) throw new Error("The patch is trivial, no need for a summarization"); var aiResponse = await openai.chat.completions.create({ model: m,