From d5cb03502f868c4723520ad824c695812a801a8d Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sat, 18 Mar 2023 03:27:44 +0100 Subject: [PATCH] Fix the username formatter returning invalid formatName '?' is not accepted character in OpenAI api as a valid name I also switched the order of the replace steps, so there will be less _- in the final username --- src/toOpenAIMessages.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/toOpenAIMessages.ts b/src/toOpenAIMessages.ts index e148363..7d61456 100644 --- a/src/toOpenAIMessages.ts +++ b/src/toOpenAIMessages.ts @@ -40,12 +40,12 @@ function formatName(name: string): string { return FoldToAscii.foldReplacing(name) // White spaces are not allowed .replace(" ", "_") + // replace characters that are not accepted by api with '_' + .replace(/[^a-zA-Z0-9_-]/g, "_") // remove trailing '-_' characters .replace(/^[-_]+|[-_]+$/g, "") // remove duplicated '-_' characters - .replace(/([-_])*/g, "") - // replace characters that are not accepted by api with '?' - .replace(/[^a-zA-Z0-9_-]/g, "?"); + .replace(/([-_])*/g, "$1"); } /**