mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(OpenAI Node): Filter available models by blacklisting rather than whitelisting (#14780)
This commit is contained in:
committed by
GitHub
parent
418a588e89
commit
0e2eceb33f
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user