yandex_cloud/
yandex.cloud.ai.translate.v2.rs

1#[allow(clippy::derive_partial_eq_without_eq)]
2#[derive(Clone, PartialEq, ::prost::Message)]
3pub struct TranslatedText {
4    /// Translated text.
5    #[prost(string, tag = "1")]
6    pub text: ::prost::alloc::string::String,
7    /// The language code of the source text.
8    /// Most languages are specified in [ISO 639-1](<https://en.wikipedia.org/wiki/ISO_639-1>) format (for example, `` ru ``), but the field are not limited to it.
9    #[prost(string, tag = "2")]
10    pub detected_language_code: ::prost::alloc::string::String,
11}
12#[allow(clippy::derive_partial_eq_without_eq)]
13#[derive(Clone, PartialEq, ::prost::Message)]
14pub struct Language {
15    /// The language code.
16    /// Most languages are specified in [ISO 639-1](<https://en.wikipedia.org/wiki/ISO_639-1>) format (for example, `` ru ``), but the field are not limited to it.
17    #[prost(string, tag = "1")]
18    pub code: ::prost::alloc::string::String,
19    /// The name of the language (for example, `` English ``).
20    #[prost(string, tag = "2")]
21    pub name: ::prost::alloc::string::String,
22}
23#[allow(clippy::derive_partial_eq_without_eq)]
24#[derive(Clone, PartialEq, ::prost::Message)]
25pub struct TranslateRequest {
26    /// The text language to translate from.
27    /// Most languages are specified in [ISO 639-1](<https://en.wikipedia.org/wiki/ISO_639-1>) format (for example, `` ru ``), but the field are not limited to it.
28    ///
29    /// Required for translating with \[glossary\](/docs/translate/concepts/glossary).
30    #[prost(string, tag = "1")]
31    pub source_language_code: ::prost::alloc::string::String,
32    /// The target language to translate the text.
33    /// Most languages are specified in [ISO 639-1](<https://en.wikipedia.org/wiki/ISO_639-1>) format (for example, `` ru ``), but the field are not limited to it.
34    #[prost(string, tag = "2")]
35    pub target_language_code: ::prost::alloc::string::String,
36    /// Format of the text to be translated.
37    #[prost(enumeration = "translate_request::Format", tag = "3")]
38    pub format: i32,
39    /// Array of the strings to translate.
40    /// The maximum total length of all strings is 10000 characters.
41    #[prost(string, repeated, tag = "4")]
42    pub texts: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
43    /// ID of the folder to which you have access.
44    /// Required for authorization with a [user account](/docs/iam/concepts/users/accounts).
45    /// Do not specify this field if you make the request on behalf of a [service account](/docs/iam/concepts/users/accounts#sa).
46    #[prost(string, tag = "5")]
47    pub folder_id: ::prost::alloc::string::String,
48    /// Model ID if you use custom model.
49    #[prost(string, tag = "6")]
50    pub model: ::prost::alloc::string::String,
51    /// Glossary to be applied for the translation. For more information, see \[Glossaries\](/docs/translate/concepts/glossary).
52    #[prost(message, optional, tag = "7")]
53    pub glossary_config: ::core::option::Option<TranslateGlossaryConfig>,
54    /// Enable spell checking.
55    #[prost(bool, tag = "8")]
56    pub speller: bool,
57}
58/// Nested message and enum types in `TranslateRequest`.
59pub mod translate_request {
60    #[derive(
61        Clone,
62        Copy,
63        Debug,
64        PartialEq,
65        Eq,
66        Hash,
67        PartialOrd,
68        Ord,
69        ::prost::Enumeration
70    )]
71    #[repr(i32)]
72    pub enum Format {
73        Unspecified = 0,
74        /// Text without markup. Default value.
75        PlainText = 1,
76        /// Text in the HTML format.
77        Html = 2,
78    }
79    impl Format {
80        /// String value of the enum field names used in the ProtoBuf definition.
81        ///
82        /// The values are not transformed in any way and thus are considered stable
83        /// (if the ProtoBuf definition does not change) and safe for programmatic use.
84        pub fn as_str_name(&self) -> &'static str {
85            match self {
86                Format::Unspecified => "FORMAT_UNSPECIFIED",
87                Format::PlainText => "PLAIN_TEXT",
88                Format::Html => "HTML",
89            }
90        }
91        /// Creates an enum from field names used in the ProtoBuf definition.
92        pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
93            match value {
94                "FORMAT_UNSPECIFIED" => Some(Self::Unspecified),
95                "PLAIN_TEXT" => Some(Self::PlainText),
96                "HTML" => Some(Self::Html),
97                _ => None,
98            }
99        }
100    }
101}
102#[allow(clippy::derive_partial_eq_without_eq)]
103#[derive(Clone, PartialEq, ::prost::Message)]
104pub struct TranslateGlossaryConfig {
105    #[prost(oneof = "translate_glossary_config::GlossarySource", tags = "1")]
106    pub glossary_source: ::core::option::Option<
107        translate_glossary_config::GlossarySource,
108    >,
109}
110/// Nested message and enum types in `TranslateGlossaryConfig`.
111pub mod translate_glossary_config {
112    #[allow(clippy::derive_partial_eq_without_eq)]
113    #[derive(Clone, PartialEq, ::prost::Oneof)]
114    pub enum GlossarySource {
115        /// Pass glossary data in the request. Currently, the only way to pass glossary.
116        #[prost(message, tag = "1")]
117        GlossaryData(super::GlossaryData),
118    }
119}
120#[allow(clippy::derive_partial_eq_without_eq)]
121#[derive(Clone, PartialEq, ::prost::Message)]
122pub struct GlossaryData {
123    /// Array of text pairs.
124    ///
125    /// The maximum total length of all source texts is 10000 characters.
126    /// The maximum total length of all translated texts is 10000 characters.
127    #[prost(message, repeated, tag = "1")]
128    pub glossary_pairs: ::prost::alloc::vec::Vec<GlossaryPair>,
129}
130#[allow(clippy::derive_partial_eq_without_eq)]
131#[derive(Clone, PartialEq, ::prost::Message)]
132pub struct GlossaryPair {
133    /// Text in the source language.
134    #[prost(string, tag = "1")]
135    pub source_text: ::prost::alloc::string::String,
136    /// Text in the target language.
137    #[prost(string, tag = "2")]
138    pub translated_text: ::prost::alloc::string::String,
139    /// Allows to add translations for specific terms to \[neuroglossaries\](/docs/translate/concepts/glossary#word-forms).
140    #[prost(bool, tag = "3")]
141    pub exact: bool,
142}
143#[allow(clippy::derive_partial_eq_without_eq)]
144#[derive(Clone, PartialEq, ::prost::Message)]
145pub struct TranslateResponse {
146    /// Array of the translations.
147    #[prost(message, repeated, tag = "1")]
148    pub translations: ::prost::alloc::vec::Vec<TranslatedText>,
149}
150#[allow(clippy::derive_partial_eq_without_eq)]
151#[derive(Clone, PartialEq, ::prost::Message)]
152pub struct DetectLanguageRequest {
153    /// The text to detect the language for.
154    #[prost(string, tag = "1")]
155    pub text: ::prost::alloc::string::String,
156    /// List of the most likely languages. These languages will be given preference when detecting the text language.
157    /// Most languages are specified in [ISO 639-1](<https://en.wikipedia.org/wiki/ISO_639-1>) format (for example, `` ru ``), but the field are not limited to it.
158    ///
159    /// To get the list of supported languages, use a \[TranslationService.ListLanguages\] request.
160    #[prost(string, repeated, tag = "2")]
161    pub language_code_hints: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
162    /// ID of the folder to which you have access.
163    /// Required for authorization with a user account (see \[yandex.cloud.iam.v1.UserAccount\] resource).
164    /// Don't specify this field if you make the request on behalf of a service account.
165    #[prost(string, tag = "3")]
166    pub folder_id: ::prost::alloc::string::String,
167}
168#[allow(clippy::derive_partial_eq_without_eq)]
169#[derive(Clone, PartialEq, ::prost::Message)]
170pub struct DetectLanguageResponse {
171    /// Most languages are specified in [ISO 639-1](<https://en.wikipedia.org/wiki/ISO_639-1>) format (for example, `` ru ``), but the field are not limited to it.
172    ///
173    /// To get the language name, use a \[TranslationService.ListLanguages\] request.
174    #[prost(string, tag = "1")]
175    pub language_code: ::prost::alloc::string::String,
176}
177#[allow(clippy::derive_partial_eq_without_eq)]
178#[derive(Clone, PartialEq, ::prost::Message)]
179pub struct ListLanguagesRequest {
180    /// ID of the folder to which you have access.
181    /// Required for authorization with a [user account](/docs/iam/concepts/users/accounts).
182    /// Do not specify this field if you make the request on behalf of a [service account](/docs/iam/concepts/users/accounts#sa).
183    #[prost(string, tag = "1")]
184    pub folder_id: ::prost::alloc::string::String,
185}
186#[allow(clippy::derive_partial_eq_without_eq)]
187#[derive(Clone, PartialEq, ::prost::Message)]
188pub struct ListLanguagesResponse {
189    /// List of supported languages.
190    #[prost(message, repeated, tag = "1")]
191    pub languages: ::prost::alloc::vec::Vec<Language>,
192}
193/// Generated client implementations.
194pub mod translation_service_client {
195    #![allow(unused_variables, dead_code, missing_docs, clippy::let_unit_value)]
196    use tonic::codegen::*;
197    use tonic::codegen::http::Uri;
198    /// A set of methods for the Translate service.
199    ///
200    /// Make sure you send your [authentication](/docs/translate/api-ref/authentication) credentials in the `Authorization` header of each request.
201    #[derive(Debug, Clone)]
202    pub struct TranslationServiceClient<T> {
203        inner: tonic::client::Grpc<T>,
204    }
205    impl TranslationServiceClient<tonic::transport::Channel> {
206        /// Attempt to create a new client by connecting to a given endpoint.
207        pub async fn connect<D>(dst: D) -> Result<Self, tonic::transport::Error>
208        where
209            D: TryInto<tonic::transport::Endpoint>,
210            D::Error: Into<StdError>,
211        {
212            let conn = tonic::transport::Endpoint::new(dst)?.connect().await?;
213            Ok(Self::new(conn))
214        }
215    }
216    impl<T> TranslationServiceClient<T>
217    where
218        T: tonic::client::GrpcService<tonic::body::BoxBody>,
219        T::Error: Into<StdError>,
220        T::ResponseBody: Body<Data = Bytes> + Send + 'static,
221        <T::ResponseBody as Body>::Error: Into<StdError> + Send,
222    {
223        pub fn new(inner: T) -> Self {
224            let inner = tonic::client::Grpc::new(inner);
225            Self { inner }
226        }
227        pub fn with_origin(inner: T, origin: Uri) -> Self {
228            let inner = tonic::client::Grpc::with_origin(inner, origin);
229            Self { inner }
230        }
231        pub fn with_interceptor<F>(
232            inner: T,
233            interceptor: F,
234        ) -> TranslationServiceClient<InterceptedService<T, F>>
235        where
236            F: tonic::service::Interceptor,
237            T::ResponseBody: Default,
238            T: tonic::codegen::Service<
239                http::Request<tonic::body::BoxBody>,
240                Response = http::Response<
241                    <T as tonic::client::GrpcService<tonic::body::BoxBody>>::ResponseBody,
242                >,
243            >,
244            <T as tonic::codegen::Service<
245                http::Request<tonic::body::BoxBody>,
246            >>::Error: Into<StdError> + Send + Sync,
247        {
248            TranslationServiceClient::new(InterceptedService::new(inner, interceptor))
249        }
250        /// Compress requests with the given encoding.
251        ///
252        /// This requires the server to support it otherwise it might respond with an
253        /// error.
254        #[must_use]
255        pub fn send_compressed(mut self, encoding: CompressionEncoding) -> Self {
256            self.inner = self.inner.send_compressed(encoding);
257            self
258        }
259        /// Enable decompressing responses.
260        #[must_use]
261        pub fn accept_compressed(mut self, encoding: CompressionEncoding) -> Self {
262            self.inner = self.inner.accept_compressed(encoding);
263            self
264        }
265        /// Limits the maximum size of a decoded message.
266        ///
267        /// Default: `4MB`
268        #[must_use]
269        pub fn max_decoding_message_size(mut self, limit: usize) -> Self {
270            self.inner = self.inner.max_decoding_message_size(limit);
271            self
272        }
273        /// Limits the maximum size of an encoded message.
274        ///
275        /// Default: `usize::MAX`
276        #[must_use]
277        pub fn max_encoding_message_size(mut self, limit: usize) -> Self {
278            self.inner = self.inner.max_encoding_message_size(limit);
279            self
280        }
281        /// Translates the text to the specified language.
282        pub async fn translate(
283            &mut self,
284            request: impl tonic::IntoRequest<super::TranslateRequest>,
285        ) -> std::result::Result<
286            tonic::Response<super::TranslateResponse>,
287            tonic::Status,
288        > {
289            self.inner
290                .ready()
291                .await
292                .map_err(|e| {
293                    tonic::Status::new(
294                        tonic::Code::Unknown,
295                        format!("Service was not ready: {}", e.into()),
296                    )
297                })?;
298            let codec = tonic::codec::ProstCodec::default();
299            let path = http::uri::PathAndQuery::from_static(
300                "/yandex.cloud.ai.translate.v2.TranslationService/Translate",
301            );
302            let mut req = request.into_request();
303            req.extensions_mut()
304                .insert(
305                    GrpcMethod::new(
306                        "yandex.cloud.ai.translate.v2.TranslationService",
307                        "Translate",
308                    ),
309                );
310            self.inner.unary(req, path, codec).await
311        }
312        /// Detects the language of the text.
313        pub async fn detect_language(
314            &mut self,
315            request: impl tonic::IntoRequest<super::DetectLanguageRequest>,
316        ) -> std::result::Result<
317            tonic::Response<super::DetectLanguageResponse>,
318            tonic::Status,
319        > {
320            self.inner
321                .ready()
322                .await
323                .map_err(|e| {
324                    tonic::Status::new(
325                        tonic::Code::Unknown,
326                        format!("Service was not ready: {}", e.into()),
327                    )
328                })?;
329            let codec = tonic::codec::ProstCodec::default();
330            let path = http::uri::PathAndQuery::from_static(
331                "/yandex.cloud.ai.translate.v2.TranslationService/DetectLanguage",
332            );
333            let mut req = request.into_request();
334            req.extensions_mut()
335                .insert(
336                    GrpcMethod::new(
337                        "yandex.cloud.ai.translate.v2.TranslationService",
338                        "DetectLanguage",
339                    ),
340                );
341            self.inner.unary(req, path, codec).await
342        }
343        /// Retrieves the list of supported languages.
344        pub async fn list_languages(
345            &mut self,
346            request: impl tonic::IntoRequest<super::ListLanguagesRequest>,
347        ) -> std::result::Result<
348            tonic::Response<super::ListLanguagesResponse>,
349            tonic::Status,
350        > {
351            self.inner
352                .ready()
353                .await
354                .map_err(|e| {
355                    tonic::Status::new(
356                        tonic::Code::Unknown,
357                        format!("Service was not ready: {}", e.into()),
358                    )
359                })?;
360            let codec = tonic::codec::ProstCodec::default();
361            let path = http::uri::PathAndQuery::from_static(
362                "/yandex.cloud.ai.translate.v2.TranslationService/ListLanguages",
363            );
364            let mut req = request.into_request();
365            req.extensions_mut()
366                .insert(
367                    GrpcMethod::new(
368                        "yandex.cloud.ai.translate.v2.TranslationService",
369                        "ListLanguages",
370                    ),
371                );
372            self.inner.unary(req, path, codec).await
373        }
374    }
375}