ChatGPT-Next-Web/test/model-available.test.ts
2024-12-29 06:45:58 +00:00

93 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { isModelNotavailableInServer } from "../app/utils/model";
describe("isModelNotavailableInServer", () => {
test("test model will return false, which means the model is available", () => {
const customModels = "";
const modelName = "gpt-4";
const providerNames = "OpenAI";
const result = isModelNotavailableInServer(
customModels,
modelName,
providerNames,
);
expect(result).toBe(false);
});
test("test model will return true when model is not available in custom models", () => {
const customModels = "-all,gpt-4o-mini";
const modelName = "gpt-4";
const providerNames = "OpenAI";
const result = isModelNotavailableInServer(
customModels,
modelName,
providerNames,
);
expect(result).toBe(true);
});
test("should respect DISABLE_GPT4 setting", () => {
process.env.DISABLE_GPT4 = "1";
const result = isModelNotavailableInServer("", "gpt-4", "OpenAI");
expect(result).toBe(true);
});
test("should handle empty provider names", () => {
const result = isModelNotavailableInServer("-all,gpt-4", "gpt-4", "");
expect(result).toBe(true);
});
test("should be case insensitive for model names", () => {
const result = isModelNotavailableInServer("-all,GPT-4", "gpt-4", "OpenAI");
expect(result).toBe(true);
});
test("support passing multiple providers, model unavailable on one of the providers will return true", () => {
const customModels = "-all,gpt-4@google";
const modelName = "gpt-4";
const providerNames = ["OpenAI", "Azure"];
const result = isModelNotavailableInServer(
customModels,
modelName,
providerNames,
);
expect(result).toBe(true);
});
// FIXME: 这个测试用例有问题,需要修复
// test("support passing multiple providers, model available on one of the providers will return false", () => {
// const customModels = "-all,gpt-4@google";
// const modelName = "gpt-4";
// const providerNames = ["OpenAI", "Google"];
// const result = isModelNotavailableInServer(
// customModels,
// modelName,
// providerNames,
// );
// expect(result).toBe(false);
// });
test("test custom model without setting provider", () => {
const customModels = "-all,mistral-large";
const modelName = "mistral-large";
const providerNames = "custom";
const result = isModelNotavailableInServer(
customModels,
modelName,
providerNames,
);
expect(result).toBe(false);
});
test("test custom model with non-standard provider", () => {
const customModels = "-all,deepseek-chat@DeepSeek";
const modelName = "deepseek-chat";
const providerNames = "custom";
const result = isModelNotavailableInServer(
customModels,
modelName,
providerNames,
);
expect(result).toBe(false);
});
});