@@ -18,12 +18,7 @@ def default(self, obj): # type: ignore[override]
1818
1919
2020def enable_notgiven_serialization () -> None :
21- """Enable global JSON support for OpenAI/Portkey "not provided" markers.
22-
23- After this is called (done automatically in portkey_ai.__init__), any
24- json.dumps(...) that encounters these markers will encode them as null
25- instead of raising a TypeError.
26- """
21+ """Globally encode NotGiven / Omit markers as null in json.dumps."""
2722 global _patched_notgiven_serialization
2823 if _patched_notgiven_serialization :
2924 return
@@ -38,10 +33,7 @@ def patched_default(self, obj): # type: ignore[override]
3833
3934
4035def disable_notgiven_serialization () -> None :
41- """Disable global JSON support for OpenAI/Portkey "not provided" markers.
42-
43- Restores the original JSONEncoder.default implementation.
44- """
36+ """Restore the original json.JSONEncoder.default implementation."""
4537 global _patched_notgiven_serialization
4638 if not _patched_notgiven_serialization :
4739 return
@@ -51,25 +43,22 @@ def disable_notgiven_serialization() -> None:
5143
5244
5345def _is_serializable (value ) -> bool :
54- """Return True if value can be serialized with PortkeyJSONEncoder."""
5546 try :
5647 json .dumps (value , cls = PortkeyJSONEncoder )
57- return True
5848 except (TypeError , ValueError ):
5949 return False
50+ return True
6051
6152
6253def serialize_kwargs (** kwargs ):
63- # Filter out non-serializable items
64- serializable_kwargs = {k : v for k , v in kwargs .items () if _is_serializable (v )}
65-
66- # Convert to string representation
67- return json .dumps (serializable_kwargs , cls = PortkeyJSONEncoder )
54+ return json .dumps (
55+ {k : v for k , v in kwargs .items () if _is_serializable (v )},
56+ cls = PortkeyJSONEncoder ,
57+ )
6858
6959
7060def serialize_args (* args ):
71- # Filter out non-serializable items
72- serializable_args = [arg for arg in args if _is_serializable (arg )]
73-
74- # Convert to string representation
75- return json .dumps (serializable_args , cls = PortkeyJSONEncoder )
61+ return json .dumps (
62+ [arg for arg in args if _is_serializable (arg )],
63+ cls = PortkeyJSONEncoder ,
64+ )
0 commit comments