11import time
22from datetime import datetime
33from enum import Enum
4- from typing import Optional , Union , List , Iterable , Callable , Literal
4+ from typing import Optional , Union , List , Iterable , Callable , Literal , Dict
55from dataclasses import dataclass
66
77from 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