UNPKG

@n8n/n8n-nodes-langchain

Version:
59 lines • 3.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EMBEDDINGS_CAPABILITY = exports.CHAT_CAPABILITY = void 0; exports.makeModelSearch = makeModelSearch; const n8n_workflow_1 = require("n8n-workflow"); const constants_1 = require("./constants"); const list_pages_1 = require("./list-pages"); const token_provider_1 = require("./token-provider"); exports.CHAT_CAPABILITY = { apiTypeSuffix: '/chat/completions', emptyMessage: 'No chat-capable model services found', emptyDescription: 'None of the visible model services supports chat completions. Use ID mode to enter a service name directly', }; exports.EMBEDDINGS_CAPABILITY = { apiTypeSuffix: '/embeddings', emptyMessage: 'No embeddings-capable model services found', emptyDescription: 'None of the visible model services supports embeddings. Use ID mode to enter a service name directly', }; function makeModelSearch(capability) { return async function searchModels(filter) { const credentials = await this.getCredentials(token_provider_1.DATABRICKS_CREDENTIAL_TYPE); (0, constants_1.assertHttpsHost)(this, credentials.host); const host = credentials.host.replace(/\/$/, ''); const listModelServices = async (parent) => await (0, list_pages_1.listDatabricksPages)(this, (0, n8n_workflow_1.requestUrl) `${host}/api/2.1/unity-catalog/model-services`, { view: 'FULL', parent }, (page) => page.model_services); let services; try { services = await listModelServices(); } catch (error) { if (!(error instanceof n8n_workflow_1.NodeApiError) || error.httpCode !== '400') throw error; services = await listModelServices('schemas/system.ai'); } if (services.length === 0) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No model services found', { description: 'Check that Unity AI Gateway is enabled on this workspace and that this credential can access at least one model service', }); } const capable = services.filter((service) => service.supported_api_types?.some((type) => type.endsWith(capability.apiTypeSuffix))); if (capable.length === 0) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), capability.emptyMessage, { description: capability.emptyDescription, }); } const allResults = capable.map((service) => { const name = service.name.replace(/^model-services\//, ''); return { name, value: name, description: service.comment }; }); if (filter) { const filterLower = filter.toLowerCase(); return { results: allResults.filter((r) => r.name.toLowerCase().includes(filterLower) || (r.description ?? '').toLowerCase().includes(filterLower)), }; } return { results: allResults }; }; } //# sourceMappingURL=model-services.js.map