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:
Mutasem Aldmour
2025-08-06 14:29:10 +02:00
committed by GitHub
parent 2a5c1e2152
commit a1682e8fe4
5 changed files with 48 additions and 16 deletions

View File

@@ -34,8 +34,8 @@ export class HuggingFaceApi implements ICredentialType {
test: ICredentialTestRequest = {
request: {
baseURL: 'https://api-inference.huggingface.co',
url: '/models/gpt2',
baseURL: 'https://huggingface.co',
url: '/api/whoami-v2',
},
};
}

View File

@@ -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 {
NodeConnectionTypes,
NodeOperationError,
type INodeType,
type INodeTypeDescription,
type ISupplyDataFunctions,
@@ -76,6 +79,13 @@ export class EmbeddingsHuggingFaceInference implements INodeType {
description: 'Custom endpoint URL',
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 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({
apiKey: credentials.apiKey as string,
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)
);
}

View File

@@ -55,7 +55,7 @@ export class LmOpenHuggingFaceInference implements INodeType {
displayName: 'Model',
name: 'model',
type: 'string',
default: 'gpt2',
default: 'mistralai/Mistral-Nemo-Base-2407',
},
{
displayName: 'Options',
@@ -139,6 +139,11 @@ export class LmOpenHuggingFaceInference implements INodeType {
const modelName = this.getNodeParameter('model', itemIndex) as string;
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({
model: modelName,
apiKey: credentials.apiKey as string,

View File

@@ -171,7 +171,7 @@
"@google-ai/generativelanguage": "2.6.0",
"@google-cloud/resource-manager": "5.3.0",
"@google/generative-ai": "0.21.0",
"@huggingface/inference": "2.8.0",
"@huggingface/inference": "4.0.5",
"@langchain/anthropic": "catalog:",
"@langchain/aws": "0.1.11",
"@langchain/cohere": "0.3.4",

31
pnpm-lock.yaml generated
View File

@@ -961,8 +961,8 @@ importers:
specifier: 0.21.0
version: 0.21.0
'@huggingface/inference':
specifier: 2.8.0
version: 2.8.0
specifier: 4.0.5
version: 4.0.5
'@langchain/anthropic':
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)))
@@ -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)
'@langchain/community':
specifier: 'catalog:'
version: 0.3.47(438356ed01a7485a5354296e4de89428)
version: 0.3.47(2b92f6f7d0c28eaf0346fdac5730ff18)
'@langchain/core':
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))
@@ -4693,12 +4693,16 @@ packages:
'@hapi/topo@5.1.0':
resolution: {integrity: sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==}
'@huggingface/inference@2.8.0':
resolution: {integrity: sha512-Ti681P1qckcCAqgzmL53jBnluPuZGelmMIuXNjgAwC5+RIjF4S0SDQu6oy44ZTwekwNp2ETaZ2sXsOk+45aC4w==}
'@huggingface/inference@4.0.5':
resolution: {integrity: sha512-/Qc45BGrN+FBA3JfdeoHfafxfNShH/dxvOsXbBdcxyxIRIYOyefeiXSlShZGVCaiqYpm+10na28D0YtvjKPTlw==}
engines: {node: '>=18'}
'@huggingface/tasks@0.11.13':
resolution: {integrity: sha512-TqFEyFtKYAYwDg9h4XQMzoSxN2NMpwSnerPBx7Y4RbM1nHLM+CTXAUHcDY+hydcA5CoDDaBGzkHw+mttY3AmFQ==}
'@huggingface/jinja@0.5.1':
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':
resolution: {integrity: sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==}
@@ -19071,11 +19075,14 @@ snapshots:
dependencies:
'@hapi/hoek': 9.3.0
'@huggingface/inference@2.8.0':
'@huggingface/inference@4.0.5':
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': {}
@@ -19540,7 +19547,7 @@ snapshots:
- aws-crt
- encoding
'@langchain/community@0.3.47(438356ed01a7485a5354296e4de89428)':
'@langchain/community@0.3.47(2b92f6f7d0c28eaf0346fdac5730ff18)':
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)
'@ibm-cloud/watsonx-ai': 1.1.2
@@ -19570,7 +19577,7 @@ snapshots:
'@getzep/zep-js': 0.9.0
'@google-ai/generativelanguage': 2.6.0(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
'@pinecone-database/pinecone': 5.1.2
'@qdrant/js-client-rest': 1.14.1(typescript@5.9.2)