diff --git a/public/scripts/PromptManager.js b/public/scripts/PromptManager.js index 678ddf268..6e9010e13 100644 --- a/public/scripts/PromptManager.js +++ b/public/scripts/PromptManager.js @@ -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'