async_dashscope/operation/image2image/
param.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3use crate::oss_util;
4#[derive(Debug, Clone, Builder, Serialize, Deserialize, PartialEq)]
5pub struct Image2imageParam {
6    #[builder(setter(into, strip_option))]
7    pub model: String,
8
9    pub input: Input,
10}
11
12impl Image2imageParam {
13    pub(crate) async fn upload_file_to_oss(
14        mut self,
15        api_key: &str,
16    ) -> Result<Self, crate::error::DashScopeError> {
17        let oss_url =
18            oss_util::upload_file_and_get_url(api_key, &self.model, &self.input.image_url).await?;
19
20        self.input.image_url = oss_url;
21
22        Ok(self)
23    }
24}
25
26#[derive(Debug, Clone, Builder, Serialize, Deserialize, PartialEq)]
27pub struct Input {
28    /// 图像的公网可访问的URL,支持 HTTP 或 HTTPS 协议。
29    ///
30    /// - 格式限制:JPG、JPEG、PNG、BMP、PNM、PPM、TIFF、WEBP
31    /// - 尺寸限制:图像的宽度和高度均需在15-8192像素范围内,宽高比在1:10至10:1范围内。
32    /// - 大小限制:不超过10MB
33    #[builder(setter(into))]
34    pub image_url: String,
35    /// 源语种。
36    ///
37    /// - 支持值:语种全称、语种编码或auto(自动检测),对大小写不敏感
38    /// - 限制:与target_lang不同,且至少有一项为中文或英文
39    /// - 示例:Chinese、en或auto
40    #[builder(setter(into))]
41    pub source_lang: String,
42    /// 目标语种。
43    ///
44    /// - 支持值:语种全称或语种编码,对大小写不敏感
45    /// - 限制:与source_lang不同,且至少有一项为中文或英文
46    /// - 示例:Chinese、en
47    #[builder(setter(into))]
48    pub target_lang: String,
49
50    #[builder(setter(into, strip_option))]
51    #[builder(default=None)]
52    pub ext: Option<Ext>,
53}
54
55#[derive(Debug, Clone, Builder, Serialize, Deserialize, PartialEq)]
56pub struct Ext {
57    /// 领域提示,为使译文风格更贴合特定领域,可以使用英文描述使用场景、译文风格等需求。
58    /// 为确保翻译效果,建议不超过200个英文单词。
59    #[builder(setter(into, strip_option))]
60    #[builder(default=None)]
61    domain_hint: Option<String>,
62
63    /// 配置敏感词,以在翻译前过滤图片中完全匹配的文本,对大小写敏感。
64    /// 敏感词的语种可与源语种不一致,支持全部的源语种和目标语种。为确保翻译效果,建议单次请求添加的敏感词不超过50个。
65    ///
66    /// 示例:["全场9折", "七天无理由退换"]
67    #[builder(setter(into, strip_option))]
68    #[builder(default=None)]
69    sensitives: Option<Vec<String>>,
70
71    /// 术语干预,为特定术语设定译文,以满足特定领域的翻译需求,术语对的语种需要与source_lang和target_lang对应。
72    #[builder(setter(into, strip_option))]
73    #[builder(default=None)]
74    terminologies: Option<Vec<Terminology>>,
75    #[builder(setter(into, strip_option))]
76    #[builder(default=None)]
77    config: Option<Config>,
78}
79
80#[derive(Debug, Clone, Builder, Serialize, Deserialize, PartialEq)]
81pub struct Terminology {
82    src: String,
83    tgt: String,
84}
85
86#[derive(Debug, Clone, Builder, Serialize, Deserialize, PartialEq)]
87pub struct Config {
88    /// 用于控制是否跳过主体检测,翻译图像中主体(如人物、商品、Logo)上的文字。
89    skip_img_segment: bool,
90}
91
92// impl Validator<Image2imageParam> for ModelValidator {
93//     fn validate<R: crate::operation::request::RequestTrait<P = Image2imageParam> + ?Sized>(
94//         &self,
95//         params: &R,
96//     ) -> crate::error::Result<()> {
97//         match self {
98//             ModelValidator::NotSupportResultFormatText => todo!(),
99//             ModelValidator::NotSupportEnableThinking => todo!(),
100//             ModelValidator::NotSupportToolCall => todo!(),
101//             ModelValidator::NotSupportJsonOutput => todo!(),
102//             ModelValidator::DimensionNotMatch => todo!(),
103//             _ => Ok(()),
104//         }
105//     }
106// }