Skip to content

Commit

Permalink
fix: allow isVisionModel utility function read env var
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangYingjin committed Dec 25, 2024
1 parent 0c3d446 commit ea1751f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,16 @@ export function getMessageImages(message: RequestMessage): string[] {
}

export function isVisionModel(model: string) {
const clientConfig = getClientConfig();
const envVisionModels = clientConfig?.visionModels
?.split(",")
.map((m) => m.trim());
if (envVisionModels?.includes(model)) {
const clientVisionModels = getClientConfig()?.visionModels || "";
const envVisionModels = process.env.VISION_MODELS || "";
const allVisionModels = `${clientVisionModels},${envVisionModels}`;

const visionModelsList = allVisionModels
.split(",")
.filter(Boolean)
.map((m: string) => m.trim());

if (visionModelsList.includes(model)) {
return true;
}
return (
Expand Down
3 changes: 2 additions & 1 deletion test/vision-model-checker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ describe("isVisionModel", () => {
});

test("should identify models from VISION_MODELS env var", () => {
process.env.VISION_MODELS = "custom-vision-model,another-vision-model";
process.env.VISION_MODELS = "custom-vision-model,another-vision-model,OpenGVLab/InternVL2-26B";

expect(isVisionModel("custom-vision-model")).toBe(true);
expect(isVisionModel("another-vision-model")).toBe(true);
expect(isVisionModel("OpenGVLab/InternVL2-26B")).toBe(true);
expect(isVisionModel("unrelated-model")).toBe(false);
});

Expand Down

0 comments on commit ea1751f

Please sign in to comment.