Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serde issue for huggingface inference API embedding #16053

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ class HuggingFaceInferenceAPIEmbedding(BaseEmbedding): # type: ignore[misc]
" Defaults to None, meaning it will loop until the server is available."
),
)
headers: Dict[str, str] = Field(
headers: Optional[Dict[str, str]] = Field(
default=None,
description=(
"Additional headers to send to the server. By default only the"
" authorization and user-agent headers are sent. Values in this dictionary"
" will override the default values."
),
)
cookies: Dict[str, str] = Field(
cookies: Optional[Dict[str, str]] = Field(
default=None, description="Additional cookies to send to the server."
)
task: Optional[str] = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exclude = ["**/BUILD"]
license = "MIT"
name = "llama-index-embeddings-huggingface-api"
readme = "README.md"
version = "0.2.0"
version = "0.2.1"

[tool.poetry.dependencies]
python = ">=3.8.1,<4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ def test_serialization(
assert serialized["model_name"] == STUB_MODEL_NAME
# Check Hugging Face Inference API Embeddings derived class specifics
assert serialized["pooling"] == Pooling.CLS

def test_serde(
self, hf_inference_api_embedding: HuggingFaceInferenceAPIEmbedding
) -> None:
serialized = hf_inference_api_embedding.model_dump()
deserialized = HuggingFaceInferenceAPIEmbedding.model_validate(serialized)
assert deserialized.headers == hf_inference_api_embedding.headers
Loading