From 13796fe3b3186320c05d8615877802b78eea7497 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Tue, 26 Nov 2024 13:44:19 -0800 Subject: [PATCH] fix: legacy query generation support --- src/lib/apis/index.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/apis/index.ts b/src/lib/apis/index.ts index a33610c31..ea20f5eda 100644 --- a/src/lib/apis/index.ts +++ b/src/lib/apis/index.ts @@ -367,15 +367,15 @@ export const generateQueries = async ( throw error; } - try { - // Step 1: Safely extract the response string - const response = res?.choices[0]?.message?.content ?? ''; - // Step 3: Find the relevant JSON block within the response + // Step 1: Safely extract the response string + const response = res?.choices[0]?.message?.content ?? ''; + + + try { const jsonStartIndex = response.indexOf('{'); const jsonEndIndex = response.lastIndexOf('}'); - // Step 4: Check if we found a valid JSON block (with both `{` and `}`) if (jsonStartIndex !== -1 && jsonEndIndex !== -1) { const jsonResponse = response.substring(jsonStartIndex, jsonEndIndex + 1); @@ -391,11 +391,11 @@ export const generateQueries = async ( } // If no valid JSON block found, return an empty array - return []; + return [response]; } catch (e) { // Catch and safely return empty array on any parsing errors console.error('Failed to parse response: ', e); - return []; + return [response]; } };