UNPKG

@n8n/n8n-nodes-langchain

Version:
64 lines • 3.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.searchModels = searchModels; const ai_utilities_1 = require("@n8n/ai-utilities"); const model_discovery_1 = require("@n8n/ai-utilities/model-discovery"); const n8n_workflow_1 = require("n8n-workflow"); const N8nOAuth2TokenCredential_1 = require("../credentials/N8nOAuth2TokenCredential"); const requireFoundryEndpoint_1 = require("../credentials/requireFoundryEndpoint"); const types_1 = require("../types"); function resolveFoundryBaseURL(node, foundryEndpoint) { return (0, model_discovery_1.getAzureFoundryOrigin)((0, requireFoundryEndpoint_1.requireFoundryEndpoint)(node, foundryEndpoint)); } function classicCredentialError(node) { return new n8n_workflow_1.NodeOperationError(node, "Only a Microsoft Foundry credential can list deployments. Select By ID and enter the deployment name, or set the credential's Endpoint Type to Microsoft Foundry."); } function missingProjectError(node) { return new n8n_workflow_1.NodeOperationError(node, 'Enter the Project in the node or in the credential to list its deployments. Or select By ID and enter the deployment name.'); } async function searchModels(filter) { const authenticationMethod = this.getNodeParameter('authentication', "azureOpenAiApi"); const nodeProject = this.getNodeParameter('project', ''); const egressFilter = this.helpers.getSecureEgressFilter(); let baseURL; let headers; let project; if (authenticationMethod === "azureOpenAiApi") { const credential = await this.getCredentials('azureOpenAiApi'); if (credential.endpointType !== 'foundry') { throw classicCredentialError(this.getNode()); } baseURL = resolveFoundryBaseURL(this.getNode(), credential.foundryEndpoint); project = nodeProject || credential.project || ''; if (!project) throw missingProjectError(this.getNode()); headers = { 'api-key': credential.apiKey }; } else { const credential = await this.getCredentials('azureEntraCognitiveServicesOAuth2Api'); if (credential.endpointType !== 'foundry') { throw classicCredentialError(this.getNode()); } baseURL = resolveFoundryBaseURL(this.getNode(), credential.foundryEndpoint); project = nodeProject || credential.project || ''; if (!project) throw missingProjectError(this.getNode()); const token = await new N8nOAuth2TokenCredential_1.N8nOAuth2TokenCredential(this.getNode(), credential, types_1.AZURE_AI_FOUNDRY_AUDIENCE, egressFilter).getToken(); if (!token) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Failed to retrieve access token'); } headers = { Authorization: `Bearer ${token.token}` }; } const models = await (0, model_discovery_1.listAzureOpenAiModels)({ baseURL, project, headers, fetch: async (input, init) => await (0, ai_utilities_1.proxyFetch)({ input, init, egressFilter }), }); return { results: models .filter((model) => !filter || model.id.toLowerCase().includes(filter.toLowerCase())) .map((model) => ({ name: model.name, value: model.id })), }; } //# sourceMappingURL=searchModels.js.map