✨ feat(custom.py): add new custom component 'YourComponent' to the project
This commit adds a new file 'custom.py' under the 'src/backend/langflow/components/custom_components' directory. The file contains the implementation of a custom component called 'YourComponent'. The 'YourComponent' class extends the 'CustomComponent' class from the 'langflow' library. It has a display name of "Custom Component" and a description of "My description". The component has a 'build_config' method that returns a configuration object with a single property 'url'. The 'url' property is multiline and required. The 'build' method of the component takes in a 'url' string, a 'llm' object of type 'BaseLLM', and a 'prompt' object of type 'PromptTemplate'. It makes a GET request to the provided 'url', runs the response text through an 'LLMChain' with the given 'llm' and 'prompt', and returns a 'Document' object with the resulting page content.
This commit is contained in:
parent
d7a13755b3
commit
0fa15d2d91
1 changed files with 21 additions and 0 deletions
21
src/backend/langflow/components/custom_components/custom.py
Normal file
21
src/backend/langflow/components/custom_components/custom.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from langflow import CustomComponent
|
||||
|
||||
from langchain.llms.base import BaseLLM
|
||||
from langchain.chains import LLMChain
|
||||
from langchain import PromptTemplate
|
||||
from langchain.schema import Document
|
||||
|
||||
import requests
|
||||
|
||||
class YourComponent(CustomComponent):
|
||||
display_name: str = "Custom Component"
|
||||
description: str = "My description"
|
||||
|
||||
def build_config(self):
|
||||
return { "url": { "multiline": True, "required": True } }
|
||||
|
||||
def build(self, url: str, llm: BaseLLM, prompt: PromptTemplate) -> Document:
|
||||
response = requests.get(url)
|
||||
chain = LLMChain(llm=llm, prompt=prompt)
|
||||
result = chain.run(response.text[:300])
|
||||
return Document(page_content=str(result))
|
||||
Loading…
Add table
Add a link
Reference in a new issue