lionagi 0.17.8__py3-none-any.whl → 0.17.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lionagi/_types.py CHANGED
@@ -1,3 +1,5 @@
1
+ """lionagi type definitions."""
2
+
1
3
  # Lazy loading for heavy type imports to improve startup performance
2
4
  _lazy_type_imports = {}
3
5
 
lionagi/fields/reason.py CHANGED
@@ -32,6 +32,8 @@ class Reason(HashableModel):
32
32
 
33
33
 
34
34
  def validate_confidence_score(cls, v):
35
+ if v is None:
36
+ return None
35
37
  try:
36
38
  return to_num(
37
39
  v,
lionagi/ln/types.py CHANGED
@@ -24,6 +24,7 @@ __all__ = (
24
24
  "Params",
25
25
  "DataClass",
26
26
  "KeysLike",
27
+ "Meta",
27
28
  )
28
29
 
29
30
  T = TypeVar("T")
@@ -312,3 +313,47 @@ class DataClass:
312
313
 
313
314
 
314
315
  KeysLike = Sequence[str] | KeysDict
316
+
317
+
318
+ @dataclass(slots=True, frozen=True)
319
+ class Meta:
320
+ """Immutable metadata container for field templates and other configurations."""
321
+
322
+ key: str
323
+ value: Any
324
+
325
+ @override
326
+ def __hash__(self) -> int:
327
+ """Make metadata hashable for caching.
328
+
329
+ Note: For callables, we hash by id to maintain identity semantics.
330
+ """
331
+ # For callables, use their id
332
+ if callable(self.value):
333
+ return hash((self.key, id(self.value)))
334
+ # For other values, try to hash directly
335
+ try:
336
+ return hash((self.key, self.value))
337
+ except TypeError:
338
+ # Fallback for unhashable types
339
+ return hash((self.key, str(self.value)))
340
+
341
+ @override
342
+ def __eq__(self, other: object) -> bool:
343
+ """Compare metadata for equality.
344
+
345
+ For callables, compare by id to increase cache hits when the same
346
+ validator instance is reused. For other values, use standard equality.
347
+ """
348
+ if not isinstance(other, Meta):
349
+ return NotImplemented
350
+
351
+ if self.key != other.key:
352
+ return False
353
+
354
+ # For callables, compare by identity
355
+ if callable(self.value) and callable(other.value):
356
+ return id(self.value) == id(other.value)
357
+
358
+ # For other values, use standard equality
359
+ return bool(self.value == other.value)