feat(OpenAI Node): Filter available models by blacklisting rather than whitelisting (#14780)

This commit is contained in:
Yiorgis Gozadinos
2025-04-23 11:09:16 +02:00
committed by GitHub
parent 418a588e89
commit 0e2eceb33f
3 changed files with 54 additions and 21 deletions

View File

@@ -16,26 +16,31 @@ export async function searchModels(
const filteredModels = models.filter((model: { id: string }) => {
const url = baseURL && new URL(baseURL);
const isValidModel =
(url && url.hostname !== 'api.openai.com') ||
model.id.startsWith('ft:') ||
model.id.startsWith('o1') ||
model.id.startsWith('o3') ||
(model.id.startsWith('gpt-') && !model.id.includes('instruct'));
const isCustomAPI = url && url.hostname !== 'api.openai.com';
// Filter out TTS, embedding, image generation, and other models
const isInvalidModel =
!isCustomAPI &&
(model.id.startsWith('babbage') ||
model.id.startsWith('davinci') ||
model.id.startsWith('computer-use') ||
model.id.startsWith('dall-e') ||
model.id.startsWith('text-embedding') ||
model.id.startsWith('tts') ||
model.id.startsWith('whisper') ||
model.id.startsWith('omni-moderation') ||
(model.id.startsWith('gpt-') && model.id.includes('instruct')));
if (!filter) return isValidModel;
if (!filter) return !isInvalidModel;
return isValidModel && model.id.toLowerCase().includes(filter.toLowerCase());
return !isInvalidModel && model.id.toLowerCase().includes(filter.toLowerCase());
});
filteredModels.sort((a, b) => a.id.localeCompare(b.id));
const results = {
return {
results: filteredModels.map((model: { id: string }) => ({
name: model.id,
value: model.id,
})),
};
return results;
}