Skip to content

Commit

Permalink
fix(bedrock): fix error 'Key cache already exists' (langflow-ai#2423)
Browse files Browse the repository at this point in the history
* bedrock: fix error 'Key cache already exists'

* [autofix.ci] apply automated fixes

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 2, 2024
1 parent 0494bc2 commit 9bc683b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from langflow.base.constants import STREAM_INFO_TEXT
from langflow.base.models.model import LCModelComponent
from langflow.field_typing import LanguageModel
from langflow.io import BoolInput, DictInput, DropdownInput, MessageInput, Output, StrInput
from langflow.inputs import MessageTextInput
from langflow.io import BoolInput, DictInput, DropdownInput, MessageInput, Output


class AmazonBedrockComponent(LCModelComponent):
Expand Down Expand Up @@ -51,12 +52,11 @@ class AmazonBedrockComponent(LCModelComponent):
],
value="anthropic.claude-3-haiku-20240307-v1:0",
),
StrInput(name="credentials_profile_name", display_name="Credentials Profile Name"),
StrInput(name="region_name", display_name="Region Name"),
DictInput(name="model_kwargs", display_name="Model Kwargs", advanced=True),
StrInput(name="endpoint_url", display_name="Endpoint URL"),
BoolInput(name="cache", display_name="Cache"),
StrInput(
MessageTextInput(name="credentials_profile_name", display_name="Credentials Profile Name"),
MessageTextInput(name="region_name", display_name="Region Name", value="us-east-1"),
DictInput(name="model_kwargs", display_name="Model Kwargs", advanced=True, is_list=True),
MessageTextInput(name="endpoint_url", display_name="Endpoint URL", advanced=True),
MessageTextInput(
name="system_message",
display_name="System Message",
info="System message to pass to the model.",
Expand All @@ -75,7 +75,6 @@ def build_model(self) -> LanguageModel: # type: ignore[type-var]
region_name = self.region_name
model_kwargs = self.model_kwargs
endpoint_url = self.endpoint_url
cache = self.cache
stream = self.stream
try:
output = ChatBedrock( # type: ignore
Expand All @@ -85,7 +84,6 @@ def build_model(self) -> LanguageModel: # type: ignore[type-var]
model_kwargs=model_kwargs,
endpoint_url=endpoint_url,
streaming=stream,
cache=cache,
)
except Exception as e:
raise ValueError("Could not connect to AmazonBedrock API.") from e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def set_attributes(self, params: dict):
_attributes = {}
for key, value in params.items():
if key in self.__dict__:
raise ValueError(f"Key {key} already exists in {self.__class__.__name__}")
raise ValueError(
f"{self.__class__.__name__} defines an input parameter named '{key}' "
f"that is a reserved word and cannot be used."
)
_attributes[key] = value
for key, input_obj in self._inputs.items():
if key not in _attributes:
Expand Down

0 comments on commit 9bc683b

Please sign in to comment.