Struct DoubaoVisionSdk

Source
pub struct DoubaoVisionSdk { /* private fields */ }
Expand description

DoubaoVision client using wrapped Request.

Implementations§

Source§

impl DoubaoVisionSdk

Source

pub fn new(api_key: &str, base_url: &str, model: &str) -> Result<Self>

Source

pub fn new_with_default_model(api_key: &str, base_url: &str) -> Result<Self>

Create with default model “doubao-1-5-thinking-vision-pro-250428”

Examples found in repository?
examples/vision_example.rs (line 13)
7async fn main() -> Result<(), Box<dyn std::error::Error>> {
8    // Initialize the SDK with your API key and base URL
9    let api_key = "284423aa-0a73-4d7c-add5-31998942a3fd";
10    let base_url = "https://ark.cn-beijing.volces.com/api/v3";
11
12    // Create the DoubaoVision SDK
13    let sdk = DoubaoVisionSdk::new_with_default_model(&api_key, &base_url)?;
14
15    // Create the Vision Client
16    let client = VisionClient::new(sdk);
17
18    // Example 1: Simple image analysis
19    let image_url = "https://minio.cyydm.shop/testbucket/upload/zy/cbc7.jpg";
20    let prompt = "What's in this image?";
21
22    let input = VisionInput::single_image(prompt, image_url);
23    let output = client.infer(input).await?;
24
25    println!("Analysis result: {}", output.content);
26    if let Some(reasoning) = output.reasoning_content {
27        println!("Reasoning: {}", reasoning);
28    }
29
30    // // Example 2: Multi-turn conversation with system prompt
31    // let messages = vec![
32    //     DoubaoVisionMessage::system("You are a helpful image analysis assistant."),
33    //     DoubaoVisionMessage::with_image(
34    //         "Please describe this image in detail.",
35    //         "https://minio.cyydm.shop/testbucket/upload/zy/cbc7.jpg",
36    //     ),
37    // ];
38
39    // let input = VisionInput::new(messages);
40    // let output = client.infer(input).await?;
41
42    // println!("\nDetailed description: {}", output.content);
43
44    // // Example 3: Multiple images comparison
45    // let messages = vec![DoubaoVisionMessage::with_images(
46    //     "Compare these two images and highlight the differences.",
47    //     vec![
48    //         "https://minio.cyydm.shop/testbucket/upload/zy/cbc7.jpg".to_string(),
49    //         "https://minio.cyydm.shop/testbucket/upload/zy/cbc8.jpg".to_string(),
50    //     ],
51    // )];
52
53    // let input = VisionInput::new(messages);
54    // let output = client.infer(input).await?;
55
56    // println!("\nComparison result: {}", output.content);
57
58    // Print usage statistics if available
59    if let Some(usage) = output.usage {
60        println!("\nToken usage:");
61        println!("  Prompt tokens: {}", usage.prompt_tokens);
62        println!("  Completion tokens: {}", usage.completion_tokens);
63        println!("  Total tokens: {}", usage.total_tokens);
64        if let Some(reasoning_tokens) = usage.reasoning_tokens {
65            println!("  Reasoning tokens: {}", reasoning_tokens);
66        }
67    }
68
69    Ok(())
70}

Trait Implementations§

Source§

impl ModelSDK for DoubaoVisionSdk

Source§

fn chat_once<'life0, 'async_trait>( &'life0 self, input: Self::Input, ) -> Pin<Box<dyn Future<Output = Result<Self::Output>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a vision request and get full response.

Source§

fn chat_stream<'life0, 'async_trait>( &'life0 self, input: Self::Input, ) -> Pin<Box<dyn Future<Output = Result<ByteStream>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a vision request and get response stream (SSE).

Source§

type Input = VisionInput

Source§

type Output = VisionOutput

Auto Trait Implementations§

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<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,