diff --git a/app/config/build.ts b/app/config/build.ts index b2b1ad49da1..aa7c10729b6 100644 --- a/app/config/build.ts +++ b/app/config/build.ts @@ -40,6 +40,7 @@ export const getBuildConfig = () => { buildMode, isApp, template: process.env.DEFAULT_INPUT_TEMPLATE ?? DEFAULT_INPUT_TEMPLATE, + visionModels: process.env.VISION_MODELS || "", }; }; diff --git a/app/utils.ts b/app/utils.ts index fafbc9e79b4..f49f1a46609 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -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 @@ -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; } diff --git a/test/vision-model-checker.test.ts b/test/vision-model-checker.test.ts index 842ef644ab4..734e992d829 100644 --- a/test/vision-model-checker.test.ts +++ b/test/vision-model-checker.test.ts @@ -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); });