Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
extractMetadataMap,
fetchJson,
type InputModality,
isDateSnapshot,
isOldModel,
type ListModelsResult,
type ModelIgnoreReason,
partition,
Expand Down Expand Up @@ -49,6 +51,12 @@ export async function listAnthropicModels(
if (shouldIgnoreCommonKeywords(model.id)) {
reasons.push("common_keyword");
}
if (isOldModel(model.id)) {
reasons.push("old_model");
}
if (isDateSnapshot(model.id)) {
reasons.push("date_snapshot");
}
return reasons.length > 0 ? reasons : null;
},
(model) => model.id,
Expand Down
38 changes: 38 additions & 0 deletions apps/desktop/src/components/settings/ai/shared/list-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { Effect } from "effect";

export type ModelIgnoreReason =
| "common_keyword"
| "old_model"
| "date_snapshot"
| "no_tool"
| "no_text_input"
| "no_completion"
| "not_llm"
| "not_chat_model"
| "context_too_small";

export type IgnoredModel = { id: string; reasons: ModelIgnoreReason[] };
Expand Down Expand Up @@ -40,6 +43,10 @@ export const commonIgnoreKeywords = [
"image",
"computer",
"robotics",
"realtime",
"moderation",
"codex",
"transcribe",
] as const;

export const fetchJson = (url: string, headers: Record<string, string>) =>
Expand All @@ -60,6 +67,37 @@ export const shouldIgnoreCommonKeywords = (id: string): boolean => {
return commonIgnoreKeywords.some((keyword) => lowerId.includes(keyword));
};

export const isDateSnapshot = (id: string): boolean => {
if (/-\d{4}-\d{2}-\d{2}/.test(id)) return true;
if (/-\d{8}$/.test(id)) return true;
if (/-\d{4}$/.test(id)) return true;
return false;
};

export const isNonChatModel = (id: string): boolean => {
const lowerId = id.toLowerCase();
const name = lowerId.includes("/") ? lowerId.split("/").pop()! : lowerId;

if (/^o\d/.test(name)) return true;
if (/^gpt-4o-/.test(name)) return true;
if (/^gpt-4\.1/.test(name)) return true;
if (name.startsWith("ft:") || lowerId.startsWith("ft:")) return true;
if (/^gemini-2\.[05]/.test(name)) return true;
if (/^gemma/.test(name)) return true;
if (/^nano-banana/.test(name)) return true;

return false;
};

export const isOldModel = (id: string): boolean => {
const lowerId = id.toLowerCase();
if (/^gpt-3\.5/.test(lowerId)) return true;
if (/^gpt-4(?!o|\.)/.test(lowerId)) return true;
if (/^(davinci|babbage|curie|ada)(-|$)/.test(lowerId)) return true;
if (/^claude-(2|instant)/.test(lowerId)) return true;
return false;
};

const hasMetadata = (metadata: ModelMetadata | undefined): boolean => {
if (!metadata) {
return false;
Expand Down
16 changes: 12 additions & 4 deletions apps/desktop/src/components/settings/ai/shared/list-google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
extractMetadataMap,
fetchJson,
type InputModality,
isDateSnapshot,
isNonChatModel,
type ListModelsResult,
type ModelIgnoreReason,
partition,
Expand Down Expand Up @@ -37,21 +39,27 @@ export async function listGoogleModels(
!model.supportedGenerationMethods ||
model.supportedGenerationMethods.includes("generateContent");

const extractModelId = (model: GoogleModel): string => {
return model.name.replace(/^models\//, "");
};

const getIgnoreReasons = (model: GoogleModel): ModelIgnoreReason[] | null => {
const reasons: ModelIgnoreReason[] = [];
if (shouldIgnoreCommonKeywords(model.name)) {
reasons.push("common_keyword");
}
if (isNonChatModel(extractModelId(model))) {
reasons.push("not_chat_model");
}
if (!supportsGeneration(model)) {
reasons.push("no_completion");
}
if (isDateSnapshot(extractModelId(model))) {
reasons.push("date_snapshot");
}
return reasons.length > 0 ? reasons : null;
};

const extractModelId = (model: GoogleModel): string => {
return model.name.replace(/^models\//, "");
};

return pipe(
fetchJson(`${baseUrl}/models`, { "x-goog-api-key": apiKey }),
Effect.andThen((json) => Schema.decodeUnknown(GoogleModelSchema)(json)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
extractMetadataMap,
fetchJson,
type InputModality,
isDateSnapshot,
type ListModelsResult,
type ModelIgnoreReason,
partition,
Expand Down Expand Up @@ -51,6 +52,9 @@ export async function listMistralModels(
if (!supportsChatCompletion(model)) {
reasons.push("no_completion");
}
if (isDateSnapshot(model.id)) {
reasons.push("date_snapshot");
}
return reasons.length > 0 ? reasons : null;
};

Expand Down
21 changes: 21 additions & 0 deletions apps/desktop/src/components/settings/ai/shared/list-openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
DEFAULT_RESULT,
extractMetadataMap,
fetchJson,
isDateSnapshot,
isNonChatModel,
isOldModel,
type ListModelsResult,
type ModelIgnoreReason,
partition,
Expand Down Expand Up @@ -38,6 +41,15 @@ export async function listOpenAIModels(
if (shouldIgnoreCommonKeywords(model.id)) {
reasons.push("common_keyword");
}
if (isNonChatModel(model.id)) {
reasons.push("not_chat_model");
}
if (isOldModel(model.id)) {
reasons.push("old_model");
}
if (isDateSnapshot(model.id)) {
reasons.push("date_snapshot");
}
return reasons.length > 0 ? reasons : null;
},
(model) => model.id,
Expand Down Expand Up @@ -73,6 +85,15 @@ export async function listGenericModels(
if (shouldIgnoreCommonKeywords(model.id)) {
reasons.push("common_keyword");
}
if (isNonChatModel(model.id)) {
reasons.push("not_chat_model");
}
if (isOldModel(model.id)) {
reasons.push("old_model");
}
if (isDateSnapshot(model.id)) {
reasons.push("date_snapshot");
}
return reasons.length > 0 ? reasons : null;
},
(model) => model.id,
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src/components/settings/ai/shared/list-openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
extractMetadataMap,
fetchJson,
type InputModality,
isDateSnapshot,
isNonChatModel,
isOldModel,
type ListModelsResult,
type ModelIgnoreReason,
partition,
Expand Down Expand Up @@ -59,12 +62,21 @@ export async function listOpenRouterModels(
if (hasCommonIgnoreKeywords(model)) {
reasons.push("common_keyword");
}
if (isNonChatModel(model.id)) {
reasons.push("not_chat_model");
}
if (!supportsTextInput(model)) {
reasons.push("no_text_input");
}
if (!supportsToolUse(model)) {
reasons.push("no_tool");
}
if (isOldModel(model.id)) {
reasons.push("old_model");
}
if (isDateSnapshot(model.id)) {
reasons.push("date_snapshot");
}
return reasons.length > 0 ? reasons : null;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ const formatIgnoreReason = (reason: ModelIgnoreReason): string => {
switch (reason) {
case "common_keyword":
return "Contains common ignore keyword";
case "old_model":
return "Old or deprecated model";
case "date_snapshot":
return "Date-specific snapshot";
case "no_tool":
return "No tool support";
case "no_text_input":
Expand All @@ -53,6 +57,8 @@ const formatIgnoreReason = (reason: ModelIgnoreReason): string => {
return "No completion support";
case "not_llm":
return "Not an LLM type";
case "not_chat_model":
return "Not a chat model";
case "context_too_small":
return "Context length too small";
}
Expand Down
Loading