add vectara icon (#1389)
* adding vectara icon * Add field_typing imports and source parameter to VectaraComponent * Refactor Vectara imports and update dependencies * Refactor VectaraSelfQueryRetriverComponent class and update field_config * Remove None values and update template strings * Add get_output_types_from_code method to DirectoryReader * Refactor directory_reader.py and handle exception when getting output types from code --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@logspace.ai> Co-authored-by: cristhianzl <cristhian.lousa@gmail.com>
This commit is contained in:
parent
c0c64c99c9
commit
8023332260
7 changed files with 1370 additions and 13 deletions
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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__")]
|
||||
|
|
|
|||
|
|
@ -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]):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue