Struct Client

Source
pub struct Client { /* private fields */ }

Implementations§

Source§

impl Client

Source

pub fn new() -> Self

Examples found in repository?
examples/text-generation.rs (line 29)
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let request = GenerationParamBuilder::default()
12        .model("qwen-turbo".to_string())
13        .input(
14            InputBuilder::default()
15                .messages(vec![MessageBuilder::default()
16                    .role("user")
17                    .content("你是谁")
18                    .build()
19                    .unwrap()])
20                .build()?,
21        )
22        .parameters(
23            ParametersBuilder::default()
24                .result_format("message")
25                .build()?,
26        )
27        .build()?;
28
29    let client = Client::new();
30
31    let response = client.generation().call(request).await?;
32    dbg!(response);
33    Ok(())
34}
More examples
Hide additional examples
examples/multimodal-generation-stream.rs (line 26)
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let request = MultiModalConversationParamBuilder::default()
12        .model("qwen-vl-max")
13        .input(InputBuilder::default().messages(vec![
14            MessageBuilder::default()
15            .role("user")
16            .contents(
17                vec![
18                    json!({"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"}),
19                    json!({"text": "这是什么?"})
20                ]
21            ).build()?
22        ]).build()?
23    )
24        .build()?;
25
26    let client = Client::new();
27
28    let response = client.multi_modal_conversation().call(request).await?;
29
30    dbg!(response);
31
32    Ok(())
33}
examples/multimodal-generation.rs (line 26)
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let request = MultiModalConversationParamBuilder::default()
12        .model("qwen-vl-max")
13        .input(InputBuilder::default().messages(vec![
14            MessageBuilder::default()
15            .role("user")
16            .contents(
17                vec![
18                    json!({"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"}),
19                    json!({"text": "这是什么?"})
20                ]
21            ).build()?
22        ]).build()?
23    )
24        .build()?;
25
26    let client = Client::new();
27
28    let response = client.multi_modal_conversation().call(request).await?;
29
30    dbg!(response);
31
32    Ok(())
33}
examples/text-embedding.rs (line 10)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let client = Client::new();
11    let input = EmbeddingsParamBuilder::default()
12        .model("text-embedding-v3")
13        .input(
14            EmbeddingsInputBuilder::default()
15                .texts(vec![
16                    "风急天高猿啸哀".into(),
17                    "渚清沙白鸟飞回".into(),
18                    "无边落木萧萧下".into(),
19                    "不尽长江滚滚来".into(),
20                ])
21                .build()?,
22        )
23        .parameters(
24            EmbeddingsParametersBuilder::default()
25                .dimension(1024)
26                .build()?,
27        )
28        .build()?;
29    let output = client.text_embeddings().call(input).await?;
30
31    dbg!(output);
32
33    Ok(())
34}
examples/qwen-mt.rs (line 34)
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let request = GenerationParamBuilder::default()
12        .model("qwen-mt-turbo".to_string())
13        .input(
14            InputBuilder::default()
15                .messages(vec![MessageBuilder::default()
16                    .role("user")
17                    .content("我看到这个视频后没有笑")
18                    .build()
19                    .unwrap()])
20                .build()?,
21        )
22        .parameters(
23            ParametersBuilder::default()
24                .translation_options(
25                    TranslationOptionsBuilder::default()
26                        .source_lang("Chinese")
27                        .target_lang("English")
28                        .build()?,
29                )
30                .build()?,
31        )
32        .build()?;
33
34    let client = Client::new();
35
36    let response = client.generation().call(request).await?;
37    dbg!(response);
38    Ok(())
39}
examples/text-generation-stream.rs (line 32)
11async fn main() -> Result<(), Box<dyn std::error::Error>> {
12    let request = GenerationParamBuilder::default()
13        .model("qwen-turbo".to_string())
14        .input(
15            InputBuilder::default()
16                .messages(vec![MessageBuilder::default()
17                    .role("user")
18                    .content("qwen 大模型系统是谁开发的?")
19                    .build()
20                    .unwrap()])
21                .build()?,
22        )
23        .stream(true)
24        .parameters(
25            ParametersBuilder::default()
26                .result_format("message")
27                .incremental_output(true)
28                .build()?,
29        )
30        .build()?;
31
32    let client = Client::new();
33
34    let mut stream = client.generation().call_stream(request).await?;
35    while let Some(response) = stream.next().await {
36        match response {
37            Ok(go) => go.output.choices.iter().for_each(|c| {
38                print!("{}", c.message.content);
39            }),
40            Err(e) => eprintln!("{}", e),
41        }
42    }
43    Ok(())
44}
Source

