From 096f3ae1fc23b6e3477487c992017b4759ace0c9 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 23 Nov 2023 08:39:51 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20refactor(utils.py):=20rename=20g?= =?UTF-8?q?et=5Ffunction=5Fcustom=20to=20eval=5Fcustom=5Fcomponent=5Fcode?= =?UTF-8?q?=20for=20better=20clarity=20and=20consistency=20=E2=9C=A8=20fea?= =?UTF-8?q?t(utils.py):=20add=20type=20hinting=20to=20eval=5Fcustom=5Fcomp?= =?UTF-8?q?onent=5Fcode=20function=20for=20better=20code=20readability=20a?= =?UTF-8?q?nd=20maintainability=20=F0=9F=94=A8=20refactor(utils.py):=20mov?= =?UTF-8?q?e=20import=20statement=20for=20PromptTemplate=20to=20the=20corr?= =?UTF-8?q?ect=20location=20for=20better=20organization=20=F0=9F=94=A8=20r?= =?UTF-8?q?efactor(utils.py):=20move=20import=20statement=20for=20validate?= =?UTF-8?q?=20to=20the=20correct=20location=20for=20better=20organization?= =?UTF-8?q?=20=F0=9F=94=A8=20refactor(utils.py):=20remove=20unused=20impor?= =?UTF-8?q?ts=20and=20reorganize=20import=20statements=20for=20better=20or?= =?UTF-8?q?ganization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/interface/importing/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/interface/importing/utils.py b/src/backend/langflow/interface/importing/utils.py index 6b28d792e..fb28bbdc8 100644 --- a/src/backend/langflow/interface/importing/utils.py +++ b/src/backend/langflow/interface/importing/utils.py @@ -3,15 +3,16 @@ import importlib from typing import Any, Type -from langchain.prompts import PromptTemplate from langchain.agents import Agent from langchain.base_language import BaseLanguageModel from langchain.chains.base import Chain from langchain.chat_models.base import BaseChatModel +from langchain.prompts import PromptTemplate from langchain.tools import BaseTool + from langflow.interface.custom.custom_component import CustomComponent -from langflow.utils import validate from langflow.interface.wrappers.base import wrapper_creator +from langflow.utils import validate def import_module(module_path: str) -> Any: @@ -180,6 +181,7 @@ def get_function(code): return validate.create_function(code, function_name) -def get_function_custom(code): +def eval_custom_component_code(code: str) -> CustomComponent: + """Evaluate custom component code""" class_name = validate.extract_class_name(code) return validate.create_class(code, class_name)