Merge pull request #4986 from ConnectAI-E/hotfix/cf-ai-gateway

hotfix: using custom models, create custom provider
This commit is contained in:
LiuElric 2024-07-12 20:31:22 +08:00 committed by GitHub
commit 4ea8c0802a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 7 deletions

View File

@ -1,9 +1,9 @@
import { DEFAULT_MODELS } from "../constant";
import { LLMModel } from "../client/api";
const customProvider = (modelName: string) => ({
id: modelName,
providerName: "Custom",
const customProvider = (providerName: string) => ({
id: providerName.toLowerCase(),
providerName: providerName,
providerType: "custom",
});
@ -71,10 +71,13 @@ export function collectModelTable(
}
// 2. if model not exists, create new model with available value
if (count === 0) {
const provider = customProvider(name);
modelTable[`${name}@${provider?.id}`] = {
name,
displayName: displayName || name,
const [customModelName, customProviderName] = name.split("@");
const provider = customProvider(
customProviderName || customModelName,
);
modelTable[`${customModelName}@${provider?.id}`] = {
name: customModelName,
displayName: displayName || customModelName,
available,
provider, // Use optional chaining
};