diff --git a/packages/components/nodes/chatmodels/ChatHuggingFace/core.ts b/packages/components/nodes/chatmodels/ChatHuggingFace/core.ts index 958e9072e..416567f0d 100644 --- a/packages/components/nodes/chatmodels/ChatHuggingFace/core.ts +++ b/packages/components/nodes/chatmodels/ChatHuggingFace/core.ts @@ -78,9 +78,7 @@ export class HuggingFaceInference extends LLM implements HFInput { async _call(prompt: string, options: this['ParsedCallOptions']): Promise { const { HfInference } = await HuggingFaceInference.imports() const hf = new HfInference(this.apiKey) - if (this.endpoint) hf.endpoint(this.endpoint) - const res = await this.caller.callWithOptions({ signal: options.signal }, hf.textGeneration.bind(hf), { - model: this.model, + const obj: any = { parameters: { // make it behave similar to openai, returning only the generated text return_full_text: false, @@ -91,7 +89,13 @@ export class HuggingFaceInference extends LLM implements HFInput { repetition_penalty: this.frequencyPenalty }, inputs: prompt - }) + } + if (this.endpoint) { + hf.endpoint(this.endpoint) + } else { + obj.model = this.model + } + const res = await this.caller.callWithOptions({ signal: options.signal }, hf.textGeneration.bind(hf), obj) return res.generated_text } diff --git a/packages/components/nodes/embeddings/HuggingFaceInferenceEmbedding/core.ts b/packages/components/nodes/embeddings/HuggingFaceInferenceEmbedding/core.ts index b8d89ebee..41e63aa49 100644 --- a/packages/components/nodes/embeddings/HuggingFaceInferenceEmbedding/core.ts +++ b/packages/components/nodes/embeddings/HuggingFaceInferenceEmbedding/core.ts @@ -30,12 +30,11 @@ export class HuggingFaceInferenceEmbeddings extends Embeddings implements Huggin async _embed(texts: string[]): Promise { // replace newlines, which can negatively affect performance. const clean = texts.map((text) => text.replace(/\n/g, ' ')) - return this.caller.call(() => - this.client.featureExtraction({ - model: this.model, - inputs: clean - }) - ) as Promise + const obj: any = { + inputs: clean + } + if (!this.endpoint) obj.model = this.model + return this.caller.call(() => this.client.featureExtraction(obj)) as Promise } embedQuery(document: string): Promise { diff --git a/packages/components/nodes/llms/HuggingFaceInference/core.ts b/packages/components/nodes/llms/HuggingFaceInference/core.ts index 958e9072e..416567f0d 100644 --- a/packages/components/nodes/llms/HuggingFaceInference/core.ts +++ b/packages/components/nodes/llms/HuggingFaceInference/core.ts @@ -78,9 +78,7 @@ export class HuggingFaceInference extends LLM implements HFInput { async _call(prompt: string, options: this['ParsedCallOptions']): Promise { const { HfInference } = await HuggingFaceInference.imports() const hf = new HfInference(this.apiKey) - if (this.endpoint) hf.endpoint(this.endpoint) - const res = await this.caller.callWithOptions({ signal: options.signal }, hf.textGeneration.bind(hf), { - model: this.model, + const obj: any = { parameters: { // make it behave similar to openai, returning only the generated text return_full_text: false, @@ -91,7 +89,13 @@ export class HuggingFaceInference extends LLM implements HFInput { repetition_penalty: this.frequencyPenalty }, inputs: prompt - }) + } + if (this.endpoint) { + hf.endpoint(this.endpoint) + } else { + obj.model = this.model + } + const res = await this.caller.callWithOptions({ signal: options.signal }, hf.textGeneration.bind(hf), obj) return res.generated_text }