From 0660016a105fdcde9e480334699b2b7191a644f9 Mon Sep 17 00:00:00 2001 From: maver Date: Sun, 25 Jun 2023 20:34:57 +0200 Subject: [PATCH] Only add name to prompts when conforming to oai api standards --- public/scripts/PromptManager.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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'