pub fn build( http_client: Client, config: Config, backoff: ExponentialBackoff, ) -> Self

Source

pub fn generation(&self) -> Generation<'_>

获取当前实例的生成(Generation)信息

此方法属于操作级别,用于创建一个Generation对象, 该对象表示当前实例的某一特定生成(代)信息

§Returns

返回一个Generation对象,用于表示当前实例的生成信息

Examples found in repository?
examples/text-generation.rs (line 31)
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let request = GenerationParamBuilder::default()
12        .model("qwen-turbo".to_string())
13        .input(
14            InputBuilder::default()
15                .messages(vec![MessageBuilder::default()
16                    .role("user")
17                    .content("你是谁")
18                    .build()
19                    .unwrap()])
20                .build()?,
21        )
22        .parameters(
23            ParametersBuilder::default()
24                .result_format("message")
25                .build()?,
26        )
27        .build()?;
28
29    let client = Client::new();
30
31    let response = client.generation().call(request).await?;
32    dbg!(response);
33    Ok(())
34}
More examples
Hide additional examples
examples/qwen-mt.rs (line 36)
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let request = GenerationParamBuilder::default()
12        .model("qwen-mt-turbo".to_string())
13        .input(
14            InputBuilder::default()
15                .messages(vec![MessageBuilder::default()
16                    .role("user")
17                    .content("我看到这个视频后没有笑")
18                    .build()
19                    .unwrap()])
20                .build()?,
21        )
22        .parameters(
23            ParametersBuilder::default()
24                .translation_options(
25                    TranslationOptionsBuilder::default()
26                        .source_lang("Chinese")
27                        .target_lang("English")
28                        .build()?,
29                )
30                .build()?,
31        )
32        .build()?;
33
34    let client = Client::new();
35
36    let response = client.generation().call(request).await?;
37    dbg!(response);
38    Ok(())
39}
examples/text-generation-stream.rs (line 34)
11async fn main() -> Result<(), Box<dyn std::error::Error>> {
12    let request = GenerationParamBuilder::default()
13        .model("qwen-turbo".to_string())
14        .input(
15            InputBuilder::default()
16                .messages(vec![MessageBuilder::default()
17                    .role("user")
18                    .content("qwen 大模型系统是谁开发的?")
19                    .build()
20                    .unwrap()])
21                .build()?,
22        )
23        .stream(true)
24        .parameters(
25            ParametersBuilder::default()
26                .result_format("message")
27                .incremental_output(true)
28                .build()?,
29        )
30        .build()?;
31
32    let client = Client::new();
33
34    let mut stream = client.generation().call_stream(request).await?;
35    while let Some(response) = stream.next().await {
36        match response {
37            Ok(go) => go.output.choices.iter().for_each(|c| {
38                print!("{}", c.message.content);
39            }),
40            Err(e) => eprintln!("{}", e),
41        }
42    }
43    Ok(())
44}
examples/qwen-mt-stream.rs (line 39)
11async fn main() -> Result<(), Box<dyn std::error::Error>> {
12    let request = GenerationParamBuilder::default()
13        .model("qwen-mt-turbo".to_string())
14        .input(
15            InputBuilder::default()
16                .messages(vec![MessageBuilder::default()
17                    .role("user")
18                    .content("我看到这个视频后没有笑")
19                    .build()
20                    .unwrap()])
21                .build()?,
22        )
23        .stream(true)
24        .parameters(
25            ParametersBuilder::default()
26                // .incremental_output(true) # Qwen-MT模型暂时不支持增量式流式输出,所以此设置无效
27                .translation_options(
28                    TranslationOptionsBuilder::default()
29                        .source_lang("Chinese")
30                        .target_lang("English")
31                        .build()?,
32                )
33                .build()?,
34        )
35        .build()?;
36
37    let client = Client::new();
38
39    let mut stream = client.generation().call_stream(request).await?;
40    while let Some(response) = stream.next().await {
41        match response {
42            Ok(go) => go.output.choices.iter().for_each(|c| {
43                println!("{}", c.message.content);
44            }),
45            Err(e) => eprintln!("{}", e),
46        }
47    }
48    Ok(())
49}
Source

