use std::collections::VecDeque;
use std::sync::{Arc, Mutex};
use async_trait::async_trait;
use crate::{AiClient, ClientError, Conversation};
pub struct MockClient {
pub name: String,
pub model: String,
pub responses: Arc<Mutex<VecDeque<Result<String, ClientError>>>>,
}
impl MockClient {
pub fn new(name: &str, responses: Vec<Result<String, ClientError>>) -> Self {
Self {
name: name.to_string(),
model: "mock-model".to_string(),
responses: Arc::new(Mutex::new(VecDeque::from(responses))),
}
}
}
#[async_trait]
impl AiClient for MockClient {
async fn send_prompt(&self, _prompt: &str) -> Result<String, ClientError> {
self.responses
.lock()
.unwrap()
.pop_front()
.unwrap_or_else(|| Ok("mock response".to_string()))
}
async fn send_conversation(
&self,
_conversation: &Conversation,
) -> Result<String, ClientError> {
self.responses
.lock()
.unwrap()
.pop_front()
.unwrap_or_else(|| Ok("mock conversation response".to_string()))
}
fn supports_conversations(&self) -> bool {
true
}
fn supports_streaming(&self) -> bool {
false
}
fn name(&self) -> &str {
&self.name
}
fn model(&self) -> &str {
&self.model
}
}