31
31
32
32
import importlib
33
33
import logging
34
- from typing import (
35
- Any ,
36
- ClassVar ,
37
- Generic ,
38
- Optional ,
39
- TypeVar ,
40
- Union ,
41
- cast ,
42
- )
34
+ from typing import Any , ClassVar , Generic , Optional , TypeVar , Union , cast
43
35
44
36
import neo4j
45
37
from pydantic import (
58
50
from neo4j_graphrag .llm import LLMInterface
59
51
from neo4j_graphrag .utils .validation import issubclass_safe
60
52
61
-
62
53
logger = logging .getLogger (__name__ )
63
54
64
55
@@ -73,7 +64,7 @@ class ObjectConfig(AbstractConfig, Generic[T]):
73
64
and its constructor parameters.
74
65
"""
75
66
76
- class_ : str | None = Field (default = None , validate_default = True )
67
+ class_ : Optional [ str ] = Field (default = None , validate_default = True )
77
68
"""Path to class to be instantiated."""
78
69
params_ : dict [str , ParamConfig ] = {}
79
70
"""Initialization parameters."""
@@ -128,7 +119,7 @@ def _get_class(cls, class_path: str, optional_module: Optional[str] = None) -> t
128
119
raise ValueError (f"Could not find { class_name } in { module_name } " )
129
120
return cast (type , klass )
130
121
131
- def parse (self , resolved_data : dict [str , Any ] | None = None ) -> T :
122
+ def parse (self , resolved_data : Optional [ dict [str , Any ]] = None ) -> T :
132
123
"""Import `class_`, resolve `params_` and instantiate object."""
133
124
self ._global_data = resolved_data or {}
134
125
logger .debug (f"OBJECT_CONFIG: parsing { self } using { resolved_data } " )
@@ -162,7 +153,7 @@ def validate_class(cls, class_: Any) -> str:
162
153
# not used
163
154
return "not used"
164
155
165
- def parse (self , resolved_data : dict [str , Any ] | None = None ) -> neo4j .Driver :
156
+ def parse (self , resolved_data : Optional [ dict [str , Any ]] = None ) -> neo4j .Driver :
166
157
params = self .resolve_params (self .params_ )
167
158
# we know these params are there because of the required params validator
168
159
uri = params .pop ("uri" )
@@ -185,7 +176,7 @@ class Neo4jDriverType(RootModel): # type: ignore[type-arg]
185
176
186
177
model_config = ConfigDict (arbitrary_types_allowed = True )
187
178
188
- def parse (self , resolved_data : dict [str , Any ] | None = None ) -> neo4j .Driver :
179
+ def parse (self , resolved_data : Optional [ dict [str , Any ]] = None ) -> neo4j .Driver :
189
180
if isinstance (self .root , neo4j .Driver ):
190
181
return self .root
191
182
# self.root is a Neo4jDriverConfig object
@@ -212,7 +203,7 @@ class LLMType(RootModel): # type: ignore[type-arg]
212
203
213
204
model_config = ConfigDict (arbitrary_types_allowed = True )
214
205
215
- def parse (self , resolved_data : dict [str , Any ] | None = None ) -> LLMInterface :
206
+ def parse (self , resolved_data : Optional [ dict [str , Any ]] = None ) -> LLMInterface :
216
207
if isinstance (self .root , LLMInterface ):
217
208
return self .root
218
209
return self .root .parse (resolved_data )
@@ -238,7 +229,7 @@ class EmbedderType(RootModel): # type: ignore[type-arg]
238
229
239
230
model_config = ConfigDict (arbitrary_types_allowed = True )
240
231
241
- def parse (self , resolved_data : dict [str , Any ] | None = None ) -> Embedder :
232
+ def parse (self , resolved_data : Optional [ dict [str , Any ]] = None ) -> Embedder :
242
233
if isinstance (self .root , Embedder ):
243
234
return self .root
244
235
return self .root .parse (resolved_data )
@@ -266,7 +257,7 @@ class ComponentType(RootModel): # type: ignore[type-arg]
266
257
267
258
model_config = ConfigDict (arbitrary_types_allowed = True )
268
259
269
- def parse (self , resolved_data : dict [str , Any ] | None = None ) -> Component :
260
+ def parse (self , resolved_data : Optional [ dict [str , Any ]] = None ) -> Component :
270
261
if isinstance (self .root , Component ):
271
262
return self .root
272
263
return self .root .parse (resolved_data )
0 commit comments