use crate::error::{Error, Result};
use serde::{Deserialize, Serialize};
pub struct ModalProvider {
#[allow(dead_code)]
token: String,
#[allow(dead_code)]
base_url: String,
}
impl ModalProvider {
pub fn new(token: &str) -> Self {
Self {
token: token.to_string(),
base_url: "https://modal.com/api".to_string(),
}
}
pub fn with_base_url(token: &str, base_url: &str) -> Self {
Self {
token: token.to_string(),
base_url: base_url.to_string(),
}
}
pub fn from_env() -> Result<Self> {
let token = std::env::var("MODAL_TOKEN")
.map_err(|_| Error::Configuration("MODAL_TOKEN not set".to_string()))?;
Ok(Self::new(&token))
}
pub async fn list_gpu_types(&self) -> Result<Vec<String>> {
Ok(vec![
"T4".to_string(),
"A10G".to_string(),
"L4".to_string(),
"A100-40GB".to_string(),
"A100-80GB".to_string(),
"H100".to_string(),
])
}
pub fn get_gpu_info(gpu_type: &str) -> Option<ModalGPUInfo> {
match gpu_type {
"T4" => Some(ModalGPUInfo {
name: gpu_type.to_string(),
memory_gb: 16,
price_per_hour: 0.59,
use_case: "Development and testing".to_string(),
}),
"A10G" => Some(ModalGPUInfo {
name: gpu_type.to_string(),
memory_gb: 24,
price_per_hour: 0.99,
use_case: "Production inference".to_string(),
}),
"L4" => Some(ModalGPUInfo {
name: gpu_type.to_string(),
memory_gb: 24,
price_per_hour: 0.80,
use_case: "Balanced workloads".to_string(),
}),
"A100-40GB" => Some(ModalGPUInfo {
name: gpu_type.to_string(),
memory_gb: 40,
price_per_hour: 2.49,
use_case: "Large model training".to_string(),
}),
"A100-80GB" => Some(ModalGPUInfo {
name: gpu_type.to_string(),
memory_gb: 80,
price_per_hour: 3.79,
use_case: "Very large models".to_string(),
}),
"H100" => Some(ModalGPUInfo {
name: gpu_type.to_string(),
memory_gb: 80,
price_per_hour: 4.99,
use_case: "State-of-the-art performance".to_string(),
}),
_ => None,
}
}
pub fn get_capabilities() -> ModalCapabilities {
ModalCapabilities {
name: "Modal".to_string(),
features: vec![
"serverless-gpu".to_string(),
"auto-scaling".to_string(),
"container-runtime".to_string(),
"web-endpoints".to_string(),
"cron-jobs".to_string(),
"secrets-management".to_string(),
],
languages: vec!["python".to_string()],
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModalGPUInfo {
pub name: String,
pub memory_gb: u32,
pub price_per_hour: f64,
pub use_case: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModalCapabilities {
pub name: String,
pub features: Vec<String>,
pub languages: Vec<String>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_provider_creation() {
let provider = ModalProvider::new("test-token");
assert!(provider.base_url.contains("modal.com"));
}
#[tokio::test]
async fn test_list_gpu_types() {
let provider = ModalProvider::new("test-token");
let gpus = provider.list_gpu_types().await.unwrap();
assert!(gpus.len() >= 5);
}
#[test]
fn test_gpu_info() {
let info = ModalProvider::get_gpu_info("H100").unwrap();
assert_eq!(info.memory_gb, 80);
}
}