Refactor code, improve type validation, and update build function name
This commit is contained in:
parent
64e5a3a98d
commit
ac569f3405
3 changed files with 5 additions and 9 deletions
|
|
@ -9,11 +9,6 @@ from langflow.utils.logger import logger
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException, UploadFile
|
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.interface.tools.custom import CustomComponent
|
||||||
|
|
||||||
from langflow.api.v1.schemas import (
|
from langflow.api.v1.schemas import (
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ def add_new_custom_field(template, field_name: str, field_type: str):
|
||||||
name=field_name,
|
name=field_name,
|
||||||
field_type=field_type,
|
field_type=field_type,
|
||||||
show=True,
|
show=True,
|
||||||
|
required=True,
|
||||||
advanced=False
|
advanced=False
|
||||||
)
|
)
|
||||||
template.get('template')[field_name] = new_field.to_dict()
|
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]
|
def_type = extra_field[1]
|
||||||
|
|
||||||
if def_field != 'self':
|
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:
|
if not def_type:
|
||||||
def_type = 'str'
|
def_type = 'str'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -211,7 +211,7 @@ def create_class(code, class_name):
|
||||||
exec_globals[class_name] = locals()[class_name]
|
exec_globals[class_name] = locals()[class_name]
|
||||||
|
|
||||||
# Return a function that imports necessary modules and creates an instance of the target class
|
# 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():
|
for module_name, module in exec_globals.items():
|
||||||
if isinstance(module, type(importlib)):
|
if isinstance(module, type(importlib)):
|
||||||
globals()[module_name] = module
|
globals()[module_name] = module
|
||||||
|
|
@ -219,9 +219,9 @@ def create_class(code, class_name):
|
||||||
instance = exec_globals[class_name](*args, **kwargs)
|
instance = exec_globals[class_name](*args, **kwargs)
|
||||||
return instance
|
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):
|
def extract_function_name(code):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue