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

fix custom models setting #6000

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export async function requestOpenai(req: NextRequest) {
[
ServiceProvider.OpenAI,
ServiceProvider.Azure,
jsonBody?.model as string, // support provider-unspecified model
"custom" as string, // support provider-unspecified model
],
)
) {
Expand Down
6 changes: 3 additions & 3 deletions app/utils/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export function collectModelTable(

// default models
models.forEach((m) => {
// using <modelName>@<providerId> as fullName
modelTable[`${m.name}@${m?.provider?.id}`] = {
// using <modelName>@<providerType> as fullName
modelTable[`${m.name}@${m?.provider?.providerType}`] = {
...m,
displayName: m.name, // 'provider' is copied over if it exists
};
Expand Down Expand Up @@ -126,7 +126,7 @@ export function collectModelTable(
displayName: displayName || customModelName,
available,
provider, // Use optional chaining
sorted: CustomSeq.next(`${customModelName}@${provider?.id}`),
sorted: CustomSeq.next(`${customModelName}@${provider?.providerType}`),
};
}
}
Expand Down
16 changes: 14 additions & 2 deletions test/model-available.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("isModelNotavailableInServer", () => {
expect(result).toBe(true);
});

// FIXME: 这个测试用例有问题,需要修复
// 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";
Expand All @@ -69,7 +69,19 @@ describe("isModelNotavailableInServer", () => {
test("test custom model without setting provider", () => {
const customModels = "-all,mistral-large";
const modelName = "mistral-large";
const providerNames = modelName;
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,
Expand Down