Skip to content

Commit

Permalink
refactor: remove NEXT_PUBLIC_ prefix from VISION_MODELS env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiming3 committed Dec 21, 2024
1 parent ed8c358 commit 210b29b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions app/config/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const getBuildConfig = () => {
buildMode,
isApp,
template: process.env.DEFAULT_INPUT_TEMPLATE ?? DEFAULT_INPUT_TEMPLATE,
visionModels: process.env.VISION_MODELS || "",
};
};

Expand Down
8 changes: 5 additions & 3 deletions app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ServiceProvider } from "./constant";
// import { fetch as tauriFetch, ResponseType } from "@tauri-apps/api/http";
import { fetch as tauriStreamFetch } from "./utils/stream";
import { VISION_MODEL_REGEXES, EXCLUDE_VISION_MODEL_REGEXES } from "./constant";
import { getClientConfig } from "./config/client";

export function trimTopic(topic: string) {
// Fix an issue where double quotes still show in the Indonesian language
Expand Down Expand Up @@ -253,9 +254,10 @@ export function getMessageImages(message: RequestMessage): string[] {
}

export function isVisionModel(model: string) {
const envVisionModels = process.env.NEXT_PUBLIC_VISION_MODELS?.split(",").map(
(m) => m.trim(),
);
const clientConfig = getClientConfig();
const envVisionModels = clientConfig.visionModels
?.split(",")
.map((m) => m.trim());
if (envVisionModels?.includes(model)) {
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions test/vision-model-checker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ describe("isVisionModel", () => {
});
});

test("should identify models from NEXT_PUBLIC_VISION_MODELS env var", () => {
process.env.NEXT_PUBLIC_VISION_MODELS = "custom-vision-model,another-vision-model";
test("should identify models from VISION_MODELS env var", () => {
process.env.VISION_MODELS = "custom-vision-model,another-vision-model";

expect(isVisionModel("custom-vision-model")).toBe(true);
expect(isVisionModel("another-vision-model")).toBe(true);
expect(isVisionModel("unrelated-model")).toBe(false);
});

test("should handle empty or missing NEXT_PUBLIC_VISION_MODELS", () => {
process.env.NEXT_PUBLIC_VISION_MODELS = "";
test("should handle empty or missing VISION_MODELS", () => {
process.env.VISION_MODELS = "";
expect(isVisionModel("unrelated-model")).toBe(false);

delete process.env.NEXT_PUBLIC_VISION_MODELS;
delete process.env.VISION_MODELS;
expect(isVisionModel("unrelated-model")).toBe(false);
expect(isVisionModel("gpt-4-vision")).toBe(true);
});
Expand Down

0 comments on commit 210b29b

Please sign in to comment.