Only add name to prompts when conforming to oai api standards

This commit is contained in:
maver 2023-06-25 20:34:57 +02:00
parent 670119e143
commit 0660016a10
1 changed files with 14 additions and 1 deletions

View File

@ -546,11 +546,24 @@ PromptManagerModule.prototype.preparePrompt = function (prompt, original = null)
else preparedPrompt.content = substituteParams(prompt.content);
}
if (prompt.name) preparedPrompt.name = prompt.name;
if (prompt.name && this.isValidName(prompt.name)) preparedPrompt.name = prompt.name;
return preparedPrompt;
}
/**
* Checks if a given name is accepted by OpenAi API
* @link https://platform.openai.com/docs/api-reference/chat/create
*
* @param name
* @returns {boolean}
*/
PromptManagerModule.prototype.isValidName = function(name) {
const regex = /^[a-zA-Z0-9_]{1,64}$/;
return regex.test(name);
}
/**
* Loads a given prompt into the edit form fields.
* @param {Object} prompt - Prompt object with properties 'name', 'role', 'content', and 'system_prompt'