22#
33# SPDX-License-Identifier: Apache-2.0
44
5- import warnings
6- from typing import Any , Dict , List , Union
5+ from typing import TYPE_CHECKING , Any , Dict , List , Union
76
87from haystack .core .errors import DeserializationError
98from haystack .core .serialization import import_class_by_name
10- from haystack .tools .tool import Tool
11- from haystack .tools .toolset import Toolset
9+
10+ if TYPE_CHECKING :
11+ from haystack .tools .tool import Tool
12+ from haystack .tools .toolset import Toolset
1213
1314
1415def serialize_tools_or_toolset (
15- tools : Union [Toolset , List [Tool ], None ],
16+ tools : Union [" Toolset" , List [" Tool" ], None ],
1617) -> Union [Dict [str , Any ], List [Dict [str , Any ]], None ]:
1718 """
1819 Serialize a Toolset or a list of Tools to a dictionary or a list of tool dictionaries.
1920
2021 :param tools: A Toolset, a list of Tools, or None
2122 :returns: A dictionary, a list of tool dictionaries, or None if tools is None
2223 """
24+ from haystack .tools .toolset import Toolset
25+
2326 if tools is None :
2427 return None
2528 if isinstance (tools , Toolset ):
@@ -36,6 +39,9 @@ def deserialize_tools_or_toolset_inplace(data: Dict[str, Any], key: str = "tools
3639 :param key:
3740 The key in the dictionary where the list of Tools or Toolset is stored.
3841 """
42+ from haystack .tools .tool import Tool
43+ from haystack .tools .toolset import Toolset
44+
3945 if key in data :
4046 serialized_tools = data [key ]
4147
@@ -72,22 +78,3 @@ def deserialize_tools_or_toolset_inplace(data: Dict[str, Any], key: str = "tools
7278 deserialized_tools .append (tool_class .from_dict (tool ))
7379
7480 data [key ] = deserialized_tools
75-
76-
77- def deserialize_tools_inplace (data : Dict [str , Any ], key : str = "tools" ):
78- """
79- Deserialize a list of Tools or a Toolset in a dictionary inplace.
80-
81- Deprecated in favor of `deserialize_tools_or_toolset_inplace`. It will be removed in Haystack 2.14.0.
82-
83- :param data:
84- The dictionary with the serialized data.
85- :param key:
86- The key in the dictionary where the list of Tools or Toolset is stored.
87- """
88- warnings .warn (
89- "`deserialize_tools_inplace` is deprecated and will be removed in Haystack 2.14.0. "
90- "Use `deserialize_tools_or_toolset_inplace` instead." ,
91- DeprecationWarning ,
92- )
93- deserialize_tools_or_toolset_inplace (data , key )
0 commit comments