Improve tag extraction in getTagsFromResponse by trimming whitespace and enhancing comma splitting for better parsing. see #365
This commit is contained in:
parent
cb307a8d07
commit
d3813c00f6
1 changed files with 3 additions and 3 deletions
|
|
@ -97,16 +97,16 @@ export const taPromptUtils = {
|
||||||
if(response_text && response_text.length > 0){
|
if(response_text && response_text.length > 0){
|
||||||
try {
|
try {
|
||||||
// Try to parse the response text as JSON
|
// 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)){
|
if(response_json && Array.isArray(response_json.tags)){
|
||||||
tags = response_json.tags;
|
tags = response_json.tags;
|
||||||
} else if(response_json && response_json.tags && typeof response_json.tags === 'string'){
|
} else if(response_json && response_json.tags && typeof response_json.tags === 'string'){
|
||||||
// If tags is a string, split it by commas
|
// 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) {
|
} catch (e) {
|
||||||
// If parsing fails, fallback to splitting by commas
|
// 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;
|
return tags;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue