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__(
356356 else :
357357 self ._error = None
358358
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+
359371 @property
360372 def candidates (self ):
361373 """The list of candidate responses.
@@ -428,7 +440,7 @@ def __str__(self) -> str:
428440 else :
429441 _iterator = f"<{ self ._iterator .__class__ .__name__ } >"
430442
431- as_dict = type ( self ._result ). to_dict (self . _result )
443+ as_dict = self .to_dict ()
432444 json_str = json .dumps (as_dict , indent = 2 )
433445
434446 _result = f"glm.GenerateContentResponse({ json_str } )"
You can’t perform that action at this time.
0 commit comments