Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing the ability to remove specified Providers. #5992

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,14 @@ If you want to disable parse settings from url, set this to 1.

To control custom models, use `+` to add a custom model, use `-` to hide a model, use `name=displayName` to customize model name, separated by comma.

User `-all` to disable all default models, `+all` to enable all default models.
Use `-all` to disable all default models, `+all` to enable all default models.
Use `-*provider` to disable specified models.
Current valid providers: `openai,azure,google,anthropic,baidu,bytedance,alibaba,tencent,moonshot,iflytek,xai,chatglm` and more to come.

For Azure: use `modelName@Azure=deploymentName` to customize model name and deployment name.
> Example: `+gpt-3.5-turbo@Azure=gpt35` will show option `gpt35(Azure)` in model list.
> If you only can use Azure model, `-all,+gpt-3.5-turbo@Azure=gpt35` will `gpt35(Azure)` the only option in model list.
> If you don't want to use Azure model, using `-*azure` will prevent Azure models from appearing in the model list.

For ByteDance: use `modelName@bytedance=deploymentName` to customize model name and deployment name.
> Example: `+Doubao-lite-4k@bytedance=ep-xxxxx-xxx` will show option `Doubao-lite-4k(ByteDance)` in model list.
Expand Down
7 changes: 7 additions & 0 deletions app/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export function collectModelTable(
Object.values(modelTable).forEach(
(model) => (model.available = available),
);
} else if (name.startsWith("*")) {
const modelId = name.substring(1).toLowerCase();
Object.values(modelTable).forEach((model) => {
if (model?.provider?.id === modelId) {
model.available = available;
}
});
} else {
// 1. find model by name, and set available value
const [customModelName, customProviderName] = getModelProvider(name);
Expand Down
142 changes: 142 additions & 0 deletions test/model.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { collectModelTable } from "@/app/utils/model"
import { LLMModel,LLMModelProvider } from "@/app/client/api";

describe('collectModelTable', () => {
const mockModels: readonly LLMModel[] = [
{
name: 'gpt-3.5-turbo',
available: true,
provider: {
id: 'openai',
providerName: 'OpenAI',
providerType: 'openai',
} as LLMModelProvider,
sorted: 1,
},
{
name: 'gpt-4',
available: true,
provider: {
id: 'openai',
providerName: 'OpenAI',
providerType: 'openai',
} as LLMModelProvider,
sorted: 1,
},
{
name: 'gpt-3.5-turbo',
available: true,
provider: {
id: 'azure',
providerName: 'Azure',
providerType: 'azure',
} as LLMModelProvider,
sorted: 2,
},
{
name: 'gpt-4',
available: true,
provider: {
id: 'azure',
providerName: 'Azure',
providerType: 'azure',
} as LLMModelProvider,
sorted: 2,
},
{
name: 'gemini-pro',
available: true,
provider: {
id: 'google',
providerName: 'Google',
providerType: 'google',
} as LLMModelProvider,
sorted: 3,
},
{
name: 'claude-3-haiku-20240307',
available: true,
provider: {
id: 'anthropic',
providerName: 'Anthropic',
providerType: 'anthropic',
} as LLMModelProvider,
sorted: 4,
},
{
name: 'grok-beta',
available: true,
provider: {
id: 'xai',
providerName: 'XAI',
providerType: 'xai',
} as LLMModelProvider,
sorted: 11,
},
];

test('all models shoule be available', () => {
const customModels = '';
const result = collectModelTable(mockModels, customModels);

expect(result['gpt-3.5-turbo@openai'].available).toBe(true);
expect(result['gpt-4@openai'].available).toBe(true);
expect(result['gpt-3.5@azure'].available).toBe(true);
expect(result['gpt-4@azure'].available).toBe(true);
expect(result['gemini-pro@google'].available).toBe(true);
expect(result['claude-3-haiku-20240307@claude'].available).toBe(true);
expect(result['grok-beta@xai'].available).toBe(true);
});
QAbot-zh marked this conversation as resolved.
Show resolved Hide resolved
test('should exclude all models when custom is "-all"', () => {
const customModels = '-all';
const result = collectModelTable(mockModels, customModels);

expect(result['gpt-3.5-turbo@openai'].available).toBe(false);
expect(result['gpt-4@openai'].available).toBe(false);
expect(result['gpt-3.5@azure'].available).toBe(false);
expect(result['gpt-4@azure'].available).toBe(false);
expect(result['gemini-pro@google'].available).toBe(false);
expect(result['claude-3-haiku-20240307@anthropic'].available).toBe(false);
expect(result['grok-beta@xai'].available).toBe(false);
});

test('should exclude all Azure models when custom is "-*azure"', () => {
const customModels = '-*azure';
const result = collectModelTable(mockModels, customModels);

expect(result['gpt-3.5-turbo@openai'].available).toBe(true);
expect(result['gpt-4@openai'].available).toBe(true);
expect(result['gpt-3.5@azure'].available).toBe(false);
expect(result['gpt-4@azure'].available).toBe(false);
expect(result['gemini-pro@google'].available).toBe(true);
expect(result['claude-3-haiku-20240307@anthropic'].available).toBe(true);
expect(result['grok-beta@xai'].available).toBe(true);
});

test('should exclude Google and XAI models when custom is "-*google,-*xai"', () => {
const customModels = '-*google,-*xai';
const result = collectModelTable(mockModels, customModels);

expect(result['gpt-3.5-turbo@openai'].available).toBe(true);
expect(result['gpt-4@openai'].available).toBe(true);
expect(result['gpt-3.5@azure'].available).toBe(true);
expect(result['gpt-4@azure'].available).toBe(true);
expect(result['gemini-pro@google'].available).toBe(false);
expect(result['claude-3-haiku-20240307@anthropic'].available).toBe(true);
expect(result['grok-beta@xai'].available).toBe(false);
});

test('should exclude all models except OpenAI when custom is "-all, +*openai"', () => {
const customModels = '-all, +*openai,gpt-4o@azure';
const result = collectModelTable(mockModels, customModels);

expect(result['gpt-3.5-turbo@openai'].available).toBe(true);
expect(result['gpt-4@openai'].available).toBe(true);
expect(result['gpt-3.5@azure'].available).toBe(false);
expect(result['gpt-4@azure'].available).toBe(false);
expect(result['gemini-pro@google'].available).toBe(false);
expect(result['claude-3-haiku-20240307@anthropic'].available).toBe(false);
expect(result['grok-beta@xai'].available).toBe(false);
expect(result['gpt-4o@azure'].available).toBe(true);
});
});