Skip to content

Commit

Permalink
llamafile provider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zees-dev committed Feb 18, 2025
1 parent 4632754 commit 2d6d97b
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions crates/blockless-drivers/src/llm_driver/llamafile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,53 @@ impl Drop for LlamafileProvider {
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::str::FromStr;
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

fn init_test_logging() {
let _ = FmtSubscriber::builder()
.with_max_level(Level::DEBUG)
.with_test_writer()
.try_init();
}

#[tokio::test]
async fn test_llamafile_lifecycle() {
init_test_logging();

let mut provider = LlamafileProvider::new(SupportedModels::Llama321BInstruct(None));
provider
.initialize(&ProviderConfig::default())
.await
.unwrap();

let messages = vec![
Message {
role: "system".to_string(),
content: "You are a helpful assistant.".to_string(),
},
Message {
role: "user".to_string(),
content: "Hello!".to_string(),
},
];

let response = provider.chat(messages).await.unwrap();
info!("Chat response: {:?}", response);
assert!(!response.content.is_empty());
}

#[test]
fn test_model_parsing() {
assert!(SupportedModels::from_str("Llama-3.2-1B-Instruct").is_ok());
assert!(SupportedModels::from_str("Llama-3.2-1B-Instruct-Q6_K").is_ok());

assert!(SupportedModels::from_str("Llama-3.2-3B-Instruct").is_ok());
assert!(SupportedModels::from_str("Llama-3.2-3B-Instruct-Q6_K").is_ok());
assert!(SupportedModels::from_str("unsupported-model").is_err());
}
}

0 comments on commit 2d6d97b

Please sign in to comment.