Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add Hugging Face as a provider#1911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Kludex merged 35 commits intopydantic:mainfromhanouticelina:hf-inference-providers
Jul 16, 2025

Conversation

hanouticelina
Copy link
Contributor

@hanouticelinahanouticelina commentedJun 4, 2025
edited
Loading

closes#1085.
Hi there, maintainer ofhuggingface_hub library 🤗 here,
This PR introduces support for Hugging Face's Inference Providers (documentationhere) as a Model Provider.

Our API is fully compatible with the OpenAI REST API spec, and the implementation closely mirrors the existingOpenAIProvider /OpenAIModel pair. Under the hood, we use thehuggingface_hub.AsyncInferenceClient client, which is a drop-in replacement of the async OpenAI client but includes provider-specific (de)serialization logic that cannot be reproduced reliably with the OpenAI client alone, see@Wauplin’s detailed explanationhere).

Note thathuggingface_hub is a stable and widely used library that was already listed as a dependency in the lockfile.

TODO:

  • Add tests.
  • Add documentation.

Wauplin, jjliggett, Luca-Blight, and scastlara reacted with hooray emojiPierrci, VyacheslavLukin, jjliggett, Luca-Blight, and scastlara reacted with rocket emoji
@KludexKludex self-assigned thisJun 5, 2025
@Kludex
Copy link
Member

Great! :)

How can I help here?

@hanouticelina
Copy link
ContributorAuthor

Hi@Kludex,
i'm currently finishing adding tests and documentation and then the PR will be ready for review! :)

@Kludex
Copy link
Member

Hi@Kludex, i'm currently finishing adding tests and documentation and then the PR will be ready for review! :)

Amazing! :)

@hyperlint-aiHyperlint AI
Copy link
Contributor

hyperlint-aibot commentedJun 9, 2025
edited
Loading

PR Change Summary

Added support for Hugging Face as a model provider, enhancing the library's capabilities for AI inference.

  • Introduced Hugging Face as a new provider for model inference.
  • Added documentation for setting up and using Hugging Face models.
  • Updated existing provider documentation to include Hugging Face provider.

Modified Files

  • docs/api/providers.md

Added Files

  • docs/api/models/huggingface.md
  • docs/models/huggingface.md

How can I customize these reviews?

Check out theHyperlint AI Reviewer docs for more information on how to customize the review.

If you just want to ignore it on this PR, you can add thehyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to addhyperlint-ignore to the PR to ignore the link check for this PR.

@hanouticelinahanouticelina marked this pull request as ready for reviewJune 9, 2025 13:05
@hanouticelina
Copy link
ContributorAuthor

Hi@Kludex,
Sorry for the delay, the PR is finally ready for review! I'll have limited availability over the next two weeks, but I'll do my best to be responsive in case you have any feedback.
At 🤗, we're super excited to get this merged!

AH-Merii reacted with rocket emoji

@hanouticelina
Copy link
ContributorAuthor

Hi@Kludex,
Just wanted to follow up now that I'm back and have a bit more time, let me know if you get a chance to take a look at the PR! 😊

@KludexKludex requested a review fromCopilotJune 25, 2025 10:41
Copilot

This comment was marked as outdated.

Comment on lines +230 to +237
'huggingface:Qwen/QwQ-32B',
'huggingface:Qwen/Qwen2.5-72B-Instruct',
'huggingface:Qwen/Qwen3-235B-A22B',
'huggingface:Qwen/Qwen3-32B',
'huggingface:deepseek-ai/DeepSeek-R1',
'huggingface:meta-llama/Llama-3.3-70B-Instruct',
'huggingface:meta-llama/Llama-4-Maverick-17B-128E-Instruct',
'huggingface:meta-llama/Llama-4-Scout-17B-16E-Instruct',
Copy link
Member

Choose a reason for hiding this comment

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

How can we keep the list of those models up-to-date? Do you folks have an endpoint that we can call to list a lot of them, or something?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

yes! we've just shippedhttps://router.huggingface.co/v1/models that returns the list of models (sorted by trending score on the Hugging Face Hub). Not sure how can I updateKnownModelName dynamically? i can do that for [LatestHuggingFaceModelNames](https://github.com/hanouticelina/pydantic-ai/blob/873f090197b6c7b8c2ae1c0760db17ef54814f86/pydantic_ai_slim/pydantic_ai/models/huggingface.py#L69, butKnownModelName needs to be update as well.

Copy link
Member

Choose a reason for hiding this comment

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

We can create a test that: if run locally, it would call that endpoint and it will check against this list of models.

In CI it should use the cassette.

Copy link
Member

@KludexKludex left a comment

Choose a reason for hiding this comment

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

I wrote some comments here.

We need to createThinkingParts (does the HuggingFace client handles them?) and we need to add code coverage.

I prefer tests strictly with VCR, if possible.

hanouticelina reacted with eyes emoji
@DouweMDouweM assignedKludex and unassignedhanouticelinaJul 7, 2025
@Kludex
Copy link
Member

Kludex commentedJul 8, 2025
edited
Loading

@hanouticelina Are you still working on this? Let me know when I should take over.

@KludexKludex assignedhanouticelina and unassignedKludexJul 8, 2025
@hanouticelina
Copy link
ContributorAuthor

Hey@Kludex,
Yes i'm still working on it, i have to finish some things before assigning it back to you, but will do as soon as i'm done! 🙂

Kludex reacted with thumbs up emoji

@hanouticelina
Copy link
ContributorAuthor

hey@Kludex,

We need to create ThinkingParts (does the HuggingFace client handles them?)

The HF client does not handleThinkingParts, in9b0edee, I added the splitting of the response content into text and thinking part, is there anything else to add for this?

@hanouticelinahanouticelina removed their assignmentJul 9, 2025
@hanouticelina
Copy link
ContributorAuthor

Hey@Kludex,
I've addressed your comments - could you take a look when you have a moment ? 🙏

@KludexKludex requested a review fromCopilotJuly 15, 2025 12:03
Copy link

@CopilotCopilotAI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Add Hugging Face as a first-class inference provider, mirroring the existing OpenAI support.

  • IntroduceHuggingFaceProvider and register it in provider selection.
  • ImplementHuggingFaceModel with full streaming and request/response handling.
  • Update tests, CLI, examples, dependencies, and documentation to include Hugging Face.

Reviewed Changes

Copilot reviewed 27 out of 28 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
pydantic_ai_slim/pydantic_ai/providers/huggingface.pyNewHuggingFaceProvider implementation
pydantic_ai_slim/pydantic_ai/models/huggingface.pyNewHuggingFaceModel implementation
tests/providers/test_huggingface.pyUnit tests for provider initialization and errors
docs/models/huggingface.mdUser documentation for Hugging Face support
pyproject.toml & pydantic_ai_slim/pyproject.tomlAddhuggingface optional dependency
Comments suppressed due to low confidence (1)

docs/models/huggingface.md:10

  • [nitpick] The installation command appears incorrect (pip/uv-add). It should bepip install "pydantic-ai-slim[huggingface]" for clarity and accuracy.
pip/uv-add "pydantic-ai-slim[huggingface]"

Copy link
Member

@KludexKludex left a comment

Choose a reason for hiding this comment

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

I think we are good here.

Thanks for handling all the coverage! :)

hanouticelina reacted with heart emoji
@KludexKludex merged commit4d755d2 intopydantic:mainJul 16, 2025
19 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

Copilot code reviewCopilotCopilot left review comments

@KludexKludexKludex approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Add HuggingFace to Models.
3 participants
@hanouticelina@Kludex@burtenshaw

[8]ページ先頭

©2009-2025 Movatter.jp