use open_agent::{AgentOptions, Client, ImageBlock, ImageDetail, Message};
#[tokio::test]
async fn test_send_message_with_image() {
let options = AgentOptions::builder()
.model("test-model")
.base_url("http://localhost:1234/v1")
.build()
.expect("Valid options");
let mut client = Client::new(options).expect("Valid client");
let msg = Message::user_with_image("What's in this image?", "https://example.com/photo.jpg")
.expect("Valid image URL");
let result = client.send_message(msg).await;
assert!(result.is_err());
assert_eq!(client.history().len(), 1);
let stored_msg = &client.history()[0];
assert_eq!(stored_msg.content.len(), 2); }
#[tokio::test]
async fn test_send_message_with_base64_image() {
let options = AgentOptions::builder()
.model("test-model")
.base_url("http://localhost:1234/v1")
.build()
.expect("Valid options");
let mut client = Client::new(options).expect("Valid client");
let base64_data = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
let msg = Message::user_with_base64_image("Analyze this image", base64_data, "image/png")
.expect("Valid base64");
let result = client.send_message(msg).await;
assert!(result.is_err()); assert_eq!(client.history().len(), 1);
let stored_msg = &client.history()[0];
assert_eq!(stored_msg.content.len(), 2); }
#[tokio::test]
async fn test_send_message_with_image_detail() {
let options = AgentOptions::builder()
.model("test-model")
.base_url("http://localhost:1234/v1")
.build()
.expect("Valid options");
let mut client = Client::new(options).expect("Valid client");
let msg = Message::user_with_image_detail(
"Analyze this diagram in detail",
"https://example.com/diagram.png",
ImageDetail::High,
)
.expect("Valid image URL");
let result = client.send_message(msg).await;
assert!(result.is_err()); assert_eq!(client.history().len(), 1);
use open_agent::ContentBlock;
let stored_msg = &client.history()[0];
match &stored_msg.content[1] {
ContentBlock::Image(img) => {
assert_eq!(img.detail(), ImageDetail::High);
}
_ => panic!("Expected Image block"),
}
}
#[tokio::test]
async fn test_send_message_with_custom_blocks() {
let options = AgentOptions::builder()
.model("test-model")
.base_url("http://localhost:1234/v1")
.build()
.expect("Valid options");
let mut client = Client::new(options).expect("Valid client");
use open_agent::{ContentBlock, MessageRole, TextBlock};
let image1 = ImageBlock::from_url("https://example.com/img1.jpg").expect("Valid URL");
let image2 = ImageBlock::from_url("https://example.com/img2.jpg").expect("Valid URL");
let msg = Message::new(
MessageRole::User,
vec![
ContentBlock::Text(TextBlock::new("Compare these images:")),
ContentBlock::Image(image1),
ContentBlock::Image(image2),
],
);
let result = client.send_message(msg).await;
assert!(result.is_err()); assert_eq!(client.history().len(), 1);
let stored_msg = &client.history()[0];
assert_eq!(stored_msg.content.len(), 3); }