Merge remote-tracking branch 'upstream/main' into dev

# Conflicts:
#	app/components/chat.tsx
#	app/constant.ts
#	app/store/access.ts
#	app/utils/hooks.ts
This commit is contained in:
sijinhui
2024-04-26 14:02:16 +08:00
10 changed files with 111 additions and 37 deletions

View File

@@ -1,5 +1,11 @@
import { LLMModel } from "../client/api";
const customProvider = (modelName: string) => ({
id: modelName,
providerName: "",
providerType: "custom",
});
export function collectModelTable(
models: readonly LLMModel[],
customModels: string,
@@ -12,6 +18,7 @@ export function collectModelTable(
displayName: string;
describe: string;
provider?: LLMModel["provider"]; // Marked as optional
isDefault?: boolean;
}
> = {};
@@ -23,12 +30,6 @@ export function collectModelTable(
};
});
const customProvider = (modelName: string) => ({
id: modelName,
providerName: "",
providerType: "custom",
});
// server custom models
customModels
.split(",")
@@ -54,6 +55,27 @@ export function collectModelTable(
};
}
});
return modelTable;
}
export function collectModelTableWithDefaultModel(
models: readonly LLMModel[],
customModels: string,
defaultModel: string,
) {
let modelTable = collectModelTable(models, customModels);
if (defaultModel && defaultModel !== "") {
delete modelTable[defaultModel];
modelTable[defaultModel] = {
name: defaultModel,
displayName: defaultModel,
available: true,
provider:
modelTable[defaultModel]?.provider ?? customProvider(defaultModel),
isDefault: true,
};
}
return modelTable;
}
@@ -69,3 +91,17 @@ export function collectModels(
return allModels;
}
export function collectModelsWithDefaultModel(
models: readonly LLMModel[],
customModels: string,
defaultModel: string,
) {
const modelTable = collectModelTableWithDefaultModel(
models,
customModels,
defaultModel,
);
const allModels = Object.values(modelTable);
return allModels;
}