Adds Metal Retriever Component (#828)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-08-28 11:43:34 +00:00 committed by GitHub
commit 4d0771c9c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 1 deletions

17
poetry.lock generated
View file

@ -3280,6 +3280,21 @@ files = [
{file = "mdurl-0.1.2.tar.gz", hash = "sha256:bb413d29f5eea38f31dd4754dd7377d4465116fb207585f97bf925588687c1ba"},
]
[[package]]
name = "metal-sdk"
version = "2.0.2"
description = "SDK for getmetal.io"
optional = false
python-versions = ">=3.7"
files = [
{file = "metal_sdk-2.0.2-py3-none-any.whl", hash = "sha256:a5a95fb3796979085965667ffc41fd9eeddc87b60671619671a0eaebd0bec4a1"},
{file = "metal_sdk-2.0.2.tar.gz", hash = "sha256:e5e35d230f00b1b838cfcffbcb7042f450b23b59448f37bdd385761871a1490d"},
]
[package.dependencies]
httpx = "*"
typing-extensions = "*"
[[package]]
name = "metaphor-python"
version = "0.1.16"
@ -7467,4 +7482,4 @@ local = ["ctransformers", "llama-cpp-python", "sentence-transformers"]
[metadata]
lock-version = "2.0"
python-versions = ">=3.9,<3.11"
content-hash = "36e1f79f4e6d2e55b652d10e43ccde639714ffff2965fa52b466bd854259ebf6"
content-hash = "35b3782f944eff6bd6676ea060b36adb51ee78e19c5ef4d8a2c08c163f87ce9a"

View file

@ -80,6 +80,7 @@ fastavro = "^1.8.0"
langchain-experimental = "^0.0.8"
metaphor-python = "^0.1.11"
pillow = "^10.0.0"
metal-sdk = "^2.0.2"
[tool.poetry.group.dev.dependencies]
black = "^23.1.0"

View file

@ -0,0 +1,28 @@
from typing import Optional
from langflow import CustomComponent
from langchain.retrievers import MetalRetriever
from langchain.schema import BaseRetriever
from metal_sdk.metal import Metal # type: ignore
class MetalRetrieverComponent(CustomComponent):
display_name: str = "Metal Retriever"
description: str = "Retriever that uses the Metal API."
def build_config(self):
return {
"api_key": {"display_name": "API Key", "password": True},
"client_id": {"display_name": "Client ID", "password": True},
"index_id": {"display_name": "Index ID"},
"params": {"display_name": "Parameters", "field_type": "code"},
"code": {"show": False},
}
def build(
self, api_key: str, client_id: str, index_id: str, params: Optional[dict] = None
) -> BaseRetriever:
try:
metal = Metal(api_key=api_key, client_id=client_id, index_id=index_id)
except Exception as e:
raise ValueError("Could not connect to Metal API.") from e
return MetalRetriever(client=metal, params=params or {})