-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds MetalRetriever, HugginfaceEndpoint and other bugfixes (#837)
- Loading branch information
Showing
9 changed files
with
210 additions
and
119 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "langflow" | ||
version = "0.4.16" | ||
version = "0.4.17" | ||
description = "A Python package with a built-in web application" | ||
authors = ["Logspace <[email protected]>"] | ||
maintainers = [ | ||
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/backend/langflow/components/llms/HuggingFaceEndpoints.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import Optional | ||
from langflow import CustomComponent | ||
from langchain.llms import HuggingFaceEndpoint | ||
from langchain.llms.base import BaseLLM | ||
|
||
|
||
class HuggingFaceEndpointsComponent(CustomComponent): | ||
display_name: str = "Hugging Face Inference API" | ||
description: str = "LLM model from Hugging Face Inference API." | ||
|
||
def build_config(self): | ||
return { | ||
"endpoint_url": {"display_name": "Endpoint URL", "password": True}, | ||
"task": { | ||
"display_name": "Task", | ||
"type": "select", | ||
"options": ["text2text-generation", "text-generation", "summarization"], | ||
}, | ||
"huggingfacehub_api_token": {"display_name": "API token", "password": True}, | ||
"model_kwargs": { | ||
"display_name": "Model Keyword Arguments", | ||
"field_type": "code", | ||
}, | ||
"code": {"show": False}, | ||
} | ||
|
||
def build( | ||
self, | ||
endpoint_url: str, | ||
task="text2text-generation", | ||
huggingfacehub_api_token: Optional[str] = None, | ||
model_kwargs: Optional[dict] = None, | ||
) -> BaseLLM: | ||
try: | ||
output = HuggingFaceEndpoint( | ||
endpoint_url=endpoint_url, | ||
task=task, | ||
huggingfacehub_api_token=huggingfacehub_api_token, | ||
) | ||
except Exception as e: | ||
raise ValueError("Could not connect to HuggingFace Endpoints API.") from e | ||
return output |
Empty file.
28 changes: 28 additions & 0 deletions
28
src/backend/langflow/components/retrievers/MetalRetriever.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters