use letta::client::{ClientConfig, LettaClient};
use letta::error::LettaResult;
use letta::types::*;
use serde_json::json;
use std::str::FromStr;
fn get_test_client() -> LettaResult<LettaClient> {
let config = ClientConfig::new("http://localhost:8283")?;
LettaClient::new(config)
}
#[tokio::test]
#[ignore = "Voice API requires OPENAI_API_KEY to be configured"]
async fn test_voice_chat_completions() -> LettaResult<()> {
let client = get_test_client()?;
let agents = client.agents().list(None).await?;
if agents.is_empty() {
println!("No agents available for voice test, creating one");
let request = CreateAgentRequest::builder()
.name("Voice Test Agent")
.agent_type(AgentType::MemGPT)
.model("letta/letta-free")
.embedding("letta/letta-free")
.build();
let agent = client.agents().create(request).await?;
println!("Created test agent: {}", agent.id);
let result = test_voice_endpoint(&client, &agent.id).await;
client.agents().delete(&agent.id).await?;
result
} else {
test_voice_endpoint(&client, &agents[0].id).await
}
}
async fn test_voice_endpoint(client: &LettaClient, agent_id: &LettaId) -> LettaResult<()> {
println!("Testing voice endpoint with agent: {}", agent_id);
let request = VoiceChatCompletionRequest {
data: json!({
"message": "Hello from voice test",
"voice_settings": {
"language": "en",
"speed": 1.0
}
}),
};
let response = client
.voice()
.create_voice_chat_completions(agent_id, request.clone(), None)
.await?;
println!(
"Voice response received without user_id: {:?}",
response.data
);
let response = client
.voice()
.create_voice_chat_completions(agent_id, request, Some("test-user-123"))
.await?;
println!("Voice response received: {:?}", response.data);
Ok(())
}
#[tokio::test]
async fn test_voice_with_invalid_agent() -> LettaResult<()> {
let client = get_test_client()?;
let fake_agent_id = LettaId::from_str("agent-00000000-0000-0000-0000-000000000000").unwrap();
let request = VoiceChatCompletionRequest {
data: json!({
"message": "Test message"
}),
};
let result = client
.voice()
.create_voice_chat_completions(&fake_agent_id, request, None)
.await;
match result {
Err(_) => {
println!("Expected error for invalid agent ID");
Ok(())
}
Ok(_) => {
panic!("Expected error but got success for invalid agent ID");
}
}
}