86
86
]
87
87
88
88
SafetySettingsType = Union [
89
- List [gapic_content_types . SafetySetting ],
89
+ List [" SafetySetting" ],
90
90
Dict [
91
91
gapic_content_types .HarmCategory ,
92
92
gapic_content_types .SafetySetting .HarmBlockThreshold ,
@@ -258,17 +258,20 @@ def _prepare_request(
258
258
raise TypeError (
259
259
"generation_config must either be a GenerationConfig object or a dictionary representation of it."
260
260
)
261
+
261
262
gapic_safety_settings = None
262
263
if safety_settings :
263
264
if isinstance (safety_settings , Sequence ):
264
- if not all (
265
- isinstance (safety_setting , gapic_content_types .SafetySetting )
266
- for safety_setting in safety_settings
267
- ):
268
- raise TypeError (
269
- "When passing a list with SafetySettings objects, every item in a list must be a SafetySetting object."
270
- )
271
- gapic_safety_settings = safety_settings
265
+ gapic_safety_settings = []
266
+ for safety_setting in safety_settings :
267
+ if isinstance (safety_setting , gapic_content_types .SafetySetting ):
268
+ gapic_safety_settings .append (safety_setting )
269
+ elif isinstance (safety_setting , SafetySetting ):
270
+ gapic_safety_settings .append (safety_setting ._raw_safety_setting )
271
+ else :
272
+ raise TypeError (
273
+ "When passing a list with SafetySettings objects, every item in a list must be a SafetySetting object."
274
+ )
272
275
elif isinstance (safety_settings , dict ):
273
276
gapic_safety_settings = [
274
277
gapic_content_types .SafetySetting (
@@ -283,6 +286,7 @@ def _prepare_request(
283
286
raise TypeError (
284
287
"safety_settings must either be a list of SafetySettings objects or a dictionary mapping from HarmCategory to HarmBlockThreshold."
285
288
)
289
+
286
290
gapic_tools = None
287
291
if tools :
288
292
gapic_tools = []
@@ -1738,6 +1742,61 @@ def _image(self) -> "Image":
1738
1742
return Image .from_bytes (data = self ._raw_part .inline_data .data )
1739
1743
1740
1744
1745
+ class SafetySetting :
1746
+ """Parameters for the generation."""
1747
+
1748
+ HarmCategory = gapic_content_types .HarmCategory
1749
+ HarmBlockMethod = gapic_content_types .SafetySetting .HarmBlockMethod
1750
+ HarmBlockThreshold = gapic_content_types .SafetySetting .HarmBlockThreshold
1751
+
1752
+ def __init__ (
1753
+ self ,
1754
+ * ,
1755
+ category : "SafetySetting.HarmCategory" ,
1756
+ threshold : "SafetySetting.HarmBlockThreshold" ,
1757
+ method : Optional ["SafetySetting.HarmBlockMethod" ] = None ,
1758
+ ):
1759
+ r"""Safety settings.
1760
+
1761
+ Args:
1762
+ category: Harm category.
1763
+ threshold: The harm block threshold.
1764
+ method: Specify if the threshold is used for probability or severity
1765
+ score. If not specified, the threshold is used for probability
1766
+ score.
1767
+ """
1768
+ self ._raw_safety_setting = gapic_content_types .SafetySetting (
1769
+ category = category ,
1770
+ threshold = threshold ,
1771
+ method = method ,
1772
+ )
1773
+
1774
+ @classmethod
1775
+ def _from_gapic (
1776
+ cls ,
1777
+ raw_safety_setting : gapic_content_types .SafetySetting ,
1778
+ ) -> "SafetySetting" :
1779
+ response = cls (
1780
+ category = raw_safety_setting .category ,
1781
+ threshold = raw_safety_setting .threshold ,
1782
+ )
1783
+ response ._raw_safety_setting = raw_safety_setting
1784
+ return response
1785
+
1786
+ @classmethod
1787
+ def from_dict (cls , safety_setting_dict : Dict [str , Any ]) -> "SafetySetting" :
1788
+ raw_safety_setting = gapic_content_types .SafetySetting (
1789
+ safety_setting_dict
1790
+ )
1791
+ return cls ._from_gapic (raw_safety_setting = raw_safety_setting )
1792
+
1793
+ def to_dict (self ) -> Dict [str , Any ]:
1794
+ return type (self ._raw_safety_setting ).to_dict (self ._raw_safety_setting )
1795
+
1796
+ def __repr__ (self ):
1797
+ return self ._raw_safety_setting .__repr__ ()
1798
+
1799
+
1741
1800
class grounding : # pylint: disable=invalid-name
1742
1801
"""Grounding namespace."""
1743
1802
0 commit comments