formatting
This commit is contained in:
parent
b8f8ec9c90
commit
b9b8937eda
5 changed files with 33 additions and 15 deletions
|
|
@ -68,7 +68,6 @@ def update_frontend_node_with_template_values(frontend_node, raw_template_data):
|
||||||
if key == "code" or not isinstance(value_dict, dict) or not frontend_field:
|
if key == "code" or not isinstance(value_dict, dict) or not frontend_field:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
value = value_dict.get("value")
|
value = value_dict.get("value")
|
||||||
template_field_type = value_dict.get("type")
|
template_field_type = value_dict.get("type")
|
||||||
frontend_node_field_type = frontend_field.get("type")
|
frontend_node_field_type = frontend_field.get("type")
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
from fastapi import APIRouter, HTTPException
|
from fastapi import APIRouter, HTTPException
|
||||||
from langflow.api.v1.base import (Code, CodeValidationResponse,
|
from langflow.api.v1.base import (
|
||||||
|
Code,
|
||||||
|
CodeValidationResponse,
|
||||||
PromptValidationResponse,
|
PromptValidationResponse,
|
||||||
ValidatePromptRequest, validate_prompt)
|
ValidatePromptRequest,
|
||||||
|
validate_prompt,
|
||||||
|
)
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
from langflow.utils.validate import validate_code
|
from langflow.utils.validate import validate_code
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ from typing import Any, Dict, List, Type, Union
|
||||||
|
|
||||||
from cachetools import TTLCache, cachedmethod, keys
|
from cachetools import TTLCache, cachedmethod, keys
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from langflow.interface.custom.schema import (CallableCodeDetails,
|
from langflow.interface.custom.schema import CallableCodeDetails, ClassCodeDetails
|
||||||
ClassCodeDetails)
|
|
||||||
|
|
||||||
|
|
||||||
class CodeSyntaxError(HTTPException):
|
class CodeSyntaxError(HTTPException):
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,7 @@ from collections import defaultdict
|
||||||
from typing import ClassVar, Dict, List, Optional
|
from typing import ClassVar, Dict, List, Optional
|
||||||
|
|
||||||
from langflow.template.field.base import TemplateField
|
from langflow.template.field.base import TemplateField
|
||||||
from langflow.template.frontend_node.constants import (CLASSES_TO_REMOVE,
|
from langflow.template.frontend_node.constants import CLASSES_TO_REMOVE, FORCE_SHOW_FIELDS
|
||||||
FORCE_SHOW_FIELDS)
|
|
||||||
from langflow.template.frontend_node.formatter import field_formatters
|
from langflow.template.frontend_node.formatter import field_formatters
|
||||||
from langflow.template.template.base import Template
|
from langflow.template.template.base import Template
|
||||||
from langflow.utils import constants
|
from langflow.utils import constants
|
||||||
|
|
|
||||||
|
|
@ -267,11 +267,27 @@ def get_default_imports(code_string):
|
||||||
}
|
}
|
||||||
|
|
||||||
langflow_imports = [
|
langflow_imports = [
|
||||||
"AgentExecutor", "BaseChatMemory", "BaseLanguageModel", "BaseLLM",
|
"AgentExecutor",
|
||||||
"BaseLoader", "BaseMemory", "BaseOutputParser", "BasePromptTemplate",
|
"BaseChatMemory",
|
||||||
"BaseRetriever", "Callable", "Chain", "ChatPromptTemplate", "Data",
|
"BaseLanguageModel",
|
||||||
"Document", "Embeddings", "NestedDict", "Object", "PromptTemplate",
|
"BaseLLM",
|
||||||
"TextSplitter", "Tool", "VectorStore"
|
"BaseLoader",
|
||||||
|
"BaseMemory",
|
||||||
|
"BaseOutputParser",
|
||||||
|
"BasePromptTemplate",
|
||||||
|
"BaseRetriever",
|
||||||
|
"Callable",
|
||||||
|
"Chain",
|
||||||
|
"ChatPromptTemplate",
|
||||||
|
"Data",
|
||||||
|
"Document",
|
||||||
|
"Embeddings",
|
||||||
|
"NestedDict",
|
||||||
|
"Object",
|
||||||
|
"PromptTemplate",
|
||||||
|
"TextSplitter",
|
||||||
|
"Tool",
|
||||||
|
"VectorStore",
|
||||||
]
|
]
|
||||||
necessary_imports = find_names_in_code(code_string, langflow_imports + ["Optional", "List", "Dict", "Union"])
|
necessary_imports = find_names_in_code(code_string, langflow_imports + ["Optional", "List", "Dict", "Union"])
|
||||||
langflow_module = importlib.import_module("langflow.field_typing")
|
langflow_module = importlib.import_module("langflow.field_typing")
|
||||||
|
|
@ -279,6 +295,7 @@ def get_default_imports(code_string):
|
||||||
|
|
||||||
return default_imports
|
return default_imports
|
||||||
|
|
||||||
|
|
||||||
def find_names_in_code(code, names):
|
def find_names_in_code(code, names):
|
||||||
"""
|
"""
|
||||||
Finds if any of the specified names are present in the given code string.
|
Finds if any of the specified names are present in the given code string.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue