#![warn(missing_docs, clippy::all, clippy::pedantic)]
#![allow(clippy::module_name_repetitions, clippy::must_use_candidate)]
#![doc = include_str!("../README.md")]
mod backend;
mod error;
mod config;
mod gguf;
mod model;
mod engine;
mod batch;
pub mod cache;
#[cfg(feature = "server")]
pub mod server;
pub use backend::{BackendInfo, BackendType, detect_best_backend, get_compiled_backend};
pub use batch::{BatchProcessor, BatchProcessorBuilder};
pub use config::{
CacheConfig, CacheConfigBuilder, EmbeddingConfig, EmbeddingConfigBuilder, EngineConfig,
EngineConfigBuilder, ModelConfig, ModelConfigBuilder, NormalizationMode, PoolingStrategy,
RerankResult, TruncateTokens,
};
pub use engine::{EmbeddingEngine, ModelInfo};
pub use error::{Error, Result};
pub use gguf::{
GGUFMetadata, clear_metadata_cache, extract_metadata as extract_gguf_metadata,
metadata_cache_size,
};
pub use model::EmbeddingModel;
use llama_cpp_2::LogOptions;
use std::sync::Once;
use tracing::{debug, info};
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
static INIT: Once = Once::new();
pub fn init() {
init_with_env_filter("info");
}
pub fn init_with_env_filter(filter: &str) {
use tracing_subscriber::{EnvFilter, fmt};
INIT.call_once(|| {
let env_filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(filter));
fmt().with_env_filter(env_filter).init();
llama_cpp_2::send_logs_to_tracing(LogOptions::default().with_logs_enabled(true));
info!("Embellama library initialized v{}", VERSION);
debug!("Debug logging enabled");
});
}
#[derive(Debug, Clone)]
pub struct VersionInfo {
pub version: &'static str,
pub rustc_version: &'static str,
pub target_arch: &'static str,
pub target_os: &'static str,
pub server_enabled: bool,
}
impl VersionInfo {
pub fn new() -> Self {
Self {
version: VERSION,
rustc_version: "unknown",
target_arch: std::env::consts::ARCH,
target_os: std::env::consts::OS,
server_enabled: cfg!(feature = "server"),
}
}
}
impl Default for VersionInfo {
fn default() -> Self {
Self::new()
}
}
impl std::fmt::Display for VersionInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Embellama v{}", self.version)?;
writeln!(f, " Target: {}-{}", self.target_arch, self.target_os)?;
writeln!(
f,
" Server: {}",
if self.server_enabled {
"enabled"
} else {
"disabled"
}
)?;
Ok(())
}
}
pub fn version_info() -> VersionInfo {
VersionInfo::new()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_version_info() {
let info = version_info();
assert_eq!(info.version, VERSION);
assert!(!info.target_arch.is_empty());
assert!(!info.target_os.is_empty());
}
#[test]
fn test_version_display() {
let info = version_info();
let display = info.to_string();
assert!(display.contains("Embellama"));
assert!(display.contains(VERSION));
}
}