models-dev 0.1.1

Simple Rust client for the models.dev API
Documentation
//! Traits for models.dev integration.
//!
//! This module defines the ModelsDevAware trait for integrating
//! with the models.dev API schema.

use crate::types::{Model, Provider};

/// A trait for types that can be integrated with models.dev provider information.
///
/// This trait allows provider implementations to declare their compatibility with
/// models.dev schema and convert from models.dev provider information.
/// 
/// # Example
/// 
/// ```rust
/// use models_dev::traits::ModelsDevAware;
/// use models_dev::types::{Provider, Model};
/// 
/// struct MyProvider {
///     // Provider-specific fields
/// }
/// 
/// impl ModelsDevAware for MyProvider {
///     fn supported_npm_packages() -> Vec<String> {
///         vec!["@ai-sdk/my-provider".to_string()]
///     }
///     
///     fn from_models_dev_info(provider: &Provider, model: Option<&Model>) -> Option<Self> {
        ///         // Check if this provider supports the NPM package
        ///         if !Self::supported_npm_packages().contains(&provider.npm) {
        ///             return None;
        ///         }
        ///         
        ///         // Create provider instance from models.dev info
        ///         Some(MyProvider {
        ///             // Initialize with provider and model data
        ///         })
        ///     }
/// }
/// ```
pub trait ModelsDevAware {
    /// The NPM package names that this provider supports.
    ///
    /// This should return a list of NPM package names that this provider
    /// implementation is compatible with. For example, an OpenAI provider
    /// might return `vec!["@ai-sdk/openai"]`.
    fn supported_npm_packages() -> Vec<String>;

    /// Create an instance of this type from models.dev provider information.
    ///
    /// This method should attempt to convert the models.dev provider information
    /// into an instance of the implementing type. It should return `None` if
    /// the provider information is not compatible with this implementation.
    ///
    /// # Arguments
    /// * `provider` - The provider information from models.dev API
    /// * `model` - Optional specific model information to use
    ///
    /// # Returns
    /// * `Some(Self)` if the provider information is compatible
    /// * `None` if the provider information is not compatible
    fn from_models_dev_info(provider: &Provider, model: Option<&Model>) -> Option<Self>
    where
        Self: Sized;
}