Add Amazon Bedrock Support

This commit is contained in:
Yuki Sekiya 2023-10-15 01:11:40 +09:00
commit 6d9bd1ae71
3 changed files with 161 additions and 329 deletions

439
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -90,6 +90,7 @@ langfuse = "^1.0.13"
pillow = "^10.0.0"
metal-sdk = "^2.2.0"
markupsafe = "^2.1.3"
boto3 = "^1.28.63"
[tool.poetry.group.dev.dependencies]

View file

@ -0,0 +1,50 @@
from typing import Optional
from langflow import CustomComponent
from langchain.llms.bedrock import Bedrock
from langchain.llms.base import BaseLLM
class AmazonBedrockComponent(CustomComponent):
display_name: str = "Amazon Bedrock"
description: str = "LLM model from Amazon Bedrock."
def build_config(self):
return {
"credentials_profile_name": {"display_name": "Credentials Profile Name", "password": True},
"model_id": {
"display_name": "Model Id",
"options": [
"ai21.j2-grande-instruct",
"ai21.j2-jumbo-instruct",
"ai21.j2-mid",
"ai21.j2-mid-v1",
"ai21.j2-ultra",
"ai21.j2-ultra-v1",
"anthropic.claude-instant-v1",
"anthropic.claude-v1",
"anthropic.claude-v2",
"cohere.command-text-v14",
],
},
"model_kwargs": {
"display_name": "Model Keyword Arguments",
"field_type": "code",
},
"code": {"show": False},
}
def build(
self,
credentials_profile_name: str,
model_id: str = "anthropic.claude-instant-v1",
model_kwargs: Optional[dict] = None,
) -> BaseLLM:
try:
output = Bedrock(
credentials_profile_name=credentials_profile_name,
model_id=model_id,
model_kwargs=model_kwargs,
)
except Exception as e:
raise ValueError("Could not connect to Test Endpoints API.") from e
return output