55from typing import List , Union
66from ._config import ClientConfig
77from .helpers import build_path
8+ from ._types import BaseResponse
9+
810
911class TranslateImageParams (TypedDict ):
1012 target_language : str
@@ -22,12 +24,13 @@ class TranslateImageParams(TypedDict):
2224
2325 return_type : NotRequired [Literal ["url" , "binary" , "base64" ]]
2426
27+
2528class TranslateParams (TypedDict ):
2629 target_language : str
2730 """
2831 Target langauge to translate to.
2932 """
30- current_language : str
33+ current_language : NotRequired [ str ]
3134 """
3235 Language to translate from.
3336 """
@@ -36,16 +39,14 @@ class TranslateParams(TypedDict):
3639 The text to translate.
3740 """
3841
39- class TranslateResponse (TypedDict ):
40- success : bool
41- """
42- Indicates whether the translation was successful.
43- """
44- translated_text : str
42+
43+ class TranslateResponse (BaseResponse ):
44+ translated_text : Union [str , List [str ]]
4545 """
4646 The translated text.
4747 """
4848
49+
4950class TranslateImageResponse (TypedDict ):
5051 success : bool
5152 """
@@ -56,6 +57,7 @@ class TranslateImageResponse(TypedDict):
5657 The image data that was translated.
5758 """
5859
60+
5961class TranslateListResponse (TypedDict ):
6062 success : bool
6163 """
@@ -94,18 +96,22 @@ def text(
9496 verb = "post" ,
9597 ).perform ()
9698 return resp
97-
99+
98100 @overload
99101 def image (self , params : TranslateImageParams ) -> TranslateImageResponse : ...
100102 @overload
101- def image (self , blob : bytes , options : TranslateImageParams = None ) -> TranslateImageParams : ...
103+ def image (
104+ self , blob : bytes , options : TranslateImageParams = None
105+ ) -> TranslateImageParams : ...
102106
103107 def image (
104108 self ,
105109 blob : Union [TranslateImageParams , bytes ],
106110 options : TranslateImageParams = None ,
107111 ) -> TranslateImageResponse :
108- if isinstance (blob , dict ): # If params is provided as a dict, we assume it's the first argument
112+ if isinstance (
113+ blob , dict
114+ ): # If params is provided as a dict, we assume it's the first argument
109115 resp = Request (
110116 config = self .config ,
111117 path = "/ai/translate/image" ,
@@ -156,12 +162,14 @@ async def text(
156162 verb = "post" ,
157163 ).perform ()
158164 return resp
159-
165+
160166 @overload
161167 async def image (self , params : TranslateImageParams ) -> TranslateImageResponse : ...
162168 @overload
163- async def image (self , blob : bytes , options : TranslateImageParams = None ) -> TranslateImageParams : ...
164-
169+ async def image (
170+ self , blob : bytes , options : TranslateImageParams = None
171+ ) -> TranslateImageParams : ...
172+
165173 async def image (
166174 self ,
167175 blob : Union [TranslateImageParams , bytes ],
@@ -189,4 +197,4 @@ async def image(
189197 headers = headers ,
190198 verb = "post" ,
191199 ).perform_with_content ()
192- return resp
200+ return resp
0 commit comments