Skip to content

Commit ff45b04

Browse files
feat: [google-cloud-language] add model_version in ModerateTextRequest and expose severity score in ClassificationCategory (#12945)
- [ ] Regenerate this pull request now. docs: minor update on documentation PiperOrigin-RevId: 656075693 Source-Link: googleapis/googleapis@ba245fa Source-Link: googleapis/googleapis-gen@93f7fef Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWNsb3VkLWxhbmd1YWdlLy5Pd2xCb3QueWFtbCIsImgiOiI5M2Y3ZmVmNTZkYjNmMjc0ZGU3NGJhOWM2YTY5NDFmNmNjYzc0MjRmIn0= --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 8a2814b commit ff45b04

File tree

9 files changed

+54
-17
lines changed

9 files changed

+54
-17
lines changed

packages/google-cloud-language/google/cloud/language/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "2.13.4" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-language/google/cloud/language_v1/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "2.13.4" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-language/google/cloud/language_v1beta2/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "2.13.4" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-language/google/cloud/language_v2/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "2.13.4" # {x-release-please-version}
16+
__version__ = "0.0.0" # {x-release-please-version}

packages/google-cloud-language/google/cloud/language_v2/types/language_service.py

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,9 @@ class Entity(proto.Message):
191191
metadata (MutableMapping[str, str]):
192192
Metadata associated with the entity.
193193
194-
For most entity types, the metadata is a Wikipedia URL
195-
(``wikipedia_url``) and Knowledge Graph MID (``mid``), if
196-
they are available. For the metadata associated with other
197-
entity types, see the Type table below.
194+
For the metadata
195+
associated with other entity types, see the Type
196+
table below.
198197
mentions (MutableSequence[google.cloud.language_v2.types.EntityMention]):
199198
The mentions of this entity in the input
200199
document. The API currently supports proper noun
@@ -208,10 +207,9 @@ class Entity(proto.Message):
208207
"""
209208

210209
class Type(proto.Enum):
211-
r"""The type of the entity. For most entity types, the associated
212-
metadata is a Wikipedia URL (``wikipedia_url``) and Knowledge Graph
213-
MID (``mid``). The table below lists the associated fields for
214-
entities that have different metadata.
210+
r"""The type of the entity. The table
211+
below lists the associated fields for entities that have
212+
different metadata.
215213
216214
Values:
217215
UNKNOWN (0):
@@ -253,7 +251,7 @@ class Type(proto.Enum):
253251
- ``locality`` - city or town
254252
- ``street_name`` - street/route name, if detected
255253
- ``postal_code`` - postal code, if detected
256-
- ``country`` - country, if detected<
254+
- ``country`` - country, if detected
257255
- ``broad_region`` - administrative area, such as the
258256
state, if detected
259257
- ``narrow_region`` - smaller administrative area, such as
@@ -434,6 +432,11 @@ class ClassificationCategory(proto.Message):
434432
The classifier's confidence of the category.
435433
Number represents how certain the classifier is
436434
that this category represents the given text.
435+
severity (float):
436+
Optional. The classifier's severity of the category. This is
437+
only present when the ModerateTextRequest.ModelVersion is
438+
set to MODEL_VERSION_2, and the corresponding category has a
439+
severity score.
437440
"""
438441

439442
name: str = proto.Field(
@@ -444,6 +447,10 @@ class ClassificationCategory(proto.Message):
444447
proto.FLOAT,
445448
number=2,
446449
)
450+
severity: float = proto.Field(
451+
proto.FLOAT,
452+
number=3,
453+
)
447454

448455

449456
class AnalyzeSentimentRequest(proto.Message):
@@ -621,13 +628,43 @@ class ModerateTextRequest(proto.Message):
621628
Attributes:
622629
document (google.cloud.language_v2.types.Document):
623630
Required. Input document.
631+
model_version (google.cloud.language_v2.types.ModerateTextRequest.ModelVersion):
632+
Optional. The model version to use for
633+
ModerateText.
624634
"""
625635

636+
class ModelVersion(proto.Enum):
637+
r"""The model version to use for ModerateText.
638+
639+
Values:
640+
MODEL_VERSION_UNSPECIFIED (0):
641+
The default model version.
642+
MODEL_VERSION_1 (1):
643+
Use the v1 model, this model is used by
644+
default when not provided. The v1 model only
645+
returns probability (confidence) score for each
646+
category.
647+
MODEL_VERSION_2 (2):
648+
Use the v2 model.
649+
The v2 model only returns probability
650+
(confidence) score for each category, and
651+
returns severity score for a subset of the
652+
categories.
653+
"""
654+
MODEL_VERSION_UNSPECIFIED = 0
655+
MODEL_VERSION_1 = 1
656+
MODEL_VERSION_2 = 2
657+
626658
document: "Document" = proto.Field(
627659
proto.MESSAGE,
628660
number=1,
629661
message="Document",
630662
)
663+
model_version: ModelVersion = proto.Field(
664+
proto.ENUM,
665+
number=2,
666+
enum=ModelVersion,
667+
)
631668

632669

633670
class ModerateTextResponse(proto.Message):

packages/google-cloud-language/samples/generated_samples/snippet_metadata_google.cloud.language.v1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-language",
11-
"version": "2.13.4"
11+
"version": "0.1.0"
1212
},
1313
"snippets": [
1414
{

packages/google-cloud-language/samples/generated_samples/snippet_metadata_google.cloud.language.v1beta2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-language",
11-
"version": "2.13.4"
11+
"version": "0.1.0"
1212
},
1313
"snippets": [
1414
{

packages/google-cloud-language/samples/generated_samples/snippet_metadata_google.cloud.language.v2.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"language": "PYTHON",
1010
"name": "google-cloud-language",
11-
"version": "2.13.4"
11+
"version": "0.1.0"
1212
},
1313
"snippets": [
1414
{

packages/google-cloud-language/scripts/fixup_language_v2_keywords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class languageCallTransformer(cst.CSTTransformer):
4343
'analyze_sentiment': ('document', 'encoding_type', ),
4444
'annotate_text': ('document', 'features', 'encoding_type', ),
4545
'classify_text': ('document', ),
46-
'moderate_text': ('document', ),
46+
'moderate_text': ('document', 'model_version', ),
4747
}
4848

4949
def leave_Call(self, original: cst.Call, updated: cst.Call) -> cst.CSTNode:

0 commit comments

Comments
 (0)