90 lines
2.5 KiB
Rust
90 lines
2.5 KiB
Rust
//! LLM Proxy Library
|
|
//!
|
|
//! This library provides the core functionality for the LLM proxy gateway,
|
|
//! including provider integration, token tracking, and API endpoints.
|
|
|
|
pub mod auth;
|
|
pub mod client;
|
|
pub mod config;
|
|
pub mod database;
|
|
pub mod dashboard;
|
|
pub mod errors;
|
|
pub mod logging;
|
|
pub mod models;
|
|
pub mod multimodal;
|
|
pub mod providers;
|
|
pub mod rate_limiting;
|
|
pub mod server;
|
|
pub mod state;
|
|
pub mod utils;
|
|
|
|
// Re-exports for convenience
|
|
pub use auth::*;
|
|
pub use config::*;
|
|
pub use database::*;
|
|
pub use errors::*;
|
|
pub use logging::*;
|
|
pub use models::*;
|
|
pub use providers::*;
|
|
pub use server::*;
|
|
pub use state::*;
|
|
|
|
/// Test utilities for integration testing
|
|
#[cfg(test)]
|
|
pub mod test_utils {
|
|
use std::sync::Arc;
|
|
|
|
use crate::{
|
|
state::AppState,
|
|
rate_limiting::RateLimitManager,
|
|
client::ClientManager,
|
|
providers::ProviderManager,
|
|
};
|
|
use sqlx::sqlite::SqlitePool;
|
|
|
|
/// Create a test application state
|
|
pub async fn create_test_state() -> Arc<AppState> {
|
|
// Create in-memory database
|
|
let pool = SqlitePool::connect("sqlite::memory:")
|
|
.await
|
|
.expect("Failed to create test database");
|
|
|
|
// Run migrations
|
|
crate::database::init(&crate::config::DatabaseConfig {
|
|
path: std::path::PathBuf::from(":memory:"),
|
|
max_connections: 5,
|
|
}).await.expect("Failed to initialize test database");
|
|
|
|
let rate_limit_manager = RateLimitManager::new(
|
|
crate::rate_limiting::RateLimiterConfig::default(),
|
|
crate::rate_limiting::CircuitBreakerConfig::default(),
|
|
);
|
|
|
|
let client_manager = Arc::new(ClientManager::new(pool.clone()));
|
|
|
|
// Create provider manager
|
|
let provider_manager = ProviderManager::new();
|
|
|
|
let model_registry = crate::models::registry::ModelRegistry {
|
|
providers: std::collections::HashMap::new(),
|
|
};
|
|
|
|
Arc::new(AppState {
|
|
provider_manager,
|
|
db_pool: pool.clone(),
|
|
rate_limit_manager: Arc::new(rate_limit_manager),
|
|
client_manager,
|
|
request_logger: Arc::new(crate::logging::RequestLogger::new(pool.clone())),
|
|
model_registry: Arc::new(model_registry),
|
|
})
|
|
}
|
|
|
|
/// Create a test HTTP client
|
|
pub fn create_test_client() -> reqwest::Client {
|
|
reqwest::Client::builder()
|
|
.timeout(std::time::Duration::from_secs(30))
|
|
.build()
|
|
.expect("Failed to create test HTTP client")
|
|
}
|
|
}
|