Skip to content

Conversation

@aibysid
Copy link

@aibysid aibysid commented Nov 8, 2025

  • Upgrade @huggingface/inference from v2.6.1 to v4.13.2
  • Update ChatHuggingFace to use InferenceClient with chatCompletion API
  • Update HuggingFaceInference (LLM) to use v4 HfInference with Inference Providers
  • Update HuggingFaceInferenceEmbedding to use v4 HfInference
  • Add endpoint handling logic to ignore custom endpoints for provider-based models
  • Add improved error handling and validation for API keys
  • Update UI descriptions to guide users on proper configuration
Screenshot 2025-11-08 at 15 57 55

Fixes #5161

- Upgrade @huggingface/inference from v2.6.1 to v4.13.2
- Update ChatHuggingFace to use InferenceClient with chatCompletion API
- Update HuggingFaceInference (LLM) to use v4 HfInference with Inference Providers
- Update HuggingFaceInferenceEmbedding to use v4 HfInference
- Add endpoint handling logic to ignore custom endpoints for provider-based models
- Add improved error handling and validation for API keys
- Update UI descriptions to guide users on proper configuration

Fixes FlowiseAI#5161
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @aibysid, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the integration with Hugging Face by upgrading the underlying inference library to its latest major version. This upgrade enables the use of Hugging Face's Inference Providers, streamlines the interaction with chat models through a new client, and introduces more intelligent endpoint management. Additionally, it improves the overall user experience by providing clearer UI instructions and more robust error handling for API key and connection issues.

Highlights

  • Hugging Face Inference API Upgrade: The @huggingface/inference library has been upgraded from version 2.6.1 to 4.13.2, bringing significant changes and new capabilities.
  • ChatHuggingFace Modernization: The ChatHuggingFace component now utilizes the new InferenceClient and its chatCompletion API, aligning with the updated library's best practices for conversational models.
  • Inference Provider Support: Both HuggingFaceInference (LLM) and HuggingFaceInferenceEmbedding components have been updated to leverage the v4 HfInference and its support for Inference Providers, simplifying model access.
  • Improved Endpoint Handling: New logic has been implemented to intelligently handle custom endpoints, ensuring they are ignored for models that use Inference Providers or router endpoints, preventing conflicts and improving reliability.
  • Enhanced API Key Validation and Error Handling: Robust API key validation has been added, including checks for existence and format (hf_ prefix). More descriptive error messages are now provided for authentication and endpoint-related issues.
  • UI Guidance Updates: User interface descriptions for 'Model' and 'Endpoint' fields have been updated to provide clearer guidance on proper configuration when using Inference Providers or custom endpoints.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request upgrades the Hugging Face Inference API to a newer version, enabling support for Inference Providers. The changes are well-implemented, including updates to ChatHuggingFace, HuggingFaceInference, and HuggingFaceInferenceEmbedding to use the new InferenceClient and chatCompletion APIs. The logic to handle custom endpoints versus provider-based models is sound, and the error handling has been significantly improved. My feedback includes a couple of suggestions to improve the robustness of API key validation and to ensure consistent handling of optional parameters in API calls.

Comment on lines +127 to +128
if (!huggingFaceApiKey) {
console.error('[ChatHuggingFace] API key validation failed: No API key found')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The API key validation should also check for empty or whitespace-only strings for robustness. This is also consistent with the validation performed in core.ts.

Suggested change
if (!huggingFaceApiKey) {
console.error('[ChatHuggingFace] API key validation failed: No API key found')
if (!huggingFaceApiKey || huggingFaceApiKey.trim() === '') {
console.error('[ChatHuggingFace] API key validation failed: Empty or undefined')

Comment on lines +72 to +85
const params: any = {
temperature: this.temperature,
max_tokens: this.maxTokens,
stop: options?.stop ?? this.stopSequences,
top_p: this.topP
}
// Include optional parameters if they are defined
if (this.topK !== undefined) {
params.top_k = this.topK
}
if (this.frequencyPenalty !== undefined) {
params.frequency_penalty = this.frequencyPenalty
}
return params
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The handling of optional parameters is inconsistent. temperature, maxTokens, and topP are added to the params object unconditionally, which means they could be passed as undefined to the API. While many libraries filter out undefined properties, it's safer and more explicit to only add properties that have a defined value. This would also make the implementation consistent with how topK and frequencyPenalty are handled.

        const params: any = {};
        if (this.temperature !== undefined) params.temperature = this.temperature;
        if (this.maxTokens !== undefined) params.max_tokens = this.maxTokens;
        if (this.topP !== undefined) params.top_p = this.topP;
        if (this.topK !== undefined) params.top_k = this.topK;
        if (this.frequencyPenalty !== undefined) params.frequency_penalty = this.frequencyPenalty;
        const stop = options?.stop ?? this.stopSequences;
        if (stop) params.stop = stop;
        return params;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hugging Face Public Inference Endpoint

1 participant