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
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
35 commits
Select commitHold shift + click to select a range
2c3b9cb
add hf inference providers support
hanouticelinaJun 4, 2025
537a657
update dependencies
hanouticelinaJun 4, 2025
af602a5
nit
hanouticelinaJun 4, 2025
1f3f7a2
update docstring
hanouticelinaJun 4, 2025
bea050c
add tests
hanouticelinaJun 9, 2025
40aef2e
add docs and known models for hf
hanouticelinaJun 9, 2025
af6fa42
Merge branch 'main' of github.com:hanouticelina/pydantic-ai into hf-i…
hanouticelinaJun 9, 2025
7a4b9a4
fix imports in test
hanouticelinaJun 9, 2025
a153081
fix tests
hanouticelinaJun 9, 2025
2f0ec51
fix provider test
hanouticelinaJun 9, 2025
69aee55
adapt cli test
hanouticelinaJun 9, 2025
f68dace
re-record vcr cassettes
hanouticelinaJun 9, 2025
cc982e5
fix token name
hanouticelinaJun 9, 2025
00da46e
fix examples test
hanouticelinaJun 9, 2025
bb20a34
Merge remote-tracking branch 'origin/main' into hf-inference-providers
KludexJun 25, 2025
922fd13
Add API docs and refactor a bit the wording
KludexJun 25, 2025
c779503
Merge branch 'main' of github.com:hanouticelina/pydantic-ai into hf-i…
hanouticelinaJul 2, 2025
873f090
Merge branch 'hf-inference-providers' of github.com:hanouticelina/pyd…
hanouticelinaJul 2, 2025
adfc254
review suggestions
hanouticelinaJul 2, 2025
e4af59e
more tests
hanouticelinaJul 7, 2025
fbead3d
Merge branch 'main' of github.com:hanouticelina/pydantic-ai into hf-i…
hanouticelinaJul 7, 2025
cd76d78
fix test
hanouticelinaJul 7, 2025
13ebbf9
fix another test
hanouticelinaJul 7, 2025
b96b710
add more vcr tests
hanouticelinaJul 9, 2025
9b0edee
split thinking part
hanouticelinaJul 9, 2025
6da1cf2
fix tests
hanouticelinaJul 9, 2025
d546e04
add more context to hugging face models page
burtenshawJul 9, 2025
789c261
Update docs/models/huggingface.md
hanouticelinaJul 9, 2025
17b74d2
Merge pull request #1 from burtenshaw/docs/inference-providers-docs
hanouticelinaJul 9, 2025
96a9c96
add more tests
hanouticelinaJul 9, 2025
0c37e41
Merge branch 'hf-inference-providers' of github.com:hanouticelina/pyd…
hanouticelinaJul 9, 2025
60e5c74
coverage
hanouticelinaJul 9, 2025
f2a74dd
remove no-cover
hanouticelinaJul 9, 2025
eb4af3f
Merge remote-tracking branch 'origin/main' into hf-inference-providers
KludexJul 16, 2025
9539909
replace exception handling
KludexJul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Add API docs and refactor a bit the wording
  • Loading branch information
@Kludex
Kludex committedJun 25, 2025
commit922fd13161f3a06cd6f95f43d28cb207e278b33e
7 changes: 7 additions & 0 deletionsdocs/api/models/huggingface.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
# `pydantic_ai.models.huggingface`

## Setup

For details on how to set up authentication with this model, see [model configuration for Hugging Face](../../models/huggingface.md).

::: pydantic_ai.models.huggingface
2 changes: 2 additions & 0 deletionsdocs/api/providers.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,3 +29,5 @@
::: pydantic_ai.providers.heroku.HerokuProvider

::: pydantic_ai.providers.openrouter.OpenRouterProvider

::: pydantic_ai.providers.huggingface.HuggingFaceProvider
27 changes: 17 additions & 10 deletionsdocs/models/huggingface.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
# Hugging Face


## Install

To use `HuggingFace`, you need to either install `pydantic-ai`, or install `pydantic-ai-slim` with the `huggingface` optional group:
To use `HuggingFaceModel`, you need to either install `pydantic-ai`, or install `pydantic-ai-slim` with the `huggingface` optional group:

```bash
pip/uv-add "pydantic-ai-slim[huggingface]"
```

## Configuration

To use `HuggingFaceModel` through their main API, go to [Inference Providers documentation](https://huggingface.co/docs/inference-providers/pricing) for all the details, and you can generate a Hugging Face Token here: https://huggingface.co/settings/tokens.
To use [HuggingFace](https://huggingface.co/) through their main API, go to
[Inference Providers documentation](https://huggingface.co/docs/inference-providers/pricing) for all the details,
and you can generate a Hugging Face access token here: https://huggingface.co/settings/tokens.

##Environment variable
##Hugging Face access token

Once you have aHuggingFace Token, you can set it as an environment variable:
Once you have aHugging Face access token, you can set it as an environment variable:

```bash
export HF_TOKEN='hf_token'
```

You can then use `HuggingFaceModel` by name:
You can then use[`HuggingFaceModel`][pydantic_ai.models.huggingface.HuggingFaceModel] by name:

```python
from pydantic_ai import Agent
Expand All@@ -41,12 +42,15 @@ agent = Agent(model)
...
```

By default, the `HuggingFaceModel` uses the `HuggingFaceProvider` that will select automatically the first of the inference providers (Cerebras, Together AI, Cohere..etc) available for the model, sorted by your preferred order in https://hf.co/settings/inference-providers.
By default, the [`HuggingFaceModel`][pydantic_ai.models.huggingface.HuggingFaceModel] uses the
[`HuggingFaceProvider`][pydantic_ai.providers.huggingface.HuggingFaceProvider] that will select automatically
the first of the inference providers (Cerebras, Together AI, Cohere..etc) available for the model, sorted by your
preferred order in https://hf.co/settings/inference-providers.

## Configure the provider

If you want to pass parameters in code to the provider, you can programmatically instantiate the
[HuggingFaceProvider][pydantic_ai.providers.huggingface.HuggingFaceProvider] and pass it to the model:
[`HuggingFaceProvider`][pydantic_ai.providers.huggingface.HuggingFaceProvider] and pass it to the model:

```python
from pydantic_ai import Agent
Expand All@@ -58,9 +62,12 @@ agent = Agent(model)
...
```

## Custom Hugging FaceClient
## Custom Hugging Faceclient

`HuggingFaceProvider` also accepts a custom `AsyncInferenceClient` client via the `hf_client` parameter, so you can customise the `headers`, `bill_to` (billing to an HF organization you're a member of), `base_url` etc. as defined in the [Hugging Face Hub python library docs](https://huggingface.co/docs/huggingface_hub/package_reference/inference_client).
[`HuggingFaceProvider`][pydantic_ai.providers.huggingface.HuggingFaceProvider] also accepts a custom
[`AsyncInferenceClient`][huggingface_hub.AsyncInferenceClient] client via the `hf_client` parameter, so you can customise
the `headers`, `bill_to` (billing to an HF organization you're a member of), `base_url` etc. as defined in the
[Hugging Face Hub python library docs](https://huggingface.co/docs/huggingface_hub/package_reference/inference_client).

```python
from huggingface_hub import AsyncInferenceClient
Expand Down
1 change: 1 addition & 0 deletionsmkdocs.yml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,6 +81,7 @@ nav:
- api/models/gemini.md
- api/models/google.md
- api/models/groq.md
- api/models/huggingface.md
- api/models/instrumented.md
- api/models/mistral.md
- api/models/test.md
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp