Skip to content

Commit

Permalink
Text edits
Browse files Browse the repository at this point in the history
  • Loading branch information
JaniceManwiller authored Nov 21, 2024
1 parent 3e206b0 commit 7c5720a
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions tonic_textual/redact_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,18 @@


class TextualNer:
"""Wrapper class for invoking Tonic Textual API
"""Wrapper class to invoke the Tonic Textual API
Parameters
----------
base_url : str
The URL to your Tonic Textual instance. Do not include trailing backslashes. The default value is https://textual.tonic.ai.
The URL to your Tonic Textual instance. Do not include trailing backslashes. The default value is https://textual.tonic.ai.
api_key : str
Your API token. This argument is optional. Instead of providing the API token
here, it is recommended that you set the API key in your environment as the
Optional. Your API token. Instead of providing the API token
here, we recommended that you set the API key in your environment as the
value of TONIC_TEXTUAL_API_KEY.
verify: bool
Whether SSL Certification verification is performed. This is enabled by
default.
Whether to verify SSL certification. By default, this is enabled.
Examples
--------
>>> from tonic_textual.redact_api import TextualNer
Expand Down Expand Up @@ -159,8 +158,8 @@ def unredact_bulk(
The list of redacted strings from which to remove the redaction.
random_seed: Optional[int] = None
An optional value to use to override Textual's default random number
seeding. Can be used to ensure that different API calls use the same or
Ann optional value to use to override Textual's default random number
seeding. Can be used to ensure that different API calls use the same or
different random seeds.
Returns
Expand Down Expand Up @@ -192,7 +191,7 @@ def unredact(self, redacted_string: str, random_seed: Optional[int] = None) -> s
random_seed: Optional[int] = None
An optional value to use to override Textual's default random number
seeding. Can be used to ensure that different API calls use the same or
seeding. Can be used to ensure that different API calls use the same or
different random seeds.
Returns
Expand Down Expand Up @@ -224,7 +223,7 @@ def redact(
label_allow_lists: Optional[Dict[str, List[str]]] = None,
) -> RedactionResponse:
"""Redacts a string. Depending on the configured handling for each sensitive
data type, values can be either redacted, synthesized, or ignored.
data type, values are either redacted, synthesized, or ignored.
Parameters
----------
Expand All @@ -237,8 +236,8 @@ def redact(
Values must be one of "Redaction", "Synthesis", or "Off".
generator_default: PiiState = PiiState.Redaction
The default redaction used for all types not specified in generator_config.
Values must be one of "Redaction", "Synthesis", or "Off".
The default redaction used for types that are not specified in generator_config.
Value must be one of "Redaction", "Synthesis", or "Off".
random_seed: Optional[int] = None
An optional value to use to override Textual's default random number
Expand Down Expand Up @@ -305,7 +304,7 @@ def redact_bulk(
label_allow_lists: Optional[Dict[str, List[str]]] = None,
) -> BulkRedactionResponse:
"""Redacts a string. Depending on the configured handling for each sensitive
data type, values can be either redacted, synthesized, or ignored.
data type, values are either redacted, synthesized, or ignored.
Parameters
----------
Expand All @@ -318,8 +317,8 @@ def redact_bulk(
Values must be one of "Redaction", "Synthesis", or "Off".
generator_default: PiiState = PiiState.Redaction
The default redaction used for all types not specified in generator_config.
Values must be one of "Redaction", "Synthesis", or "Off".
The default redaction used for all types that are not specified in generator_config.
Value must be one of "Redaction", "Synthesis", or "Off".
random_seed: Optional[int] = None
An optional value to use to override Textual's default random number
Expand Down Expand Up @@ -382,7 +381,7 @@ def llm_synthesis(
generator_config: Dict[str, PiiState] = dict(),
generator_default: PiiState = PiiState.Redaction,
) -> RedactionResponse:
"""Deidentifies a string by redacting sensitive data and replacing these values
"""Deidentifies a string. Redacting sensitive data and replaces those values
with values generated by an LLM.
Parameters
Expand All @@ -395,7 +394,7 @@ def llm_synthesis(
whether to redact, synthesize, or ignore it.
generator_default: PiiState = PiiState.Redaction
The default redaction used for all types not specified in generator_config.
The default redaction used for all types that are not specified in generator_config.
Returns
-------
Expand Down Expand Up @@ -438,29 +437,29 @@ def redact_json(
jsonpath_allow_lists: Optional[Dict[str, List[str]]] = None,
) -> RedactionResponse:
"""Redacts the values in a JSON blob. Depending on the configured handling for
each sensitive data type, values can be either redacted, synthesized, or
each sensitive data type, values are either redacted, synthesized, or
ignored.
Parameters
----------
json_string : Union[str, dict]
The JSON whose values will be redacted. This can be either a JSON string
or a Python dictionary
The JSON for which to redact values. This can be either a JSON string
or a Python dictionary.
generator_config: Dict[str, PiiState]
A dictionary of sensitive data entities. For each entity, indicates whether
to redact, synthesize, or ignore it.
generator_default: PiiState = PiiState.Redaction
The default redaction used for all types not specified in generator_config.
The default redaction to use for all types that are not specified in generator_config.
random_seed: Optional[int] = None
An optional value to use to override Textual's default random number
seeding. Can be used to ensure that different API calls use the same or
different random seeds.
label_block_lists: Optional[Dict[str, List[str]]]
A dictionary of (entity type, ignored values). When an value for the entity type, matches a listed regular expression,
A dictionary of (entity type, ignored values). When an value for the entity type matches a listed regular expression,
the value is ignored and is not redacted or synthesized.
label_allow_lists: Optional[Dict[str, List[str]]]
Expand Down Expand Up @@ -538,7 +537,7 @@ def redact_xml(
different random seeds.
label_block_lists: Optional[Dict[str, List[str]]]
A dictionary of (entity type, ignored values). When an value for the entity type, matches a listed regular expression,
A dictionary of (entity type, ignored values). When an value for the entity type matches a listed regular expression,
the value is ignored and is not redacted or synthesized.
label_allow_lists: Optional[Dict[str, List[str]]]
Expand Down Expand Up @@ -735,14 +734,14 @@ def start_file_redaction(self, file: io.IOBase, file_name: str) -> str:
Parameters
--------
file: io.IOBase
The opened file, available for reading, which will be uploaded and redacted
The opened file, available for reading, to upload and redact.
file_name: str
The name of the file
The name of the file.
Returns
-------
str
The job id which can be used to download the redacted file once it is ready
The job identifier, which can be used to download the redacted file when it is ready.
"""

Expand Down Expand Up @@ -775,14 +774,14 @@ def download_redacted_file(
Parameters
--------
job_id: str
The ID of the redaction job
The identifier of the redaction job.
generator_config: Dict[str, PiiState]
A dictionary of sensitive data entities. For each entity, indicates whether
to redact, synthesize, or ignore it.
generator_default: PiiState = PiiState.Redaction
The default redaction used for all types not specified in generator_config.
The default redaction used for all types that are not specified in generator_config.
random_seed: Optional[int] = None
An optional value to use to override Textual's default random number
Expand All @@ -794,17 +793,17 @@ def download_redacted_file(
the value is ignored and is not redacted or synthesized.
num_retries: int = 6
An optional value to specify how many times to attempt to download the
file. If a file is not yet ready for download, there will be a 10 second
An optional value to specify the number of times to attempt to download the
file. If a file is not yet ready for download, Textual pauses 10-second
pause before retrying. (The default value is 6)
wait_between_retries: int = 10
The number of seconds to wait between retry attempts. (The default value is 6)
The number of seconds to wait between retry attempts. (The default value is 10)
Returns
-------
bytes
The redacted file as byte array
The redacted file as a byte array.
"""

validate_generator_options(generator_default, generator_config)
Expand Down Expand Up @@ -837,8 +836,8 @@ def download_redacted_file(

retryWord = "retry" if num_retries == 1 else "retries"
raise FileNotReadyForDownload(
f"After {num_retries} {retryWord} the file is not yet ready for download. "
"This is likely due to a high service load. Please try again later."
f"After {num_retries} {retryWord}, the file is not yet ready to download. "
"This is likely due to a high service load. Try again later."
)


Expand Down

0 comments on commit 7c5720a

Please sign in to comment.