🎯 feat: Enhance Title Parameter Parsing with new Anthropic Format

This commit is contained in:
Danny Avila 2024-11-06 13:40:49 -05:00 committed by GitHub
parent 0c2a583df8
commit 766643ea1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 89 additions and 2 deletions

View file

@ -99,10 +99,24 @@ ONLY include the generated translation without quotations, nor its related key</
* @returns {string} The parsed parameter's value or a default value if not found.
*/
function parseParamFromPrompt(prompt, paramName) {
const paramRegex = new RegExp(`<${paramName}>([\\s\\S]+?)</${paramName}>`);
// Handle null/undefined prompt
if (!prompt) {
return `No ${paramName} provided`;
}
// Try original format first: <title>value</title>
const simpleRegex = new RegExp(`<${paramName}>(.*?)</${paramName}>`, 's');
const simpleMatch = prompt.match(simpleRegex);
if (simpleMatch) {
return simpleMatch[1].trim();
}
// Try parameter format: <parameter name="title">value</parameter>
const paramRegex = new RegExp(`<parameter name="${paramName}">(.*?)</parameter>`, 's');
const paramMatch = prompt.match(paramRegex);
if (paramMatch && paramMatch[1]) {
if (paramMatch) {
return paramMatch[1].trim();
}