File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
google/generativeai/types Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -356,6 +356,18 @@ def __init__(
356
356
else :
357
357
self ._error = None
358
358
359
+ def to_dict (self ):
360
+ """Returns the result as a JSON-compatible dict.
361
+
362
+ Note: This doesn't capture the iterator state when streaming, it only captures the accumulated
363
+ `GenerateContentResponse` fields.
364
+
365
+ >>> import json
366
+ >>> response = model.generate_content('Hello?')
367
+ >>> json.dumps(response.to_dict())
368
+ """
369
+ return type (self ._result ).to_dict (self ._result )
370
+
359
371
@property
360
372
def candidates (self ):
361
373
"""The list of candidate responses.
@@ -428,7 +440,7 @@ def __str__(self) -> str:
428
440
else :
429
441
_iterator = f"<{ self ._iterator .__class__ .__name__ } >"
430
442
431
- as_dict = type ( self ._result ). to_dict (self . _result )
443
+ as_dict = self .to_dict ()
432
444
json_str = json .dumps (as_dict , indent = 2 )
433
445
434
446
_result = f"glm.GenerateContentResponse({ json_str } )"
You can’t perform that action at this time.
0 commit comments