mirror of
https://github.com/open-webui/open-webui
synced 2025-01-01 08:42:14 +00:00
fix: legacy query generation support
This commit is contained in:
parent
63402c48a8
commit
13796fe3b3
@ -367,15 +367,15 @@ export const generateQueries = async (
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
// Step 1: Safely extract the response string
|
// Step 1: Safely extract the response string
|
||||||
const response = res?.choices[0]?.message?.content ?? '';
|
const response = res?.choices[0]?.message?.content ?? '';
|
||||||
|
|
||||||
// Step 3: Find the relevant JSON block within the response
|
|
||||||
|
try {
|
||||||
const jsonStartIndex = response.indexOf('{');
|
const jsonStartIndex = response.indexOf('{');
|
||||||
const jsonEndIndex = response.lastIndexOf('}');
|
const jsonEndIndex = response.lastIndexOf('}');
|
||||||
|
|
||||||
// Step 4: Check if we found a valid JSON block (with both `{` and `}`)
|
|
||||||
if (jsonStartIndex !== -1 && jsonEndIndex !== -1) {
|
if (jsonStartIndex !== -1 && jsonEndIndex !== -1) {
|
||||||
const jsonResponse = response.substring(jsonStartIndex, 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
|
// If no valid JSON block found, return an empty array
|
||||||
return [];
|
return [response];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Catch and safely return empty array on any parsing errors
|
// Catch and safely return empty array on any parsing errors
|
||||||
console.error('Failed to parse response: ', e);
|
console.error('Failed to parse response: ', e);
|
||||||
return [];
|
return [response];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user