Add argument for AmazonBedrock and Amazon Kendra
This commit is contained in:
parent
8abfb7a00e
commit
2cafb33b8e
2 changed files with 28 additions and 10 deletions
|
|
@ -10,7 +10,6 @@ class AmazonBedrockComponent(CustomComponent):
|
||||||
|
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
return {
|
return {
|
||||||
"credentials_profile_name": {"display_name": "Credentials Profile Name", "password": True},
|
|
||||||
"model_id": {
|
"model_id": {
|
||||||
"display_name": "Model Id",
|
"display_name": "Model Id",
|
||||||
"options": [
|
"options": [
|
||||||
|
|
@ -26,25 +25,24 @@ class AmazonBedrockComponent(CustomComponent):
|
||||||
"cohere.command-text-v14",
|
"cohere.command-text-v14",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
"model_kwargs": {
|
"credentials_profile_name": {"display_name": "Credentials Profile Name"},
|
||||||
"display_name": "Model Keyword Arguments",
|
"streaming": {
|
||||||
"field_type": "code",
|
"display_name": "Streaming",
|
||||||
|
"field_type": "bool"
|
||||||
},
|
},
|
||||||
"code": {"show": False},
|
"code": {"show": False},
|
||||||
}
|
}
|
||||||
|
|
||||||
def build(
|
def build(
|
||||||
self,
|
self,
|
||||||
credentials_profile_name: str,
|
|
||||||
model_id: str = "anthropic.claude-instant-v1",
|
model_id: str = "anthropic.claude-instant-v1",
|
||||||
model_kwargs: Optional[dict] = None,
|
credentials_profile_name: Optional[str] = None,
|
||||||
) -> BaseLLM:
|
) -> BaseLLM:
|
||||||
try:
|
try:
|
||||||
output = Bedrock(
|
output = Bedrock(
|
||||||
credentials_profile_name=credentials_profile_name,
|
credentials_profile_name=credentials_profile_name,
|
||||||
model_id=model_id,
|
model_id=model_id,
|
||||||
model_kwargs=model_kwargs,
|
) # type: ignore
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError("Could not connect to AmazonBedrock API.") from e
|
raise ValueError("Could not connect to AmazonBedrock API.") from e
|
||||||
return output
|
return output
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
from typing import Optional
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
from langchain.retrievers import AmazonKendraRetriever
|
from langchain.retrievers import AmazonKendraRetriever
|
||||||
from langchain.schema import BaseRetriever
|
from langchain.schema import BaseRetriever
|
||||||
|
|
@ -10,18 +11,37 @@ class AmazonKendraRetrieverComponent(CustomComponent):
|
||||||
def build_config(self):
|
def build_config(self):
|
||||||
return {
|
return {
|
||||||
"index_id": {"display_name": "Index ID"},
|
"index_id": {"display_name": "Index ID"},
|
||||||
|
"region_name": {"display_name": "Region Name"},
|
||||||
|
"credentials_profile_name": {"display_name": "Credentials Profile Name"},
|
||||||
"attribute_filter": {
|
"attribute_filter": {
|
||||||
"attribute_filter": "Attribute Filter",
|
"attribute_filter": "Attribute Filter",
|
||||||
"field_type": "code",
|
"field_type": "code",
|
||||||
},
|
},
|
||||||
|
"top_k": {"display_name": "Top K", "field_type": "int"},
|
||||||
|
"user_context": {
|
||||||
|
"attribute_filter": "User Context",
|
||||||
|
"field_type": "code",
|
||||||
|
},
|
||||||
"code": {"show": False},
|
"code": {"show": False},
|
||||||
}
|
}
|
||||||
|
|
||||||
def build(
|
def build(
|
||||||
self, index_id: str, attribute_filter: dict
|
self,
|
||||||
|
index_id: str,
|
||||||
|
top_k: int = 3,
|
||||||
|
region_name: Optional[str] = None,
|
||||||
|
credentials_profile_name: Optional[str] = None,
|
||||||
|
attribute_filter: Optional[dict] = None,
|
||||||
|
user_context: Optional[dict] = None,
|
||||||
) -> BaseRetriever:
|
) -> BaseRetriever:
|
||||||
try:
|
try:
|
||||||
output = AmazonKendraRetriever(index_id=index_id, attribute_filter=attribute_filter)
|
output = AmazonKendraRetriever(
|
||||||
|
index_id=index_id,
|
||||||
|
top_k=top_k,
|
||||||
|
region_name=region_name,
|
||||||
|
credentials_profile_name=credentials_profile_name,
|
||||||
|
attribute_filter=attribute_filter,
|
||||||
|
user_context=user_context) # type: ignore
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError("Could not connect to AmazonKendra API.") from e
|
raise ValueError("Could not connect to AmazonKendra API.") from e
|
||||||
return output
|
return output
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue