async_dashscope/operation/
text2image.rs

1use crate::{Client, error::Result};
2pub use output::*;
3pub use param::*;
4
5mod output;
6mod param;
7
8const TEXT2IMAGE_PATH: &str = "/services/aigc/text2image/image-synthesis";
9
10pub struct Text2Image<'a> {
11    client: &'a Client,
12}
13
14impl<'a> Text2Image<'a> {
15    pub fn new(client: &'a Client) -> Self {
16        Self { client }
17    }
18
19    pub async fn call(&self, request: Text2imageParam) -> Result<Text2ImageOutput> {
20        // 检查参数
21        // let validators = check_model_parameters(&request.model);
22        // for valid in validators {
23        //     valid.validate(&request)?;
24        // }
25
26        let mut headers = self.client.config().headers();
27        headers.insert("X-DashScope-Async", "enable".parse().unwrap());
28
29        // 发送POST请求到生成服务,并等待结果
30        self.client
31            .post_with_headers(TEXT2IMAGE_PATH, request, headers)
32            .await
33    }
34}