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

feat(frontend): Improve models input UI/UX in settings #3530

Merged
merged 22 commits into from
Aug 23, 2024
Merged
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
Prev Previous commit
Next Next commit
Handle models without a provider
  • Loading branch information
amanape committed Aug 22, 2024
commit d1cb6e85f32ef86d4e75408cb7a4b98988049213
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { ModelSelector } from "./ModelSelector";

describe("ModelSelector", () => {
const models = {
openai: {
separator: "/",
models: ["gpt-4o", "gpt-3.5-turbo"],
},
azure: {
separator: "/",
models: ["ada", "gpt-35-turbo"],
Expand Down
109 changes: 58 additions & 51 deletions frontend/src/utils/extractModelAndProvider.test.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,62 @@
import { describe, it, expect } from "vitest";
import { extractModelAndProvider } from "./extractModelAndProvider";

test("extractModelAndProvider", () => {
expect(extractModelAndProvider("azure/ada")).toEqual({
provider: "azure",
model: "ada",
separator: "/",
});

expect(
extractModelAndProvider("azure/standard/1024-x-1024/dall-e-2"),
).toEqual({
provider: "azure",
model: "standard/1024-x-1024/dall-e-2",
separator: "/",
});

expect(extractModelAndProvider("vertex_ai_beta/chat-bison")).toEqual({
provider: "vertex_ai_beta",
model: "chat-bison",
separator: "/",
});

expect(extractModelAndProvider("cohere.command-r-v1:0")).toEqual({
provider: "cohere",
model: "command-r-v1:0",
separator: ".",
});

expect(
extractModelAndProvider("cloudflare/@cf/mistral/mistral-7b-instruct-v0.1"),
).toEqual({
provider: "cloudflare",
model: "@cf/mistral/mistral-7b-instruct-v0.1",
separator: "/",
});

expect(extractModelAndProvider("gpt-4o")).toEqual({
provider: "",
model: "gpt-4o",
separator: "",
});

expect(extractModelAndProvider("together-ai-21.1b-41b")).toEqual({
provider: "",
model: "together-ai-21.1b-41b",
separator: "",
});

expect(extractModelAndProvider("gpt-3.5-turbo")).toEqual({
provider: "",
model: "gpt-3.5-turbo",
separator: "",
describe("extractModelAndProvider", () => {
it("should work", () => {
expect(extractModelAndProvider("azure/ada")).toEqual({
provider: "azure",
model: "ada",
separator: "/",
});

expect(
extractModelAndProvider("azure/standard/1024-x-1024/dall-e-2"),
).toEqual({
provider: "azure",
model: "standard/1024-x-1024/dall-e-2",
separator: "/",
});

expect(extractModelAndProvider("vertex_ai_beta/chat-bison")).toEqual({
provider: "vertex_ai_beta",
model: "chat-bison",
separator: "/",
});

expect(extractModelAndProvider("cohere.command-r-v1:0")).toEqual({
provider: "cohere",
model: "command-r-v1:0",
separator: ".",
});

expect(
extractModelAndProvider(
"cloudflare/@cf/mistral/mistral-7b-instruct-v0.1",
),
).toEqual({
provider: "cloudflare",
model: "@cf/mistral/mistral-7b-instruct-v0.1",
separator: "/",
});

expect(extractModelAndProvider("together-ai-21.1b-41b")).toEqual({
provider: "",
model: "together-ai-21.1b-41b",
separator: "",
});
});

it("should add provider for popular models", () => {
expect(extractModelAndProvider("gpt-3.5-turbo")).toEqual({
provider: "openai",
model: "gpt-3.5-turbo",
separator: "/",
});

expect(extractModelAndProvider("gpt-4o")).toEqual({
provider: "openai",
model: "gpt-4o",
separator: "/",
});
});
});
7 changes: 6 additions & 1 deletion frontend/src/utils/extractModelAndProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isNumber } from "./isNumber";
import { VERIFIED_OPENAI_MODELS } from "./verified-models";

/**
* Checks if the split array is actually a version number.
Expand Down Expand Up @@ -36,7 +37,11 @@ export const extractModelAndProvider = (model: string) => {
}
}
if (split.length === 1) {
// no "/" or "." separator found, return as model only
// no "/" or "." separator found
if (VERIFIED_OPENAI_MODELS.includes(split[0])) {
return { provider: "openai", model: split[0], separator: "/" };
}
// return as model only
return { provider: "", model, separator: "" };
}
const [provider, ...modelId] = split;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/utils/mapProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const MAP_PROVIDER = {
openai: "OpenAI",
azure: "Azure",
azure_ai: "Azure AI Studio",
vertex_ai: "VertexAI",
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/utils/organizeModelsAndProviders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ test("organizeModelsAndProviders", () => {
separator: "/",
models: ["@cf/mistral/mistral-7b-instruct-v0.1"],
},
openai: {
separator: "/",
models: ["gpt-4o", "gpt-3.5-turbo"],
},
other: {
separator: "",
models: ["gpt-4o", "together-ai-21.1b-41b", "gpt-3.5-turbo"],
models: ["together-ai-21.1b-41b"],
},
});
});
8 changes: 8 additions & 0 deletions frontend/src/utils/verified-models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const VERIFIED_OPENAI_MODELS = [
"gpt-4o",
"gpt-4o-mini",
"gpt-4-turbo",
"gpt-4",
"gpt-4-32k",
"gpt-3.5-turbo",
];