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: LLMMetadataExtractor serialisation #136

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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 @@ -228,11 +228,12 @@ def to_dict(self) -> Dict[str, Any]:
return default_to_dict(
self,
prompt=self.prompt,
input_text=self.prompt_variable,
prompt_variable=self.prompt_variable,
expected_keys=self.expected_keys,
raise_on_failure=self.raise_on_failure,
generator_api=self.generator_api.value,
generator_api_params=llm_provider["init_parameters"],
page_range=self.expanded_range
)

@classmethod
Expand Down
7 changes: 5 additions & 2 deletions test/components/extractors/test_llm_metadata_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_init_missing_prompt_variable(self, monkeypatch):
prompt_variable="test2"
)

def test_to_dict(self, monkeypatch):
def test_to_dict_default_params(self, monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "test-api-key")
extractor = LLMMetadataExtractor(
prompt="some prompt that was used with the LLM {{test}}",
Expand All @@ -68,15 +68,18 @@ def test_to_dict(self, monkeypatch):
prompt_variable="test",
generator_api_params={'model': 'gpt-4o-mini', 'generation_kwargs': {"temperature": 0.5}},
raise_on_failure=True)

extractor_dict = extractor.to_dict()

assert extractor_dict == {
'type': 'haystack_experimental.components.extractors.llm_metadata_extractor.LLMMetadataExtractor',
'init_parameters': {
'prompt': 'some prompt that was used with the LLM {{test}}',
'expected_keys': ['key1', 'key2'],
'raise_on_failure': True,
'input_text': 'test',
'prompt_variable': 'test',
'generator_api': 'openai',
'page_range': None,
'generator_api_params': {
'api_base_url': None,
'api_key': {'env_vars': ['OPENAI_API_KEY'],'strict': True,'type': 'env_var'},
Expand Down
Loading