66from ._config import ClientConfig
77
88
9+ class TranslateImageParams (TypedDict ):
10+ target_language : str
11+ """
12+ Target langauge to translate to.
13+ """
14+ url : str
15+ """
16+ The URL of the image to translate.
17+ """
18+ file_store_key : NotRequired [str ]
19+ """
20+ The file store key of the image to translate.
21+ """
22+
923class TranslateParams (TypedDict ):
1024 target_language : str
1125 """
@@ -20,7 +34,6 @@ class TranslateParams(TypedDict):
2034 The text to translate.
2135 """
2236
23-
2437class TranslateResponse (TypedDict ):
2538 success : bool
2639 """
@@ -31,6 +44,15 @@ class TranslateResponse(TypedDict):
3144 The translated text.
3245 """
3346
47+ class TranslateImageResponse (TypedDict ):
48+ success : bool
49+ """
50+ Indicates whether the translation was successful.
51+ """
52+ image : bytes
53+ """
54+ The image data that was translated.
55+ """
3456
3557class TranslateListResponse (TypedDict ):
3658 success : bool
@@ -61,15 +83,18 @@ def __init__(
6183 )
6284
6385 def translate (
64- self , params : TranslateParams
65- ) -> Union [TranslateResponse , TranslateListResponse ]:
66- path = "/ai/translate"
86+ self , params : Union [TranslateParams , TranslateImageParams ]
87+ ) -> Union [TranslateResponse , TranslateListResponse , TranslateImageResponse ]:
88+ if "url" in params or "file_store_key" in params :
89+ path = "/ai/translate/image"
90+ else :
91+ path = "/ai/translate"
6792 resp = Request (
6893 config = self .config ,
6994 path = path ,
7095 params = cast (Dict [Any , Any ], params ),
7196 verb = "post" ,
72- ).perform_with_content ()
97+ ).perform ()
7398 return resp
7499
75100
@@ -91,13 +116,16 @@ def __init__(
91116 )
92117
93118 async def translate (
94- self , params : TranslateParams
95- ) -> Union [TranslateResponse , TranslateListResponse ]:
96- path = "/ai/translate"
119+ self , params : Union [TranslateParams , TranslateImageParams ]
120+ ) -> Union [TranslateResponse , TranslateListResponse , TranslateImageParams ]:
121+ if "url" in params or "file_store_key" in params :
122+ path = "/ai/translate/image"
123+ else :
124+ path = "/ai/translate"
97125 resp = await AsyncRequest (
98126 config = self .config ,
99127 path = path ,
100128 params = cast (Dict [Any , Any ], params ),
101129 verb = "post" ,
102- ).perform_with_content ()
130+ ).perform ()
103131 return resp
0 commit comments