@n8n/n8n-nodes-langchain
Version:
51 lines • 2.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.listModels = listModels;
const listBedrockInferenceProfiles_1 = require("../../../../utils/aws/listBedrockInferenceProfiles");
const resolveBedrockApi_1 = require("../../../../utils/aws/resolveBedrockApi");
async function listModels() {
const api = await (0, resolveBedrockApi_1.resolveBedrockApi)(this);
const [foundationModels, inferenceProfiles] = await Promise.allSettled([
this.helpers.httpRequestWithAuthentication.call(this, api.credentialsType, {
method: 'GET',
baseURL: api.baseURL,
url: '/foundation-models?byOutputModality=EMBEDDING',
json: true,
}),
(0, listBedrockInferenceProfiles_1.listBedrockInferenceProfiles)(this, api),
]);
if (foundationModels.status === 'rejected' && inferenceProfiles.status === 'rejected') {
throw foundationModels.reason;
}
if (foundationModels.status === 'rejected') {
this.logger.warn('Bedrock model listing: foundation-models request failed', {
error: foundationModels.reason,
});
}
if (inferenceProfiles.status === 'rejected') {
this.logger.warn('Bedrock model listing: inference-profiles request failed', {
error: inferenceProfiles.reason,
});
}
const options = [];
const embeddingModelIds = new Set();
if (foundationModels.status === 'fulfilled') {
for (const model of foundationModels.value.modelSummaries ?? []) {
embeddingModelIds.add(model.modelId);
if (model.inferenceTypesSupported?.includes('ON_DEMAND')) {
options.push({
name: model.modelName,
value: model.modelId,
description: model.modelArn,
});
}
}
}
if (inferenceProfiles.status === 'fulfilled') {
const isEmbeddingProfile = (profile) => foundationModels.status === 'rejected' ||
(profile.models ?? []).some((model) => embeddingModelIds.has(model.modelArn?.split('/').pop() ?? ''));
options.push(...inferenceProfiles.value.filter(isEmbeddingProfile).map(listBedrockInferenceProfiles_1.toProfileOption));
}
return options.sort((a, b) => a.name.localeCompare(b.name));
}
//# sourceMappingURL=listModels.js.map