Skip to content

Commit

Permalink
Adding random seed
Browse files Browse the repository at this point in the history
  • Loading branch information
akamor committed Nov 13, 2024
1 parent 82b78c9 commit 087ab1f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tonic_textual/classes/parse_api_responses/file_parse_result.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Dict, List, Union
from typing import Dict, List, Optional, Union

import requests
from requests import RequestException
Expand Down Expand Up @@ -111,6 +111,7 @@ def get_markdown(
self,
generator_config: Dict[str, PiiState] = dict(),
generator_default: PiiState = PiiState.Off,
random_seed: Optional[int] = None
) -> str:
"""Returns file in markdown format, redacted or synthesized based on config.
Expand All @@ -124,7 +125,12 @@ def get_markdown(
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".
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.
Returns
-------
str
Expand All @@ -143,6 +149,12 @@ def get_markdown(
utf_compatible_filtered_entities = make_utf_compatible_entities(
rawtext, filtered_entities
)

if random_seed is not None:
additional_headers = {"textual-random-seed": str(random_seed)}
else:
additional_headers = {}

response = self.client.http_post(
"/api/redact/known_entities",
data={
Expand All @@ -151,6 +163,7 @@ def get_markdown(
"generatorConfig": generator_config,
"generatorDefault": generator_default,
},
additional_headers=additional_headers
)
return response["redactedText"]

Expand Down

0 comments on commit 087ab1f

Please sign in to comment.