11from pathlib import Path
22from typing import List , Union , Optional , Literal , Any , Annotated , Type , TypeVar
3- from pydantic import BaseModel , Field , field_validator , computed_field , field_serializer
3+ from pydantic import BaseModel , Field , field_validator , field_serializer
4+ from pydantic import ValidationError
45import json
56import logging
67
@@ -57,21 +58,6 @@ def check_value_format(cls, v: str):
5758 raise ValueError (msg )
5859 return v
5960
60- @computed_field
61- def name (self ) -> str :
62- """Dynamically computes the function name from the 'value' field."""
63- try :
64- return self .value .rsplit ("." , 1 )[- 1 ]
65- except IndexError :
66- msg = f"Could not extract function name from invalid FunctionNode value: '{ self .value } ' (ID: { self .id } ). Check validation."
67- raise ValueError (msg )
68- except Exception as e :
69- logger .error (
70- f"Unexpected error computing name for FunctionNode value: '{ self .value } ' (ID: { self .id } ): { e } " ,
71- exc_info = True ,
72- )
73- raise
74-
7561
7662# Discriminated Union for Nodes
7763PwdNode = Annotated [
@@ -127,7 +113,6 @@ def dump_json(
127113 self ,
128114 * ,
129115 indent : Optional [int ] = 2 ,
130- exclude_computed_function_names : bool = True ,
131116 ** kwargs ,
132117 ) -> str :
133118 """
@@ -143,29 +128,12 @@ def dump_json(
143128 Returns:
144129 JSON string representation of the workflow.
145130 """
146- logger .info (
147- f"Dumping workflow model to JSON string (indent={ indent } , exclude_func_names={ exclude_computed_function_names } )..."
148- )
149131
150132 # Dump the model to a dictionary first, using mode='json' for compatible types
151133 # Pass any extra kwargs (like custom 'exclude' rules for other fields)
152134 workflow_dict = self .model_dump (mode = "json" , ** kwargs )
153135
154- # --- Post-process the dictionary to exclude function names if requested ---
155- if exclude_computed_function_names and "nodes" in workflow_dict :
156- nodes_list = workflow_dict .get ("nodes" , [])
157- for i , node_dict in enumerate (nodes_list ):
158- # Check type and presence of name before deleting
159- if (
160- isinstance (node_dict , dict )
161- and node_dict .get ("type" ) == "function"
162- and "name" in node_dict
163- ):
164- # Create a new dict without the 'name' key for immutability or modify in place
165- # Modifying in place is usually fine here
166- del nodes_list [i ]["name" ]
167-
168- # Dump the potentially modified dictionary to a JSON string
136+ # Dump the dictionary to a JSON string
169137 try :
170138 json_string = json .dumps (workflow_dict , indent = indent )
171139 logger .info ("Successfully dumped workflow model to JSON string." )
@@ -181,7 +149,6 @@ def dump_json_file(
181149 file_name : Union [str , Path ],
182150 * ,
183151 indent : Optional [int ] = 2 ,
184- exclude_computed_function_names : bool = True ,
185152 ** kwargs ,
186153 ) -> None :
187154 """
@@ -198,7 +165,6 @@ def dump_json_file(
198165 # Pass kwargs to dump_json, which passes them to model_dump
199166 json_string = self .dump_json (
200167 indent = indent ,
201- exclude_computed_function_names = exclude_computed_function_names ,
202168 ** kwargs ,
203169 )
204170 try :
0 commit comments