File size: 1,301 Bytes
246d201 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import { extractModelAndProvider } from "./extract-model-and-provider";
/**
* Given a list of models, organize them by provider
* @param models The list of models
* @returns An object containing the provider and models
*
* @example
* const models = [
* "azure/ada",
* "azure/gpt-35-turbo",
* "cohere.command-r-v1:0",
* ];
*
* organizeModelsAndProviders(models);
* // returns {
* // azure: {
* // separator: "/",
* // models: ["ada", "gpt-35-turbo"],
* // },
* // cohere: {
* // separator: ".",
* // models: ["command-r-v1:0"],
* // },
* // }
*/
export const organizeModelsAndProviders = (models: string[]) => {
const object: Record<string, { separator: string; models: string[] }> = {};
models.forEach((model) => {
const {
separator,
provider,
model: modelId,
} = extractModelAndProvider(model);
// Ignore "anthropic" providers with a separator of "."
// These are outdated and incompatible providers.
if (provider === "anthropic" && separator === ".") {
return;
}
const key = provider || "other";
if (!object[key]) {
object[key] = { separator, models: [] };
}
object[key].models.push(modelId);
});
return object;
};
|