pub fn multi_modal_conversation(&self) -> MultiModalConversation<'_>

启发多模态对话的功能

该函数提供了与多模态对话相关的操作入口 它创建并返回一个MultiModalConversation实例,用于执行多模态对话操作

§Returns

返回一个MultiModalConversation实例,用于进行多模态对话操作

Examples found in repository?
examples/multimodal-generation-stream.rs (line 28)
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let request = MultiModalConversationParamBuilder::default()
12        .model("qwen-vl-max")
13        .input(InputBuilder::default().messages(vec![
14            MessageBuilder::default()
15            .role("user")
16            .contents(
17                vec![
18                    json!({"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"}),
19                    json!({"text": "这是什么?"})
20                ]
21            ).build()?
22        ]).build()?
23    )
24        .build()?;
25
26    let client = Client::new();
27
28    let response = client.multi_modal_conversation().call(request).await?;
29
30    dbg!(response);
31
32    Ok(())
33}
More examples
Hide additional examples
examples/multimodal-generation.rs (line 28)
10async fn main() -> Result<(), Box<dyn std::error::Error>> {
11    let request = MultiModalConversationParamBuilder::default()
12        .model("qwen-vl-max")
13        .input(InputBuilder::default().messages(vec![
14            MessageBuilder::default()
15            .role("user")
16            .contents(
17                vec![
18                    json!({"image": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20241022/emyrja/dog_and_girl.jpeg"}),
19                    json!({"text": "这是什么?"})
20                ]
21            ).build()?
22        ]).build()?
23    )
24        .build()?;
25
26    let client = Client::new();
27
28    let response = client.multi_modal_conversation().call(request).await?;
29
30    dbg!(response);
31
32    Ok(())
33}
Source

pub fn text_embeddings(&self) -> Embeddings<'_>

获取文本嵌入表示

此函数提供了一个接口,用于将文本转换为嵌入表示 它利用当前实例的上下文来生成文本的嵌入表示

§返回值

返回一个Embeddings实例,该实例封装了文本嵌入相关的操作和数据 Embeddings类型提供了进一步处理文本数据的能力,如计算文本相似度或进行文本分类等

Examples found in repository?
examples/text-embedding.rs (line 29)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let client = Client::new();
11    let input = EmbeddingsParamBuilder::default()
12        .model("text-embedding-v3")
13        .input(
14            EmbeddingsInputBuilder::default()
15                .texts(vec![
16                    "风急天高猿啸哀".into(),
17                    "渚清沙白鸟飞回".into(),
18                    "无边落木萧萧下".into(),
19                    "不尽长江滚滚来".into(),
20                ])
21                .build()?,
22        )
23        .parameters(
24            EmbeddingsParametersBuilder::default()
25                .dimension(1024)
26                .build()?,
27        )
28        .build()?;
29    let output = client.text_embeddings().call(input).await?;
30
31    dbg!(output);
32
33    Ok(())
34}

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Client

Source§

fn default() -> Client

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Client

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T