Refactor code, improve type validation, and update build function name

This commit is contained in:
gustavoschaedler 2023-07-05 02:03:22 +01:00
commit ac569f3405
3 changed files with 5 additions and 9 deletions

View file

@ -9,11 +9,6 @@ from langflow.utils.logger import logger
from fastapi import APIRouter, Depends, HTTPException, UploadFile
# from langflow.api.extract_info_from_class import (
# ClassCodeExtractor,
# is_valid_class_template
# )
from langflow.interface.tools.custom import CustomComponent
from langflow.api.v1.schemas import (

View file

@ -66,6 +66,7 @@ def add_new_custom_field(template, field_name: str, field_type: str):
name=field_name,
field_type=field_type,
show=True,
required=True,
advanced=False
)
template.get('template')[field_name] = new_field.to_dict()
@ -109,7 +110,7 @@ def build_langchain_template_custom_component(extractor: CustomComponent):
def_type = extra_field[1]
if def_field != 'self':
# TODO: Validate type - if possible to render into frontend
# TODO: Validate type - if is possible to render into frontend
if not def_type:
def_type = 'str'

View file

@ -211,7 +211,7 @@ def create_class(code, class_name):
exec_globals[class_name] = locals()[class_name]
# Return a function that imports necessary modules and creates an instance of the target class
def build(*args, **kwargs):
def build_my_class(*args, **kwargs):
for module_name, module in exec_globals.items():
if isinstance(module, type(importlib)):
globals()[module_name] = module
@ -219,9 +219,9 @@ def create_class(code, class_name):
instance = exec_globals[class_name](*args, **kwargs)
return instance
build.__globals__.update(exec_globals)
build_my_class.__globals__.update(exec_globals)
return build
return build_my_class
def extract_function_name(code):