genai.text.moderation.moderation_service module#

pydantic model genai.text.moderation.moderation_service.BaseConfig[source]#

Bases: BaseServiceConfig

Config:
  • extra: str = forbid

  • validate_assignment: bool = True

  • validate_default: bool = True

field create_execution_options: CreateExecutionOptions = CreateExecutionOptions(throw_on_error=True, ordered=True)#
pydantic model genai.text.moderation.moderation_service.CreateExecutionOptions[source]#

Bases: BaseServiceConfig

Config:
  • extra: str = forbid

  • validate_assignment: bool = True

  • validate_default: bool = True

field ordered: bool = True#

Items will be yielded in the order they were passed in, although they may be processed on the server in different order.

field throw_on_error: bool = True#

Flag indicating whether to throw an error if any error occurs during execution (if disabled, ‘None’ may be returned in case of error).

class genai.text.moderation.moderation_service.ModerationService[source]#

Bases: BaseService[BaseConfig, BaseServiceServices]

Config#

alias of BaseConfig

create(inputs, *, hap=None, social_bias=None, execution_options=None)[source]#
Parameters:
  • inputs (str | list[str]) – Prompt/Prompts for text moderation.

  • hap (dict | HAPOptions | None) – HAP configuration (hate, abuse, profanity).

  • social_bias (dict | SocialBiasOptions | None) – Social Bias configuration.

  • execution_options (dict | CreateExecutionOptions | None) – Configuration processing.

Return type:

Generator[TextModerationCreateResponse, None, None]

Example

from genai import Client, Credentials from genai.text.moderation import HAPOptions

client = Client(credentials=Credentials.from_env()) inputs = [“First input”, “Second input”] counter = 0

for response in client.text.moderation.create(inputs=inputs, hap=HAPOptions(threshold=0.65)):
for result in response.results:

input = inputs[counter] counter += 1 print(f”Response for {input}”, result.hap)

Raises:
Parameters:
  • inputs (str | list[str]) –

  • hap (dict | HAPOptions | None) –

  • social_bias (dict | SocialBiasOptions | None) –

  • execution_options (dict | CreateExecutionOptions | None) –

Return type:

Generator[TextModerationCreateResponse, None, None]