Skip to content

Commit 700f44d

Browse files
committed
rm serde methods
1 parent 707c877 commit 700f44d

4 files changed

Lines changed: 8 additions & 61 deletions

File tree

integrations/vllm/src/haystack_integrations/components/embedders/vllm/document_embedder.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from dataclasses import replace
66
from typing import Any
77

8-
from haystack import Document, component, default_from_dict, default_to_dict, logging
8+
from haystack import Document, component, logging
99
from haystack.utils import Secret
1010
from more_itertools import batched
1111
from openai import APIError, AsyncOpenAI, OpenAI
@@ -146,36 +146,6 @@ def warm_up(self) -> None:
146146
)
147147
self._is_warmed_up = True
148148

149-
def to_dict(self) -> dict[str, Any]:
150-
"""
151-
Serialize this component to a dictionary.
152-
153-
:returns: The serialized component as a dictionary.
154-
"""
155-
return default_to_dict(
156-
self,
157-
model=self.model,
158-
api_key=self.api_key,
159-
api_base_url=self.api_base_url,
160-
prefix=self.prefix,
161-
suffix=self.suffix,
162-
dimensions=self.dimensions,
163-
batch_size=self.batch_size,
164-
progress_bar=self.progress_bar,
165-
meta_fields_to_embed=self.meta_fields_to_embed,
166-
embedding_separator=self.embedding_separator,
167-
timeout=self.timeout,
168-
max_retries=self.max_retries,
169-
http_client_kwargs=self.http_client_kwargs,
170-
raise_on_failure=self.raise_on_failure,
171-
extra_parameters=self.extra_parameters,
172-
)
173-
174-
@classmethod
175-
def from_dict(cls, data: dict[str, Any]) -> "VLLMDocumentEmbedder":
176-
"""Deserialize this component from a dictionary."""
177-
return default_from_dict(cls, data)
178-
179149
def _prepare_texts_to_embed(self, documents: list[Document]) -> dict[str, str]:
180150
"""Concatenate each Document's text with the selected meta fields."""
181151
texts_to_embed = {}

integrations/vllm/src/haystack_integrations/components/embedders/vllm/text_embedder.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from typing import Any
66

7-
from haystack import component, default_from_dict, default_to_dict
7+
from haystack import component
88
from haystack.utils import Secret
99
from openai import AsyncOpenAI, OpenAI
1010
from openai.types import CreateEmbeddingResponse
@@ -118,31 +118,6 @@ def warm_up(self) -> None:
118118
)
119119
self._is_warmed_up = True
120120

121-
def to_dict(self) -> dict[str, Any]:
122-
"""
123-
Serialize this component to a dictionary.
124-
125-
:returns: The serialized component as a dictionary.
126-
"""
127-
return default_to_dict(
128-
self,
129-
model=self.model,
130-
api_key=self.api_key.to_dict() if self.api_key else None,
131-
api_base_url=self.api_base_url,
132-
prefix=self.prefix,
133-
suffix=self.suffix,
134-
dimensions=self.dimensions,
135-
timeout=self.timeout,
136-
max_retries=self.max_retries,
137-
http_client_kwargs=self.http_client_kwargs,
138-
extra_parameters=self.extra_parameters,
139-
)
140-
141-
@classmethod
142-
def from_dict(cls, data: dict[str, Any]) -> "VLLMTextEmbedder":
143-
"""Deserialize this component from a dictionary."""
144-
return default_from_dict(cls, data)
145-
146121
def _prepare_input(self, text: str) -> dict[str, Any]:
147122
if not isinstance(text, str):
148123
msg = (

integrations/vllm/tests/test_document_embedder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77
import pytest
88
from haystack import Document
9+
from haystack.core.serialization import component_from_dict, component_to_dict
910
from haystack.utils import Secret
1011
from openai import APIError
1112
from openai.types import CreateEmbeddingResponse, Embedding
@@ -96,7 +97,7 @@ def test_warm_up(self, monkeypatch):
9697
def test_to_dict(self, monkeypatch):
9798
monkeypatch.delenv("VLLM_API_KEY", raising=False)
9899

99-
component_dict = VLLMDocumentEmbedder(model=MODEL).to_dict()
100+
component_dict = component_to_dict(VLLMDocumentEmbedder(model=MODEL), "embedder")
100101
assert component_dict == {
101102
"type": "haystack_integrations.components.embedders.vllm.document_embedder.VLLMDocumentEmbedder",
102103
"init_parameters": {
@@ -140,7 +141,7 @@ def test_from_dict(self, monkeypatch):
140141
"extra_parameters": None,
141142
},
142143
}
143-
embedder = VLLMDocumentEmbedder.from_dict(data)
144+
embedder = component_from_dict(VLLMDocumentEmbedder, data, "embedder")
144145
assert embedder.api_key == Secret.from_env_var("VLLM_API_KEY", strict=False)
145146
assert embedder.model == MODEL
146147
assert embedder.api_base_url == "http://localhost:8000/v1"

integrations/vllm/tests/test_text_embedder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from unittest.mock import AsyncMock, MagicMock
55

66
import pytest
7+
from haystack.core.serialization import component_from_dict, component_to_dict
78
from haystack.utils import Secret
89
from openai.types import CreateEmbeddingResponse, Embedding
910
from openai.types.create_embedding_response import Usage
@@ -84,7 +85,7 @@ def test_warm_up(self, monkeypatch):
8485
def test_to_dict(self, monkeypatch):
8586
monkeypatch.delenv("VLLM_API_KEY", raising=False)
8687

87-
component_dict = VLLMTextEmbedder(model=MODEL).to_dict()
88+
component_dict = component_to_dict(VLLMTextEmbedder(model=MODEL), "embedder")
8889
assert component_dict == {
8990
"type": "haystack_integrations.components.embedders.vllm.text_embedder.VLLMTextEmbedder",
9091
"init_parameters": {
@@ -118,7 +119,7 @@ def test_from_dict(self, monkeypatch):
118119
"extra_parameters": None,
119120
},
120121
}
121-
embedder = VLLMTextEmbedder.from_dict(data)
122+
embedder = component_from_dict(VLLMTextEmbedder, data, "embedder")
122123
assert embedder.api_key == Secret.from_env_var("VLLM_API_KEY", strict=False)
123124
assert embedder.model == MODEL
124125
assert embedder.api_base_url == "http://localhost:8000/v1"

0 commit comments

Comments
 (0)