Skip to content

Commit

Permalink
Adds MetalRetriever, HugginfaceEndpoint and other bugfixes (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielluiz authored Aug 29, 2023
2 parents 7987a10 + 70e5b11 commit d5faee5
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 119 deletions.
238 changes: 128 additions & 110 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
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 = [
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def build(
self,
model_name: str,
openai_api_key: str,
openai_api_base: str,
tools: Tool,
openai_api_base: Optional[str] = None,
memory: Optional[BaseMemory] = None,
system_message: Optional[SystemMessagePromptTemplate] = None,
max_token_limit: int = 2000,
Expand Down
42 changes: 42 additions & 0 deletions src/backend/langflow/components/llms/HuggingFaceEndpoints.py
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 src/backend/langflow/components/retrievers/MetalRetriever.py
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.
3 changes: 3 additions & 0 deletions src/frontend/src/components/inputListComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ export default function InputListComponent({
}
}, [disabled]);

// @TODO Recursive Character Text Splitter - the value might be in string format, whereas the InputListComponent specifically requires an array format. To ensure smooth operation and prevent potential errors, it's crucial that we handle the conversion from a string to an array with the string as its element.
typeof value === 'string' ? value = [value] : value = value;

return (
<div
className={classNames(
Expand Down
13 changes: 6 additions & 7 deletions tests/test_llms_template.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from fastapi.testclient import TestClient
from langflow.settings import settings


def test_llms_settings(client: TestClient):
response = client.get("api/v1/all")
assert response.status_code == 200
json_response = response.json()
llms = json_response["llms"]
assert set(llms.keys()) == set(settings.LLMS)
# def test_llms_settings(client: TestClient):
# response = client.get("api/v1/all")
# assert response.status_code == 200
# json_response = response.json()
# llms = json_response["llms"]
# assert set(llms.keys()) == set(settings.LLMS)


# def test_hugging_face_hub(client: TestClient):
Expand Down

0 comments on commit d5faee5

Please sign in to comment.