Define parameters used for required components

To integrate a YouTube document loader from LangChain into GenAI Stack, define a class and inherit the custom component. Each component necessitates a display name, description, and documentation URL that should be appropriately reflected on the user interface (UI).

Inside the class, create a build_config() method to specify the parameters utilized by the component. In the context of integrating the YouTube loader, user input for the URL and the desired transcription language is essential. For these parameters, construct a Python dictionary and assign the display_name, is_list, required, and value as keys that will be updated on the UI. For instance, consider the URL as an example component.

  • display_name (str): The component's name, e.g., Video URL

  • is_list (bool): Indicates whether the required parameter is a list input

  • required (bool): Specifies whether the input is mandatory

  • value (str): The default value, which can be left empty or assigned a default value

These parameters will help define and communicate the necessary information for the YouTube loader within the UI. Once all the essential parameters are defined, utilize the build(**kwargs) method to instantiate the custom component with the specified configurations.

class YoutubeLoaderComponent(CustomComponent):
    display_name: str = "Youtube Loader"
    description: str = "Downloads the YouTube transcripts and video information."
    documentation: str = (
        "https://python.langchain.com/docs/integrations/providers/youtube"
    )
    beta = False

    def build_config(self):
        return {
            "youtube_url": {
                "display_name": "Video URL",
                "is_list": False,
                "required": True,
                "value": "",
            },
            "language": {
                "display_name": "Language",
                "is_list": False,
                "required": True,
                "value": "en",
                "info": "language code to extract transcript. please check subtitles/cc to know available transcripts.",
            },
     }

    def build(self, youtube_url: str, language: str) -> List[Document]:
        loader_instance = YoutubeLoader.from_youtube_url(
            youtube_url=youtube_url, add_video_info=False, language=language
        )
        return loader_instance.load()

Last updated