Skip to content

Commit 962802c

Browse files
authored
Feature: add password and extraction parameters for document translation
1 parent 9583aa7 commit 962802c

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

examples/memories_management.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def main():
2626
lara = Translator(credentials)
2727

2828
memory_id = None
29-
external_memory_id = None
3029
memory_2_to_delete = None
3130

3231
try:
@@ -147,12 +146,6 @@ def main():
147146
except Exception as e:
148147
print(f"Error deleting memory: {e}")
149148

150-
if external_memory_id:
151-
try:
152-
deleted_external_memory = lara.memories.delete(external_memory_id)
153-
print(f"🗑️ Deleted external memory: {deleted_external_memory.name}")
154-
except Exception as e:
155-
print(f"Error deleting external memory: {e}")
156149

157150
if memory_2_to_delete:
158151
try:

src/lara_sdk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from ._client import LaraObject
22
from ._credentials import Credentials
33
from ._errors import LaraApiError, LaraError
4-
from ._translator import Memory, MemoryImport, TextBlock, TextResult, Memories, Translator, TranslatePriority, UseCache, Documents, Document, DocumentStatus
4+
from ._translator import Memory, MemoryImport, TextBlock, TextResult, Memories, Translator, TranslatePriority, UseCache, Documents, Document, DocumentStatus, DocxExtractionParams, DocumentExtractionParams
55

66
# This constant is auto-generated by the build script.
77
# Manual modifications will be overwritten and may cause unexpected behavior.

src/lara_sdk/_translator.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ class DocumentOptions:
6767
no_trace: Optional[bool] = None
6868
style: Optional[TranslationStyle] = None
6969

70+
# Extraction parameters for DOCX files
71+
@dataclass
72+
class DocxExtractionParams:
73+
extract_comments: Optional[bool] = None
74+
accept_revisions: Optional[bool] = None
75+
76+
def to_dict(self) -> Dict[str, Union[str, bool]]:
77+
result = {}
78+
if self.extract_comments is not None:
79+
result['extract_comments'] = self.extract_comments
80+
if self.accept_revisions is not None:
81+
result['accept_revisions'] = self.accept_revisions
82+
return result
83+
84+
# Union type for all extraction parameter types
85+
DocumentExtractionParams = Union[DocxExtractionParams]
86+
7087
class Document(LaraObject):
7188

7289
def __init__(self, **kwargs):
@@ -300,7 +317,8 @@ def __init__(self, client: LaraClient):
300317

301318
def upload(self, file_path: str, filename: str, target: str, source: Optional[str] = None,
302319
adapt_to: Optional[List[str]] = None, glossaries: Optional[List[str]] = None, no_trace: bool = False,
303-
style: Optional[TranslationStyle] = None) -> Document:
320+
style: Optional[TranslationStyle] = None, password: Optional[str] = None,
321+
extraction_params: Optional[DocumentExtractionParams] = None) -> Document:
304322
with open(file_path, 'rb') as file_payload:
305323
response_data = self._client.get('/documents/upload-url', {'filename': filename})
306324

@@ -322,9 +340,15 @@ def upload(self, file_path: str, filename: str, target: str, source: Optional[st
322340
if glossaries is not None:
323341
body['glossaries'] = glossaries
324342

343+
if password is not None:
344+
body['password'] = password
345+
325346
if style is not None:
326347
body['style'] = style
327348

349+
if extraction_params is not None:
350+
body['extraction_params'] = extraction_params.to_dict()
351+
328352
headers = None
329353
if no_trace is True:
330354
headers = {'X-No-Trace': 'true'}
@@ -343,10 +367,11 @@ def download(self, id: str, output_format: Optional[str] = None) -> bytes:
343367

344368
def translate(self, file_path: str, filename: str, target: str, source: Optional[str] = None,
345369
adapt_to: Optional[List[str]] = None, glossaries: Optional[List[str]] = None, output_format: Optional[str] = None,
346-
no_trace: bool = False, style: Optional[TranslationStyle] = None) -> bytes:
370+
no_trace: bool = False, style: Optional[TranslationStyle] = None, password: Optional[str] = None,
371+
extraction_params: Optional[DocumentExtractionParams] = None) -> bytes:
347372

348373
document = self.upload(file_path=file_path, filename=filename, target=target, source=source, adapt_to=adapt_to,
349-
glossaries=glossaries, no_trace=no_trace, style=style)
374+
glossaries=glossaries, no_trace=no_trace, style=style, password=password, extraction_params=extraction_params)
350375

351376
max_wait_time = 60 * 15 # 15 minutes
352377
start = time.time()

0 commit comments

Comments
 (0)