From d3813c00f64760834483e9a4a85a64c912530894 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 15 Jun 2025 00:28:04 +0200 Subject: [PATCH] Improve tag extraction in getTagsFromResponse by trimming whitespace and enhancing comma splitting for better parsing. see #365 --- js/mzta-utils-prompt.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/mzta-utils-prompt.js b/js/mzta-utils-prompt.js index b0c0a96c..c42d40d6 100644 --- a/js/mzta-utils-prompt.js +++ b/js/mzta-utils-prompt.js @@ -97,16 +97,16 @@ export const taPromptUtils = { if(response_text && response_text.length > 0){ try { // Try to parse the response text as JSON - let response_json = JSON.parse(response_text); + let response_json = JSON.parse(response_text.trim()); if(response_json && Array.isArray(response_json.tags)){ tags = response_json.tags; } else if(response_json && response_json.tags && typeof response_json.tags === 'string'){ // If tags is a string, split it by commas - tags = response_json.tags.split(',').map(tag => tag.trim()); + tags = response_json.tags.split(/,\s*/).map(tag => tag.trim()); } } catch (e) { // If parsing fails, fallback to splitting by commas - tags = response_text.split(',').map(tag => tag.trim()); + tags = response_text.split(/,\s*/).map(tag => tag.trim()); } } return tags;