pub struct DoubaoVisionSdk { /* private fields */ }Expand description
DoubaoVision client using wrapped Request.
Implementations§
Source§impl DoubaoVisionSdk
impl DoubaoVisionSdk
pub fn new(api_key: &str, base_url: &str, model: &str) -> Result<Self>
Sourcepub fn new_with_default_model(api_key: &str, base_url: &str) -> Result<Self>
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
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,
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,
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).
type Input = VisionInput
type Output = VisionOutput
Auto Trait Implementations§
impl Freeze for DoubaoVisionSdk
impl !RefUnwindSafe for DoubaoVisionSdk
impl Send for DoubaoVisionSdk
impl Sync for DoubaoVisionSdk
impl Unpin for DoubaoVisionSdk
impl !UnwindSafe for DoubaoVisionSdk
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more