🔧 fix(__init__.py): update import statement for CustomComponent to reflect new location

🔧 fix(constants.py): update import statement for CustomComponent to reflect new location
🔧 fix(constants.py): update field_config to build_config to match changes in CustomComponent class
🔧 fix(constants.py): update build method signature to match changes in CustomComponent class
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-27 07:02:14 -03:00
commit 8d8fae78c8
2 changed files with 7 additions and 7 deletions

View file

@ -1,7 +1,7 @@
from importlib import metadata
from langflow.cache import cache_manager
from langflow.processing.process import load_flow_from_json
from langflow.utils.types import Prompt
from langflow.interface.custom.custom_component import CustomComponent
try:
__version__ = metadata.version(__package__)
@ -10,4 +10,4 @@ except metadata.PackageNotFoundError:
__version__ = ""
del metadata # optional, avoids polluting the results of dir(__package__)
__all__ = ["load_flow_from_json", "cache_manager", "Prompt"]
__all__ = ["load_flow_from_json", "cache_manager", "CustomComponent"]

View file

@ -35,8 +35,7 @@ CUSTOM_COMPONENT_SUPPORTED_TYPES = {
DEFAULT_CUSTOM_COMPONENT_CODE = """
from langflow import Prompt
from langflow.interface.custom.custom_component import CustomComponent
from langflow import CustomComponent
from langchain.llms.base import BaseLLM
from langchain.chains import LLMChain
@ -48,11 +47,12 @@ import requests
class YourComponent(CustomComponent):
display_name: str = "Your Component"
description: str = "Your description"
field_config = { "url": { "multiline": True, "required": True } }
def build(self, url: str, llm: BaseLLM, template: Prompt) -> Document:
def build_config(self):
return { "url": { "multiline": True, "required": True } }
def build(self, url: str, llm: BaseLLM, prompt: PromptTemplate) -> Document:
response = requests.get(url)
prompt = PromptTemplate.from_template(template)
chain = LLMChain(llm=llm, prompt=prompt)
result = chain.run(response.text[:300])
return Document(page_content=str(result))