From b3c38a1ee422ace422feadb9ac297500ef88373f Mon Sep 17 00:00:00 2001 From: "Q.A.zh" <40236765+QAbot-zh@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:05:28 +0000 Subject: [PATCH] use regex to split modelName and providerName to process multi '@' symbols --- app/api/common.ts | 2 +- app/components/chat.tsx | 2 +- app/components/model-config.tsx | 2 +- app/utils/model.ts | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/api/common.ts b/app/api/common.ts index 24453dd9635..060c05632d3 100644 --- a/app/api/common.ts +++ b/app/api/common.ts @@ -79,7 +79,7 @@ export async function requestOpenai(req: NextRequest) { .filter((v) => !!v && !v.startsWith("-") && v.includes(modelName)) .forEach((m) => { const [fullName, displayName] = m.split("="); - const [_, providerName] = fullName.split("@"); + const [_, providerName] = fullName.split(/@(?=[^@]*$)/); if (providerName === "azure" && !displayName) { const [_, deployId] = (serverConfig?.azureUrl ?? "").split( "deployments/", diff --git a/app/components/chat.tsx b/app/components/chat.tsx index b18c86708a7..241eb2911f0 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -612,7 +612,7 @@ export function ChatActions(props: { onClose={() => setShowModelSelector(false)} onSelection={(s) => { if (s.length === 0) return; - const [model, providerName] = s[0].split("@"); + const [model, providerName] = s[0].split(/@(?=[^@]*$)/); chatStore.updateCurrentSession((session) => { session.mask.modelConfig.model = model as ModelType; session.mask.modelConfig.providerName = diff --git a/app/components/model-config.tsx b/app/components/model-config.tsx index 6ce25f6642c..91389e4e195 100644 --- a/app/components/model-config.tsx +++ b/app/components/model-config.tsx @@ -20,7 +20,7 @@ export function ModelConfigList(props: { aria-label={Locale.Settings.Model} value={value} onChange={(e) => { - const [model, providerName] = e.currentTarget.value.split("@"); + const [model, providerName] = e.currentTarget.value.split(/@(?=[^@]*$)/); props.updateConfig((config) => { config.model = ModalConfigValidator.model(model); config.providerName = providerName as ServiceProvider; diff --git a/app/utils/model.ts b/app/utils/model.ts index 0b62b53be09..b4abbbddad0 100644 --- a/app/utils/model.ts +++ b/app/utils/model.ts @@ -79,10 +79,10 @@ export function collectModelTable( ); } else { // 1. find model by name, and set available value - const [customModelName, customProviderName] = name.split("@"); + const [customModelName, customProviderName] = name.split(/@(?=[^@]*$)/); let count = 0; for (const fullName in modelTable) { - const [modelName, providerName] = fullName.split("@"); + const [modelName, providerName] = fullName.split(/@(?=[^@]*$)/); if ( customModelName == modelName && (customProviderName === undefined || @@ -102,7 +102,7 @@ export function collectModelTable( } // 2. if model not exists, create new model with available value if (count === 0) { - let [customModelName, customProviderName] = name.split("@"); + let [customModelName, customProviderName] = name.split(/@(?=[^@]*$)/); const provider = customProvider( customProviderName || customModelName, );