11import os
22from unittest .mock import MagicMock
33
4- import boto3
54import pytest
65from haystack import Document , Pipeline
76from haystack .components .builders import PromptBuilder
@@ -88,44 +87,6 @@ def test_to_dict_openai(self, monkeypatch):
8887 },
8988 }
9089
91- def test_to_dict_aws_bedrock (self , boto3_session_mock ):
92- extractor = LLMMetadataExtractor (
93- prompt = "some prompt that was used with the LLM {{document.content}}" ,
94- expected_keys = ["key1" , "key2" ],
95- generator_api = LLMProvider .AWS_BEDROCK ,
96- generator_api_params = {"model" : "meta.llama.test" },
97- raise_on_failure = True ,
98- )
99- extractor_dict = extractor .to_dict ()
100- assert extractor_dict == {
101- "type" : "haystack.components.extractors.llm_metadata_extractor.LLMMetadataExtractor" ,
102- "init_parameters" : {
103- "prompt" : "some prompt that was used with the LLM {{document.content}}" ,
104- "generator_api" : "aws_bedrock" ,
105- "generator_api_params" : {
106- "aws_access_key_id" : {"type" : "env_var" , "env_vars" : ["AWS_ACCESS_KEY_ID" ], "strict" : False },
107- "aws_secret_access_key" : {
108- "type" : "env_var" ,
109- "env_vars" : ["AWS_SECRET_ACCESS_KEY" ],
110- "strict" : False ,
111- },
112- "aws_session_token" : {"type" : "env_var" , "env_vars" : ["AWS_SESSION_TOKEN" ], "strict" : False },
113- "aws_region_name" : {"type" : "env_var" , "env_vars" : ["AWS_DEFAULT_REGION" ], "strict" : False },
114- "aws_profile_name" : {"type" : "env_var" , "env_vars" : ["AWS_PROFILE" ], "strict" : False },
115- "model" : "meta.llama.test" ,
116- "stop_words" : [],
117- "generation_kwargs" : {},
118- "streaming_callback" : None ,
119- "boto3_config" : None ,
120- "tools" : None ,
121- },
122- "expected_keys" : ["key1" , "key2" ],
123- "page_range" : None ,
124- "raise_on_failure" : True ,
125- "max_workers" : 3 ,
126- },
127- }
128-
12990 def test_from_dict_openai (self , monkeypatch ):
13091 monkeypatch .setenv ("OPENAI_API_KEY" , "test-api-key" )
13192 extractor_dict = {
@@ -151,42 +112,6 @@ def test_from_dict_openai(self, monkeypatch):
151112 assert extractor .prompt == "some prompt that was used with the LLM {{document.content}}"
152113 assert extractor .generator_api == LLMProvider .OPENAI
153114
154- def test_from_dict_aws_bedrock (self , boto3_session_mock ):
155- extractor_dict = {
156- "type" : "haystack.components.extractors.llm_metadata_extractor.LLMMetadataExtractor" ,
157- "init_parameters" : {
158- "prompt" : "some prompt that was used with the LLM {{document.content}}" ,
159- "generator_api" : "aws_bedrock" ,
160- "generator_api_params" : {
161- "aws_access_key_id" : {"type" : "env_var" , "env_vars" : ["AWS_ACCESS_KEY_ID" ], "strict" : False },
162- "aws_secret_access_key" : {
163- "type" : "env_var" ,
164- "env_vars" : ["AWS_SECRET_ACCESS_KEY" ],
165- "strict" : False ,
166- },
167- "aws_session_token" : {"type" : "env_var" , "env_vars" : ["AWS_SESSION_TOKEN" ], "strict" : False },
168- "aws_region_name" : {"type" : "env_var" , "env_vars" : ["AWS_DEFAULT_REGION" ], "strict" : False },
169- "aws_profile_name" : {"type" : "env_var" , "env_vars" : ["AWS_PROFILE" ], "strict" : False },
170- "model" : "meta.llama.test" ,
171- "stop_words" : [],
172- "generation_kwargs" : {},
173- "streaming_callback" : None ,
174- "boto3_config" : None ,
175- "tools" : None ,
176- },
177- "expected_keys" : ["key1" , "key2" ],
178- "page_range" : None ,
179- "raise_on_failure" : True ,
180- "max_workers" : 3 ,
181- },
182- }
183- extractor = LLMMetadataExtractor .from_dict (extractor_dict )
184- assert extractor .raise_on_failure is True
185- assert extractor .expected_keys == ["key1" , "key2" ]
186- assert extractor .prompt == "some prompt that was used with the LLM {{document.content}}"
187- assert extractor .generator_api == LLMProvider .AWS_BEDROCK
188- assert extractor .llm_provider .model == "meta.llama.test"
189-
190115 def test_warm_up (self , monkeypatch ):
191116 monkeypatch .setenv ("OPENAI_API_KEY" , "test-api-key" )
192117 extractor = LLMMetadataExtractor (prompt = "prompt {{document.content}}" , generator_api = LLMProvider .OPENAI )
0 commit comments