Skip to content

Commit

Permalink
use regex to split modelName and providerName to process multi '@' sy…
Browse files Browse the repository at this point in the history
…mbols
  • Loading branch information
QAbot-zh committed Aug 9, 2024
1 parent cf1c8e8 commit b3c38a1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
2 changes: 1 addition & 1 deletion app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion app/components/model-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions app/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand All @@ -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,
);
Expand Down

0 comments on commit b3c38a1

Please sign in to comment.