Skip to content

Commit

Permalink
feat: [google-cloud-language] add model_version in ModerateTextReques…
Browse files Browse the repository at this point in the history
…t 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>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Jul 29, 2024
1 parent 8a2814b commit ff45b04
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "2.13.4" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "2.13.4" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "2.13.4" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
__version__ = "2.13.4" # {x-release-please-version}
__version__ = "0.0.0" # {x-release-please-version}
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,9 @@ class Entity(proto.Message):
metadata (MutableMapping[str, str]):
Metadata associated with the entity.
For most entity types, the metadata is a Wikipedia URL
(``wikipedia_url``) and Knowledge Graph MID (``mid``), if
they are available. For the metadata associated with other
entity types, see the Type table below.
For the metadata
associated with other entity types, see the Type
table below.
mentions (MutableSequence[google.cloud.language_v2.types.EntityMention]):
The mentions of this entity in the input
document. The API currently supports proper noun
Expand All @@ -208,10 +207,9 @@ class Entity(proto.Message):
"""

class Type(proto.Enum):
r"""The type of the entity. For most entity types, the associated
metadata is a Wikipedia URL (``wikipedia_url``) and Knowledge Graph
MID (``mid``). The table below lists the associated fields for
entities that have different metadata.
r"""The type of the entity. The table
below lists the associated fields for entities that have
different metadata.
Values:
UNKNOWN (0):
Expand Down Expand Up @@ -253,7 +251,7 @@ class Type(proto.Enum):
- ``locality`` - city or town
- ``street_name`` - street/route name, if detected
- ``postal_code`` - postal code, if detected
- ``country`` - country, if detected<
- ``country`` - country, if detected
- ``broad_region`` - administrative area, such as the
state, if detected
- ``narrow_region`` - smaller administrative area, such as
Expand Down Expand Up @@ -434,6 +432,11 @@ class ClassificationCategory(proto.Message):
The classifier's confidence of the category.
Number represents how certain the classifier is
that this category represents the given text.
severity (float):
Optional. The classifier's severity of the category. This is
only present when the ModerateTextRequest.ModelVersion is
set to MODEL_VERSION_2, and the corresponding category has a
severity score.
"""

name: str = proto.Field(
Expand All @@ -444,6 +447,10 @@ class ClassificationCategory(proto.Message):
proto.FLOAT,
number=2,
)
severity: float = proto.Field(
proto.FLOAT,
number=3,
)


class AnalyzeSentimentRequest(proto.Message):
Expand Down Expand Up @@ -621,13 +628,43 @@ class ModerateTextRequest(proto.Message):
Attributes:
document (google.cloud.language_v2.types.Document):
Required. Input document.
model_version (google.cloud.language_v2.types.ModerateTextRequest.ModelVersion):
Optional. The model version to use for
ModerateText.
"""

class ModelVersion(proto.Enum):
r"""The model version to use for ModerateText.
Values:
MODEL_VERSION_UNSPECIFIED (0):
The default model version.
MODEL_VERSION_1 (1):
Use the v1 model, this model is used by
default when not provided. The v1 model only
returns probability (confidence) score for each
category.
MODEL_VERSION_2 (2):
Use the v2 model.
The v2 model only returns probability
(confidence) score for each category, and
returns severity score for a subset of the
categories.
"""
MODEL_VERSION_UNSPECIFIED = 0
MODEL_VERSION_1 = 1
MODEL_VERSION_2 = 2

document: "Document" = proto.Field(
proto.MESSAGE,
number=1,
message="Document",
)
model_version: ModelVersion = proto.Field(
proto.ENUM,
number=2,
enum=ModelVersion,
)


class ModerateTextResponse(proto.Message):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"language": "PYTHON",
"name": "google-cloud-language",
"version": "2.13.4"
"version": "0.1.0"
},
"snippets": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"language": "PYTHON",
"name": "google-cloud-language",
"version": "2.13.4"
"version": "0.1.0"
},
"snippets": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"language": "PYTHON",
"name": "google-cloud-language",
"version": "2.13.4"
"version": "0.1.0"
},
"snippets": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class languageCallTransformer(cst.CSTTransformer):
'analyze_sentiment': ('document', 'encoding_type', ),
'annotate_text': ('document', 'features', 'encoding_type', ),
'classify_text': ('document', ),
'moderate_text': ('document', ),
'moderate_text': ('document', 'model_version', ),
}

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

0 comments on commit ff45b04

Please sign in to comment.