llmkit 0.1.3

Production-grade LLM client - 100+ providers, 11,000+ models. Pure Rust.
Documentation
//! Oracle Cloud Infrastructure (OCI) Generative AI provider.
//!
//! Oracle OCI Generative AI provides access to various LLM models through Oracle's
//! cloud infrastructure. It offers enterprise-grade security, compliance, and integration
//! with other OCI services.
//!
//! # Features
//! - Multiple model families (Cohere, Meta Llama, Mistral)
//! - Native Chinese language support
//! - Dedicated cluster support for compliance
//! - Integration with OCI IAM for authentication
//! - Fine-tuning capabilities
//! - Cost optimization features

use serde::{Deserialize, Serialize};

use crate::error::{Error, Result};

/// Oracle OCI Generative AI provider
pub struct OracleOCIProvider {
    #[allow(dead_code)]
    api_key: String,
    #[allow(dead_code)]
    compartment_id: String,
}

impl OracleOCIProvider {
    /// Create a new Oracle OCI provider with API key and compartment ID
    pub fn new(api_key: &str, compartment_id: &str) -> Self {
        Self {
            api_key: api_key.to_string(),
            compartment_id: compartment_id.to_string(),
        }
    }

    /// Create from environment variables
    /// Requires `ORACLE_API_KEY` and `ORACLE_COMPARTMENT_ID`
    pub fn from_env() -> Result<Self> {
        let api_key = std::env::var("ORACLE_API_KEY").map_err(|_| {
            Error::Configuration("ORACLE_API_KEY environment variable not set".to_string())
        })?;
        let compartment_id = std::env::var("ORACLE_COMPARTMENT_ID").map_err(|_| {
            Error::Configuration("ORACLE_COMPARTMENT_ID environment variable not set".to_string())
        })?;
        Ok(Self::new(&api_key, &compartment_id))
    }

    /// Get list of available OCI Generative AI models
    pub async fn list_models(&self) -> Result<Vec<String>> {
        // Mock implementation
        Ok(vec![
            "cohere.command".to_string(),
            "cohere.command-light".to_string(),
            "cohere.summarize-xlarge".to_string(),
            "meta.llama-2-70b-chat".to_string(),
            "meta.llama-3-70b-instruct".to_string(),
            "mistral.mixtral-8x7b-instruct".to_string(),
        ])
    }

    /// Get model details
    pub fn get_model_info(model: &str) -> Option<OracleModelInfo> {
        match model {
            "cohere.command" => Some(OracleModelInfo {
                name: "cohere.command".to_string(),
                model_family: "Cohere".to_string(),
                context_window: 4096,
                supports_vision: false,
                supports_function_call: true,
                max_output_tokens: 4096,
                capabilities: vec!["text-generation".to_string(), "chat".to_string()],
            }),
            "cohere.command-light" => Some(OracleModelInfo {
                name: "cohere.command-light".to_string(),
                model_family: "Cohere".to_string(),
                context_window: 4096,
                supports_vision: false,
                supports_function_call: true,
                max_output_tokens: 2048,
                capabilities: vec!["text-generation".to_string(), "chat".to_string()],
            }),
            "cohere.summarize-xlarge" => Some(OracleModelInfo {
                name: "cohere.summarize-xlarge".to_string(),
                model_family: "Cohere".to_string(),
                context_window: 8192,
                supports_vision: false,
                supports_function_call: false,
                max_output_tokens: 4096,
                capabilities: vec!["summarization".to_string()],
            }),
            "meta.llama-2-70b-chat" => Some(OracleModelInfo {
                name: "meta.llama-2-70b-chat".to_string(),
                model_family: "Meta Llama".to_string(),
                context_window: 4096,
                supports_vision: false,
                supports_function_call: false,
                max_output_tokens: 4096,
                capabilities: vec!["chat".to_string()],
            }),
            "meta.llama-3-70b-instruct" => Some(OracleModelInfo {
                name: "meta.llama-3-70b-instruct".to_string(),
                model_family: "Meta Llama".to_string(),
                context_window: 8192,
                supports_vision: false,
                supports_function_call: true,
                max_output_tokens: 4096,
                capabilities: vec!["chat".to_string(), "instruction-following".to_string()],
            }),
            "mistral.mixtral-8x7b-instruct" => Some(OracleModelInfo {
                name: "mistral.mixtral-8x7b-instruct".to_string(),
                model_family: "Mistral".to_string(),
                context_window: 32768,
                supports_vision: false,
                supports_function_call: true,
                max_output_tokens: 4096,
                capabilities: vec!["chat".to_string(), "code-generation".to_string()],
            }),
            _ => None,
        }
    }

