langflow/src/backend/langflow/template/frontend_node/utilities.py
Gabriel Luiz Freitas Almeida d0aa3261f1 🐛 fix(flows.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(schemas.py): change json.dumps to orjson_dumps for improved performance and compatibility with orjson library
🐛 fix(utils.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(loading.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(utils.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(vector_store.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(types.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
🐛 fix(process.py): change json.loads to orjson.loads for improved performance and compatibility with orjson library
 feat(server.ts): change port variable case from lowercase port to uppercase PORT to improve semantics
 feat(server.ts): add support for process.env.PORT environment variable to be able to run app on a configurable port

🔧 fix(base.py): import orjson instead of json to improve performance and compatibility
🔧 fix(frontend_node/llms.py): use orjson_dumps instead of json.dumps to improve performance and compatibility
🔧 fix(frontend_node/utilities.py): use orjson_dumps instead of json.dumps to improve performance and compatibility
🔧 fix(test_cache.py): import orjson and use orjson_dumps instead of json.dumps to improve performance and compatibility

🔧 fix(test_database.py): import correct json encoder and decoder functions to fix import errors
🔧 fix(test_database.py): replace json.dumps and json.loads with orjson_dumps and orjson.loads for better performance and compatibility
🔧 fix(test_loading.py): remove unused import statement
2023-08-22 11:04:41 -03:00

25 lines
1 KiB
Python

import ast
from typing import Optional
from langflow.database.models.base import orjson_dumps
from langflow.template.field.base import TemplateField
from langflow.template.frontend_node.base import FrontendNode
class UtilitiesFrontendNode(FrontendNode):
@staticmethod
def format_field(field: TemplateField, name: Optional[str] = None) -> None:
FrontendNode.format_field(field, name)
# field.field_type could be "Literal['news', 'search', 'places', 'images']
# we need to convert it to a list
# It seems it could also be like "typing_extensions.['news', 'search', 'places', 'images']"
if "Literal" in field.field_type:
field_type = field.field_type.replace("typing_extensions.", "")
field_type = field_type.replace("Literal", "")
field.options = ast.literal_eval(field_type)
field.is_list = True
field.field_type = "str"
if isinstance(field.value, dict):
field.field_type = "code"
field.value = orjson_dumps(field.value)