Selaa lähdekoodia

fix: legacy query generation support

Timothy Jaeryang Baek 5 kuukautta sitten
vanhempi
commit
13796fe3b3
1 muutettua tiedostoa jossa 7 lisäystä ja 7 poistoa
  1. 7 7
      src/lib/apis/index.ts

+ 7 - 7
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];
 	}
 };