    /// Get inference endpoint configuration
    pub fn get_endpoint_config(endpoint_type: &str) -> Option<OracleEndpointConfig> {
        match endpoint_type {
            "shared" => Some(OracleEndpointConfig {
                endpoint_type: "shared".to_string(),
                availability: "production".to_string(),
                max_tokens_per_minute: 90000,
                max_requests_per_minute: 60,
                supports_batching: true,
            }),
            "dedicated" => Some(OracleEndpointConfig {
                endpoint_type: "dedicated".to_string(),
                availability: "enterprise".to_string(),
                max_tokens_per_minute: 500000,
                max_requests_per_minute: 1000,
                supports_batching: true,
            }),
            "on-premises" => Some(OracleEndpointConfig {
                endpoint_type: "on-premises".to_string(),
                availability: "customer-managed".to_string(),
                max_tokens_per_minute: 1000000,
                max_requests_per_minute: 5000,
                supports_batching: true,
            }),
            _ => None,
        }
    }
}

/// Oracle OCI model information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OracleModelInfo {
    /// Model name/ID
    pub name: String,
    /// Model family (Cohere, Meta Llama, Mistral, etc.)
    pub model_family: String,
    /// Context window size in tokens
    pub context_window: u32,
    /// Whether this model supports vision/images
    pub supports_vision: bool,
    /// Whether this model supports function calling
    pub supports_function_call: bool,
    /// Maximum output tokens
    pub max_output_tokens: u32,
    /// Specific capabilities
    pub capabilities: Vec<String>,
}

/// Oracle OCI endpoint configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OracleEndpointConfig {
    /// Endpoint type (shared, dedicated, on-premises)
    pub endpoint_type: String,
    /// Availability tier
    pub availability: String,
    /// Maximum tokens per minute
    pub max_tokens_per_minute: u32,
    /// Maximum requests per minute
    pub max_requests_per_minute: u32,
    /// Whether batching is supported
    pub supports_batching: bool,
}

/// Deployment type for Oracle OCI models
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default)]
pub enum DeploymentType {
    /// Shared infrastructure (cost-effective)
    #[default]
    Shared,
    /// Dedicated cluster (isolated performance)
    Dedicated,
    /// On-premises deployment
    OnPremises,
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_oracle_provider_creation() {
        let provider = OracleOCIProvider::new("test-key", "test-compartment");
        assert_eq!(provider.api_key, "test-key");
        assert_eq!(provider.compartment_id, "test-compartment");
    }

    #[tokio::test]
    async fn test_list_models() {
        let provider = OracleOCIProvider::new("test-key", "test-compartment");
        let models = provider.list_models().await.unwrap();
        assert!(!models.is_empty());
        assert!(models.contains(&"cohere.command".to_string()));
        assert!(models.contains(&"meta.llama-3-70b-instruct".to_string()));
    }

    #[test]
    fn test_get_model_info() {
        let info = OracleOCIProvider::get_model_info("cohere.command").unwrap();
        assert_eq!(info.name, "cohere.command");
        assert_eq!(info.model_family, "Cohere");
        assert!(info.supports_function_call);
        assert!(!info.supports_vision);
    }

    #[test]
    fn test_llama_model_info() {
        let info = OracleOCIProvider::get_model_info("meta.llama-3-70b-instruct").unwrap();
        assert_eq!(info.model_family, "Meta Llama");
        assert_eq!(info.context_window, 8192);
        assert!(info.supports_function_call);
    }

    #[test]
    fn test_mistral_model_info() {
        let info = OracleOCIProvider::get_model_info("mistral.mixtral-8x7b-instruct").unwrap();
        assert_eq!(info.model_family, "Mistral");
        assert!(info.supports_function_call);
        assert_eq!(info.context_window, 32768);
    }

    #[test]
    fn test_model_info_invalid() {
        let info = OracleOCIProvider::get_model_info("invalid-model");
        assert!(info.is_none());
    }

    #[test]
    fn test_get_endpoint_config() {
        let config = OracleOCIProvider::get_endpoint_config("shared").unwrap();
        assert_eq!(config.endpoint_type, "shared");
        assert_eq!(config.max_requests_per_minute, 60);
        assert!(config.supports_batching);
    }

    #[test]
    fn test_dedicated_endpoint_config() {
        let config = OracleOCIProvider::get_endpoint_config("dedicated").unwrap();
        assert_eq!(config.endpoint_type, "dedicated");
        assert!(config.max_tokens_per_minute > 100000);
        assert!(config.supports_batching);
    }

    #[test]
    fn test_endpoint_config_invalid() {
        let config = OracleOCIProvider::get_endpoint_config("invalid-type");
        assert!(config.is_none());
    }

    #[test]
    fn test_deployment_type_default() {
        assert_eq!(DeploymentType::default(), DeploymentType::Shared);
    }

    #[test]
    fn test_endpoint_capabilities() {
        let shared = OracleOCIProvider::get_endpoint_config("shared").unwrap();
        let dedicated = OracleOCIProvider::get_endpoint_config("dedicated").unwrap();

        assert!(shared.max_requests_per_minute < dedicated.max_requests_per_minute);
        assert!(shared.max_tokens_per_minute < dedicated.max_tokens_per_minute);
    }
}