diff --git a/src/backend/langflow/components/vectorstores/Vectara.py b/src/backend/langflow/components/vectorstores/Vectara.py index af828c49e..722137354 100644 --- a/src/backend/langflow/components/vectorstores/Vectara.py +++ b/src/backend/langflow/components/vectorstores/Vectara.py @@ -3,11 +3,11 @@ import urllib import urllib.request from typing import List, Optional, Union -from langchain.embeddings import FakeEmbeddings -from langchain.schema import BaseRetriever, Document -from langchain_community.vectorstores import Vectara, VectorStore - +from langchain_community.embeddings import FakeEmbeddings +from langchain_community.vectorstores.vectara import Vectara +from langchain_core.vectorstores import VectorStore from langflow import CustomComponent +from langflow.field_typing import BaseRetriever, Document class VectaraComponent(CustomComponent): @@ -29,14 +29,10 @@ class VectaraComponent(CustomComponent): "password": True, "required": True, }, - "code": {"show": False}, - "documents": { - "display_name": "Documents", - "info": "Pass in either for Self Query Retriever or for making a Vectara Object", - }, + "documents": {"display_name": "Documents", "info": "If provided, will be upserted to corpus (optional)"}, "files_url": { "display_name": "Files Url", - "info": "Make vectara object using url of files(documents not needed)", + "info": "Make vectara object using url of files (optional)", }, } @@ -48,6 +44,8 @@ class VectaraComponent(CustomComponent): files_url: Optional[List[str]] = None, documents: Optional[Document] = None, ) -> Union[VectorStore, BaseRetriever]: + source = "Langflow" + if documents is not None: return Vectara.from_documents( documents=documents, @@ -55,6 +53,7 @@ class VectaraComponent(CustomComponent): vectara_customer_id=vectara_customer_id, vectara_corpus_id=vectara_corpus_id, vectara_api_key=vectara_api_key, + source=source, ) if files_url is not None: @@ -70,10 +69,12 @@ class VectaraComponent(CustomComponent): vectara_customer_id=vectara_customer_id, vectara_corpus_id=vectara_corpus_id, vectara_api_key=vectara_api_key, + source=source, ) return Vectara( vectara_customer_id=vectara_customer_id, vectara_corpus_id=vectara_corpus_id, vectara_api_key=vectara_api_key, + source=source, ) diff --git a/src/backend/langflow/interface/custom/directory_reader/directory_reader.py b/src/backend/langflow/interface/custom/directory_reader/directory_reader.py index d6cca5c83..7bf55bec8 100644 --- a/src/backend/langflow/interface/custom/directory_reader/directory_reader.py +++ b/src/backend/langflow/interface/custom/directory_reader/directory_reader.py @@ -2,6 +2,7 @@ import ast import os import zlib +from langflow.interface.custom.custom_component import CustomComponent from loguru import logger @@ -245,9 +246,18 @@ class DirectoryReader: else: component_name_camelcase = component_name + if validation_result: + try: + output_types = self.get_output_types_from_code(result_content) + except Exception as exc: + logger.exception(f"Error while getting output types from code: {str(exc)}") + output_types = [component_name_camelcase] + else: + output_types = [component_name_camelcase] + component_info = { "name": "CustomComponent", - "output_types": [component_name_camelcase], + "output_types": output_types, "file": filename, "code": result_content if validation_result else "", "error": "" if validation_result else result_content, @@ -259,3 +269,13 @@ class DirectoryReader: response["menu"].append(menu_result) logger.debug("-------------------- Component menu list built --------------------") return response + + @staticmethod + def get_output_types_from_code(code: str) -> list: + """ + Get the output types from the code. + """ + custom_component = CustomComponent(code=code) + types_list = custom_component.get_function_entrypoint_return_type + # Get the name of types classes + return [type_.__name__ for type_ in types_list if hasattr(type_, "__name__")] diff --git a/src/backend/langflow/interface/custom/utils.py b/src/backend/langflow/interface/custom/utils.py index 7e54bd547..e6125b515 100644 --- a/src/backend/langflow/interface/custom/utils.py +++ b/src/backend/langflow/interface/custom/utils.py @@ -7,8 +7,6 @@ from typing import Any, Dict, List, Optional, Union from uuid import UUID from fastapi import HTTPException -from loguru import logger - from langflow.field_typing.range_spec import RangeSpec from langflow.interface.custom.code_parser.utils import extract_inner_type from langflow.interface.custom.custom_component import CustomComponent @@ -21,6 +19,7 @@ from langflow.interface.importing.utils import eval_custom_component_code from langflow.template.field.base import TemplateField from langflow.template.frontend_node.custom_components import CustomComponentFrontendNode from langflow.utils.util import get_base_classes +from loguru import logger def add_output_types(frontend_node: CustomComponentFrontendNode, return_types: List[str]): diff --git a/src/frontend/src/icons/VectaraIcon/Vectara.jsx b/src/frontend/src/icons/VectaraIcon/Vectara.jsx new file mode 100644 index 000000000..0566f82eb --- /dev/null +++ b/src/frontend/src/icons/VectaraIcon/Vectara.jsx @@ -0,0 +1,1074 @@ +const SvgVectara = (props) => ( + <> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +); +export default SvgVectara; diff --git a/src/frontend/src/icons/VectaraIcon/index.tsx b/src/frontend/src/icons/VectaraIcon/index.tsx new file mode 100644 index 000000000..5adc2d7e7 --- /dev/null +++ b/src/frontend/src/icons/VectaraIcon/index.tsx @@ -0,0 +1,9 @@ +import React, { forwardRef } from "react"; +import SvgVectara from "./Vectara"; + +export const VectaraIcon = forwardRef< + SVGSVGElement, + React.PropsWithChildren<{}> +>((props, ref) => { + return ; +}); diff --git a/src/frontend/src/icons/VectaraIcon/vectara.svg b/src/frontend/src/icons/VectaraIcon/vectara.svg new file mode 100644 index 000000000..1faafd320 --- /dev/null +++ b/src/frontend/src/icons/VectaraIcon/vectara.svg @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/frontend/src/utils/styleUtils.ts b/src/frontend/src/utils/styleUtils.ts index 82ff5fbf3..b0432fe7e 100644 --- a/src/frontend/src/utils/styleUtils.ts +++ b/src/frontend/src/utils/styleUtils.ts @@ -134,6 +134,7 @@ import { SearxIcon } from "../icons/Searx"; import { ShareIcon } from "../icons/Share"; import { Share2Icon } from "../icons/Share2"; import SvgSlackIcon from "../icons/Slack/SlackIcon"; +import { VectaraIcon } from "../icons/VectaraIcon"; import { VertexAIIcon } from "../icons/VertexAI"; import { WeaviateIcon } from "../icons/Weaviate"; import SvgWikipedia from "../icons/Wikipedia/Wikipedia"; @@ -227,6 +228,7 @@ export const nodeNames: { [char: string]: string } = { }; export const nodeIconsLucide: iconsType = { + Vectara: VectaraIcon, ArrowUpToLine: ArrowUpToLine, Chroma: ChromaIcon, AirbyteJSONLoader: AirbyteIcon,