freeplay 0.5.0a2__py3-none-any.whl → 0.5.0a3__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.
- freeplay/utils.py +39 -1
- {freeplay-0.5.0a2.dist-info → freeplay-0.5.0a3.dist-info}/METADATA +1 -1
- {freeplay-0.5.0a2.dist-info → freeplay-0.5.0a3.dist-info}/RECORD +6 -6
- {freeplay-0.5.0a2.dist-info → freeplay-0.5.0a3.dist-info}/LICENSE +0 -0
- {freeplay-0.5.0a2.dist-info → freeplay-0.5.0a3.dist-info}/WHEEL +0 -0
- {freeplay-0.5.0a2.dist-info → freeplay-0.5.0a3.dist-info}/entry_points.txt +0 -0
freeplay/utils.py
CHANGED
@@ -75,8 +75,42 @@ def get_user_agent() -> str:
|
|
75
75
|
# Recursively convert Pydantic models, lists, and dicts to dict compatible format -- used to allow us to accept
|
76
76
|
# provider message shapes (usually generated types) or the default {'content': ..., 'role': ...} shape.
|
77
77
|
def convert_provider_message_to_dict(obj: Any) -> Any:
|
78
|
+
"""
|
79
|
+
Convert provider message objects to dictionaries.
|
80
|
+
For Vertex AI objects, automatically converts to camelCase.
|
81
|
+
"""
|
82
|
+
# List of possible raw attribute names in Vertex AI objects
|
83
|
+
vertex_raw_attrs = [
|
84
|
+
'_raw_content', # For Content objects
|
85
|
+
'_raw_tool', # For Tool objects
|
86
|
+
'_raw_message', # For message objects
|
87
|
+
'_raw_candidate', # For Candidate objects
|
88
|
+
'_raw_response', # For response objects
|
89
|
+
'_raw_function_declaration', # For FunctionDeclaration
|
90
|
+
'_raw_generation_config', # For GenerationConfig
|
91
|
+
'_pb', # Generic protobuf attribute
|
92
|
+
]
|
93
|
+
|
94
|
+
# Check for Vertex AI objects with raw protobuf attributes
|
95
|
+
for attr_name in vertex_raw_attrs:
|
96
|
+
if hasattr(obj, attr_name):
|
97
|
+
raw_obj = getattr(obj, attr_name)
|
98
|
+
if raw_obj is not None:
|
99
|
+
try:
|
100
|
+
# Use the metaclass to_dict with camelCase conversion
|
101
|
+
return type(raw_obj).to_dict(
|
102
|
+
raw_obj,
|
103
|
+
preserving_proto_field_name=False, # camelCase
|
104
|
+
use_integers_for_enums=False, # Keep as strings (we'll lowercase them)
|
105
|
+
including_default_value_fields=False # Exclude defaults
|
106
|
+
)
|
107
|
+
except: # noqa: E722
|
108
|
+
# If we can't convert, continue to the next attribute
|
109
|
+
pass
|
110
|
+
|
111
|
+
# For non-Vertex AI objects, use their standard to_dict methods
|
78
112
|
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
|
79
|
-
# Vertex AI
|
113
|
+
# Regular to_dict (for Vertex AI wrappers without _raw_* attributes)
|
80
114
|
return obj.to_dict()
|
81
115
|
elif hasattr(obj, 'model_dump'):
|
82
116
|
# Pydantic v2
|
@@ -85,7 +119,11 @@ def convert_provider_message_to_dict(obj: Any) -> Any:
|
|
85
119
|
# Pydantic v1
|
86
120
|
return obj.dict(encode_json=True)
|
87
121
|
elif isinstance(obj, dict):
|
122
|
+
# Handle dictionaries recursively
|
88
123
|
return {k: convert_provider_message_to_dict(v) for k, v in obj.items()}
|
89
124
|
elif isinstance(obj, list):
|
125
|
+
# Handle lists recursively
|
90
126
|
return [convert_provider_message_to_dict(item) for item in obj]
|
127
|
+
|
128
|
+
# Return as-is for primitive types
|
91
129
|
return obj
|
@@ -15,9 +15,9 @@ freeplay/resources/sessions.py,sha256=dZtd9nq2nH8pmXxQOJitBnN5Jl3kjggDItDcjC69TY
|
|
15
15
|
freeplay/resources/test_cases.py,sha256=nXL_976RwSJDT6OWDM4GEzbcOzcGkJ9ulvb0XOzCRDM,2240
|
16
16
|
freeplay/resources/test_runs.py,sha256=IkqW2LrVrLzFcGtalwP4FV-DeQKKb6Nekvy02FfoH8k,5007
|
17
17
|
freeplay/support.py,sha256=9X-utKyM9BkhCLJbPT184ud26Dc69f3DiHjyN8qq0vQ,15266
|
18
|
-
freeplay/utils.py,sha256=
|
19
|
-
freeplay-0.5.
|
20
|
-
freeplay-0.5.
|
21
|
-
freeplay-0.5.
|
22
|
-
freeplay-0.5.
|
23
|
-
freeplay-0.5.
|
18
|
+
freeplay/utils.py,sha256=OtoSnlDrLEk3MWiXmKFJ4Sw42-1kQ94-d_2ekHT6eUo,5038
|
19
|
+
freeplay-0.5.0a3.dist-info/LICENSE,sha256=_jzIw45hB1XHGxiQ8leZ0GH_X7bR_a8qgxaqnHbCUOo,1064
|
20
|
+
freeplay-0.5.0a3.dist-info/METADATA,sha256=wJZwNOsRV5Oq1xPG8Wbx1H4UpbC4oH6RbuVP_erRPqM,1662
|
21
|
+
freeplay-0.5.0a3.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
22
|
+
freeplay-0.5.0a3.dist-info/entry_points.txt,sha256=32s3rf2UUCqiJT4jnClEXZhdXlvl30uwpcxz-Gsy4UU,54
|
23
|
+
freeplay-0.5.0a3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|