🔨 refactor(HuggingFaceEndpoints.py): update import statement for HuggingFaceEndpoint class to match new file structure

🔧 chore(HuggingFaceEndpoints.py): remove unused import statement for langchain.llms.base module

🔧 chore(HuggingFaceEndpoints.py): remove unused "type" field from task parameter in build method signature

🔧 chore(HuggingFaceEndpoints.py): add default value for task parameter in build method signature

🔧 chore(HuggingFaceEndpoints.py): add default values for huggingfacehub_api_token and model_kwargs parameters in build method signature

🐛 fix(HuggingFaceEndpoints.py): add model_kwargs parameter to HuggingFaceEndpoint constructor to fix missing argument error
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-10-12 19:22:41 -03:00
commit dad8480ce3

View file

@ -1,6 +1,6 @@
from typing import Optional
from langflow import CustomComponent
from langchain.llms import HuggingFaceEndpoint
from langchain.llms.huggingface_endpoint import HuggingFaceEndpoint
from langchain.llms.base import BaseLLM
@ -13,7 +13,6 @@ class HuggingFaceEndpointsComponent(CustomComponent):
"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},
@ -27,7 +26,7 @@ class HuggingFaceEndpointsComponent(CustomComponent):
def build(
self,
endpoint_url: str,
task="text2text-generation",
task: str = "text2text-generation",
huggingfacehub_api_token: Optional[str] = None,
model_kwargs: Optional[dict] = None,
) -> BaseLLM:
@ -36,6 +35,7 @@ class HuggingFaceEndpointsComponent(CustomComponent):
endpoint_url=endpoint_url,
task=task,
huggingfacehub_api_token=huggingfacehub_api_token,
model_kwargs=model_kwargs,
)
except Exception as e:
raise ValueError("Could not connect to HuggingFace Endpoints API.") from e