Writing Custom Components in GenAI Stack
Introduction
Writing a Custom Component
Structure of a Custom Component
from genflow.interface.custom.custom_component import CustomComponent
from langchain.schema import Document
from typing import List
class ExampleComponent(CustomComponent):
display_name: str = "ExampleComponent"
description: str = "This is an example custom component."
version: str = "1.0"
def build_config(self):
return {
"param1": {
"display_name": "Parameter 1",
"required": True,
"input_types": ["Input"],
},
"param2": {
"display_name": "Parameter 2",
"required": False,
"input_types": ["Input"],
},
"code": {"show": False},
}
def build(self, param1: str, param2: str) -> List[Document]:
# Custom logic to build and return documents
documents = [Document(page_content=f"Param1: {param1}, Param2: {param2}")]
return documentsExplanation
Understanding the Typing System
Maintaining Type Consistency
Example: GitHub File Loader Component
Explanation
Last updated
Was this helpful?