Skip to content

Commit bb61e7e

Browse files
authored
Add custom headers in translate request
1 parent c6fe2e7 commit bb61e7e

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/lara_sdk/_translator.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22
from datetime import datetime
33
from enum import Enum
4-
from typing import Optional, Union, List, Iterable, Callable, Literal
4+
from typing import Optional, Union, List, Iterable, Callable, Literal, Dict
55
from dataclasses import dataclass
66

77
from gzip_stream import GZIPCompressedStream
@@ -387,7 +387,8 @@ def translate(self, text: Union[str, Iterable[str], Iterable[TextBlock]], *,
387387
glossaries: List[str] = None, instructions: List[str] = None, content_type: str = None,
388388
multiline: bool = True, timeout_ms: int = None, priority: TranslatePriority = None,
389389
use_cache: Union[bool, UseCache] = None, cache_ttl_s: int = None,
390-
no_trace: bool = False, verbose: bool = False) -> TextResult:
390+
no_trace: bool = False, verbose: bool = False,
391+
headers: Optional[Dict[str, str]] = None) -> TextResult:
391392
if isinstance(text, str):
392393
q = text
393394
elif hasattr(text, '__iter__'):
@@ -413,8 +414,10 @@ def translate(self, text: Union[str, Iterable[str], Iterable[TextBlock]], *,
413414
'glossaries': glossaries, 'verbose': verbose
414415
}
415416

416-
headers = None
417+
request_headers = {}
418+
if headers is not None:
419+
request_headers.update(headers)
417420
if no_trace is True:
418-
headers = {'X-No-Trace': 'true'}
421+
request_headers['X-No-Trace'] = 'true'
419422

420-
return TextResult(**self._client.post('/translate', body, headers=headers))
423+
return TextResult(**self._client.post('/translate', body, headers=request_headers))

0 commit comments

Comments
 (0)