mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(Hugging Face Inference Model Node, Embeddings Hugging Face Inference Node): Fix credential validation for HF nodes and add provider for (#18047)
This commit is contained in:
@@ -34,8 +34,8 @@ export class HuggingFaceApi implements ICredentialType {
|
|||||||
|
|
||||||
test: ICredentialTestRequest = {
|
test: ICredentialTestRequest = {
|
||||||
request: {
|
request: {
|
||||||
baseURL: 'https://api-inference.huggingface.co',
|
baseURL: 'https://huggingface.co',
|
||||||
url: '/models/gpt2',
|
url: '/api/whoami-v2',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
import type { InferenceProviderOrPolicy } from '@huggingface/inference';
|
||||||
|
import { PROVIDERS_OR_POLICIES } from '@huggingface/inference';
|
||||||
import { HuggingFaceInferenceEmbeddings } from '@langchain/community/embeddings/hf';
|
import { HuggingFaceInferenceEmbeddings } from '@langchain/community/embeddings/hf';
|
||||||
import {
|
import {
|
||||||
NodeConnectionTypes,
|
NodeConnectionTypes,
|
||||||
|
NodeOperationError,
|
||||||
type INodeType,
|
type INodeType,
|
||||||
type INodeTypeDescription,
|
type INodeTypeDescription,
|
||||||
type ISupplyDataFunctions,
|
type ISupplyDataFunctions,
|
||||||
@@ -76,6 +79,13 @@ export class EmbeddingsHuggingFaceInference implements INodeType {
|
|||||||
description: 'Custom endpoint URL',
|
description: 'Custom endpoint URL',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Provider',
|
||||||
|
name: 'provider',
|
||||||
|
type: 'options',
|
||||||
|
options: PROVIDERS_OR_POLICIES.map((value) => ({ value, name: value })),
|
||||||
|
default: 'auto',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
@@ -91,6 +101,10 @@ export class EmbeddingsHuggingFaceInference implements INodeType {
|
|||||||
const credentials = await this.getCredentials('huggingFaceApi');
|
const credentials = await this.getCredentials('huggingFaceApi');
|
||||||
const options = this.getNodeParameter('options', itemIndex, {}) as object;
|
const options = this.getNodeParameter('options', itemIndex, {}) as object;
|
||||||
|
|
||||||
|
if ('provider' in options && !isValidHFProviderOrPolicy(options.provider)) {
|
||||||
|
throw new NodeOperationError(this.getNode(), 'Unsupported provider');
|
||||||
|
}
|
||||||
|
|
||||||
const embeddings = new HuggingFaceInferenceEmbeddings({
|
const embeddings = new HuggingFaceInferenceEmbeddings({
|
||||||
apiKey: credentials.apiKey as string,
|
apiKey: credentials.apiKey as string,
|
||||||
model,
|
model,
|
||||||
@@ -102,3 +116,9 @@ export class EmbeddingsHuggingFaceInference implements INodeType {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isValidHFProviderOrPolicy(provider: unknown): provider is InferenceProviderOrPolicy {
|
||||||
|
return (
|
||||||
|
typeof provider === 'string' && (PROVIDERS_OR_POLICIES as readonly string[]).includes(provider)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ export class LmOpenHuggingFaceInference implements INodeType {
|
|||||||
displayName: 'Model',
|
displayName: 'Model',
|
||||||
name: 'model',
|
name: 'model',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: 'gpt2',
|
default: 'mistralai/Mistral-Nemo-Base-2407',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Options',
|
displayName: 'Options',
|
||||||
@@ -139,6 +139,11 @@ export class LmOpenHuggingFaceInference implements INodeType {
|
|||||||
const modelName = this.getNodeParameter('model', itemIndex) as string;
|
const modelName = this.getNodeParameter('model', itemIndex) as string;
|
||||||
const options = this.getNodeParameter('options', itemIndex, {}) as object;
|
const options = this.getNodeParameter('options', itemIndex, {}) as object;
|
||||||
|
|
||||||
|
// LangChain does not yet support specifying Provider
|
||||||
|
// That's why mistral's model is the default value
|
||||||
|
// It is one of the few models that seem to work out of the box
|
||||||
|
// Other models are returning "Model x/y is not supported for task text-generation and provider z. Supported task: conversational."
|
||||||
|
// https://github.com/langchain-ai/langchainjs/discussions/8434#discussioncomment-13603787
|
||||||
const model = new HuggingFaceInference({
|
const model = new HuggingFaceInference({
|
||||||
model: modelName,
|
model: modelName,
|
||||||
apiKey: credentials.apiKey as string,
|
apiKey: credentials.apiKey as string,
|
||||||
|
|||||||
@@ -171,7 +171,7 @@
|
|||||||
"@google-ai/generativelanguage": "2.6.0",
|
"@google-ai/generativelanguage": "2.6.0",
|
||||||
"@google-cloud/resource-manager": "5.3.0",
|
"@google-cloud/resource-manager": "5.3.0",
|
||||||
"@google/generative-ai": "0.21.0",
|
"@google/generative-ai": "0.21.0",
|
||||||
"@huggingface/inference": "2.8.0",
|
"@huggingface/inference": "4.0.5",
|
||||||
"@langchain/anthropic": "catalog:",
|
"@langchain/anthropic": "catalog:",
|
||||||
"@langchain/aws": "0.1.11",
|
"@langchain/aws": "0.1.11",
|
||||||
"@langchain/cohere": "0.3.4",
|
"@langchain/cohere": "0.3.4",
|
||||||
|
|||||||
31
pnpm-lock.yaml
generated
31
pnpm-lock.yaml
generated
@@ -961,8 +961,8 @@ importers:
|
|||||||
specifier: 0.21.0
|
specifier: 0.21.0
|
||||||
version: 0.21.0
|
version: 0.21.0
|
||||||
'@huggingface/inference':
|
'@huggingface/inference':
|
||||||
specifier: 2.8.0
|
specifier: 4.0.5
|
||||||
version: 2.8.0
|
version: 4.0.5
|
||||||
'@langchain/anthropic':
|
'@langchain/anthropic':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 0.3.23(@langchain/core@0.3.61(@opentelemetry/api@1.9.0)(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(openai@5.8.1(ws@8.18.2)(zod@3.25.67)))
|
version: 0.3.23(@langchain/core@0.3.61(@opentelemetry/api@1.9.0)(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(openai@5.8.1(ws@8.18.2)(zod@3.25.67)))
|
||||||
@@ -974,7 +974,7 @@ importers:
|
|||||||
version: 0.3.4(@langchain/core@0.3.61(@opentelemetry/api@1.9.0)(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(openai@5.8.1(ws@8.18.2)(zod@3.25.67)))(encoding@0.1.13)
|
version: 0.3.4(@langchain/core@0.3.61(@opentelemetry/api@1.9.0)(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(openai@5.8.1(ws@8.18.2)(zod@3.25.67)))(encoding@0.1.13)
|
||||||
'@langchain/community':
|
'@langchain/community':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 0.3.47(438356ed01a7485a5354296e4de89428)
|
version: 0.3.47(2b92f6f7d0c28eaf0346fdac5730ff18)
|
||||||
'@langchain/core':
|
'@langchain/core':
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 0.3.61(@opentelemetry/api@1.9.0)(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(openai@5.8.1(ws@8.18.2)(zod@3.25.67))
|
version: 0.3.61(@opentelemetry/api@1.9.0)(@opentelemetry/sdk-trace-base@1.30.1(@opentelemetry/api@1.9.0))(openai@5.8.1(ws@8.18.2)(zod@3.25.67))
|
||||||
@@ -4693,12 +4693,16 @@ packages:
|
|||||||
'@hapi/topo@5.1.0':
|
'@hapi/topo@5.1.0':
|
||||||
resolution: {integrity: sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==}
|
resolution: {integrity: sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==}
|
||||||
|
|
||||||
'@huggingface/inference@2.8.0':
|
'@huggingface/inference@4.0.5':
|
||||||
resolution: {integrity: sha512-Ti681P1qckcCAqgzmL53jBnluPuZGelmMIuXNjgAwC5+RIjF4S0SDQu6oy44ZTwekwNp2ETaZ2sXsOk+45aC4w==}
|
resolution: {integrity: sha512-/Qc45BGrN+FBA3JfdeoHfafxfNShH/dxvOsXbBdcxyxIRIYOyefeiXSlShZGVCaiqYpm+10na28D0YtvjKPTlw==}
|
||||||
engines: {node: '>=18'}
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
'@huggingface/tasks@0.11.13':
|
'@huggingface/jinja@0.5.1':
|
||||||
resolution: {integrity: sha512-TqFEyFtKYAYwDg9h4XQMzoSxN2NMpwSnerPBx7Y4RbM1nHLM+CTXAUHcDY+hydcA5CoDDaBGzkHw+mttY3AmFQ==}
|
resolution: {integrity: sha512-yUZLld4lrM9iFxHCwFQ7D1HW2MWMwSbeB7WzWqFYDWK+rEb+WldkLdAJxUPOmgICMHZLzZGVcVjFh3w/YGubng==}
|
||||||
|
engines: {node: '>=18'}
|
||||||
|
|
||||||
|
'@huggingface/tasks@0.19.34':
|
||||||
|
resolution: {integrity: sha512-dIl3jyeddCEFJeogJOcbhfIq1tlo3N9K4EAxG/MfkGL0l7hI2kfs91Ut+1h6i09TQM8A9XM91NV7Jz6PgfWE7Q==}
|
||||||
|
|
||||||
'@humanfs/core@0.19.1':
|
'@humanfs/core@0.19.1':
|
||||||
resolution: {integrity: sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==}
|
resolution: {integrity: sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==}
|
||||||
@@ -19071,11 +19075,14 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@hapi/hoek': 9.3.0
|
'@hapi/hoek': 9.3.0
|
||||||
|
|
||||||
'@huggingface/inference@2.8.0':
|
'@huggingface/inference@4.0.5':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@huggingface/tasks': 0.11.13
|
'@huggingface/jinja': 0.5.1
|
||||||
|
'@huggingface/tasks': 0.19.34
|
||||||
|
|
||||||
'@huggingface/tasks@0.11.13': {}
|
'@huggingface/jinja@0.5.1': {}
|
||||||
|
|
||||||
|
'@huggingface/tasks@0.19.34': {}
|
||||||
|
|
||||||
'@humanfs/core@0.19.1': {}
|
'@humanfs/core@0.19.1': {}
|
||||||
|
|
||||||
@@ -19540,7 +19547,7 @@ snapshots:
|
|||||||
- aws-crt
|
- aws-crt
|
||||||
- encoding
|
- encoding
|
||||||
|
|
||||||
'@langchain/community@0.3.47(438356ed01a7485a5354296e4de89428)':
|
'@langchain/community@0.3.47(2b92f6f7d0c28eaf0346fdac5730ff18)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@browserbasehq/stagehand': 1.9.0(@playwright/test@1.54.2)(deepmerge@4.3.1)(dotenv@16.5.0)(encoding@0.1.13)(openai@5.8.1(ws@8.18.2)(zod@3.25.67))(zod@3.25.67)
|
'@browserbasehq/stagehand': 1.9.0(@playwright/test@1.54.2)(deepmerge@4.3.1)(dotenv@16.5.0)(encoding@0.1.13)(openai@5.8.1(ws@8.18.2)(zod@3.25.67))(zod@3.25.67)
|
||||||
'@ibm-cloud/watsonx-ai': 1.1.2
|
'@ibm-cloud/watsonx-ai': 1.1.2
|
||||||
@@ -19570,7 +19577,7 @@ snapshots:
|
|||||||
'@getzep/zep-js': 0.9.0
|
'@getzep/zep-js': 0.9.0
|
||||||
'@google-ai/generativelanguage': 2.6.0(encoding@0.1.13)
|
'@google-ai/generativelanguage': 2.6.0(encoding@0.1.13)
|
||||||
'@google-cloud/storage': 7.12.1(encoding@0.1.13)
|
'@google-cloud/storage': 7.12.1(encoding@0.1.13)
|
||||||
'@huggingface/inference': 2.8.0
|
'@huggingface/inference': 4.0.5
|
||||||
'@mozilla/readability': 0.6.0
|
'@mozilla/readability': 0.6.0
|
||||||
'@pinecone-database/pinecone': 5.1.2
|
'@pinecone-database/pinecone': 5.1.2
|
||||||
'@qdrant/js-client-rest': 1.14.1(typescript@5.9.2)
|
'@qdrant/js-client-rest': 1.14.1(typescript@5.9.2)
|
||||||
|
|||||||
Reference in New Issue
Block a user