pub trait ModelsDevAware {
// Required methods
fn supported_npm_packages() -> Vec<String>;
fn from_models_dev_info(
provider: &Provider,
model: Option<&Model>,
) -> Option<Self>
where Self: Sized;
}Expand description
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
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
})
}
}Required Methods§
Sourcefn supported_npm_packages() -> Vec<String>
fn supported_npm_packages() -> Vec<String>
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"].
Sourcefn from_models_dev_info(
provider: &Provider,
model: Option<&Model>,
) -> Option<Self>where
Self: Sized,
fn from_models_dev_info(
provider: &Provider,
model: Option<&Model>,
) -> Option<Self>where
Self: Sized,
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 APImodel- Optional specific model information to use
§Returns
Some(Self)if the provider information is compatibleNoneif the provider information is not compatible
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.