pub enum ModelSpec {
Name(ModelName),
Iden(ModelIden),
Target(ServiceTarget),
}Expand description
Specifies how to identify and resolve a model for API calls.
ModelSpec provides three levels of control over model resolution:
-
ModelSpec::Name: Just a model name string. The adapter kind is inferred from the name, and auth/endpoint are resolved via the client’s configured resolvers. -
ModelSpec::Iden: An explicitModelIdenwith adapter kind specified. Skips adapter inference but still resolves auth/endpoint via config. -
ModelSpec::Target: A completeServiceTargetwith endpoint, auth, and model. Used directly, only runs the service target resolver.
§Examples
use genai::adapter::AdapterKind;
use genai::resolver::{AuthData, Endpoint};
use genai::{ModelIden, ModelSpec, ServiceTarget};
// Using a string name (full inference)
let spec: ModelSpec = "gpt-4".into();
// Using an explicit ModelIden (skip adapter inference)
let spec: ModelSpec = ModelIden::new(AdapterKind::OpenAI, "gpt-4").into();
// Using a complete ServiceTarget (bypass all resolution)
let target = ServiceTarget {
endpoint: Endpoint::from_static("https://custom.api/v1/"),
auth: AuthData::from_env("CUSTOM_API_KEY"),
model: ModelIden::new(AdapterKind::OpenAI, "custom-model"),
};
let spec: ModelSpec = target.into();Variants§
Name(ModelName)
Model name - without or without model namespace
Iden(ModelIden)
Explicit ModelIden - skips adapter inference, still resolves auth/endpoint.
Target(ServiceTarget)
Complete ServiceTarget - used directly, bypasses model mapping and auth resolution
Implementations§
Source§impl ModelSpec
impl ModelSpec
Sourcepub fn from_static_name(name: &'static str) -> Self
pub fn from_static_name(name: &'static str) -> Self
Creates a ModelSpec::Name from a static str.
Sourcepub fn from_iden(model_iden: impl Into<ModelIden>) -> Self
pub fn from_iden(model_iden: impl Into<ModelIden>) -> Self
Creates a ModelSpec::Iden from a ModelIden
Sourcepub fn from_target(target: ServiceTarget) -> Self
pub fn from_target(target: ServiceTarget) -> Self
Creates a ModelSpec::Target from a complete service target.