pub struct Model {
pub id: String,
pub name: Option<String>,
pub description: Option<String>,
pub type: Option<String>,
pub created_at: Option<u64>,
pub owned_by: Option<String>,
pub context_length: Option<u32>,
}Expand description
Represents a single model available from a provider.
This struct is designed to be flexible enough to accommodate the varying responses from different LLM providers while providing a common interface.
§Fields
id: The unique identifier for the model (required)name: A human-readable name for the modeldescription: A detailed description of the model’s capabilitiesr#type: The type of model (e.g., “chat”, “completion”, “embedding”)created_at: Timestamp when the model was createdowned_by: The organization or entity that owns the modelcontext_length: The maximum context window size for the model
§Example
use rig::model::Model;
// Create a model with just an ID
let model = Model::from_id("gpt-4");
// Create a model with ID and name
let model = Model::new("gpt-4", "GPT-4");
// Create a model with all fields
let model = Model {
id: "gpt-4".to_string(),
name: Some("GPT-4".to_string()),
description: Some("A large language model...".to_string()),
r#type: Some("chat".to_string()),
created_at: Some(1677610600),
owned_by: Some("openai".to_string()),
context_length: Some(8192),
};Fields§
§id: StringThe unique identifier for the model (required)
name: Option<String>A human-readable name for the model
description: Option<String>A detailed description of the model’s capabilities
type: Option<String>The type of model (e.g., “chat”, “completion”, “embedding”)
created_at: Option<u64>Timestamp when the model was created (Unix epoch)
owned_by: Option<String>The organization or entity that owns the model
context_length: Option<u32>The maximum context window size for the model
Implementations§
Source§impl Model
impl Model
Sourcepub fn display_name(&self) -> &str
pub fn display_name(&self) -> &str
Returns a reference to the model’s name, or the ID if no name is set.
This is useful for display purposes when you want to show the most human-readable identifier available.
§Example
use rig::model::Model;
let model_with_name = Model::new("gpt-4", "GPT-4");
assert_eq!(model_with_name.display_name(), "GPT-4");
let model_without_name = Model::from_id("gpt-4");
assert_eq!(model_without_name.display_name(), "gpt-4");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Model
impl<'de> Deserialize<'de> for Model
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Model, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Model, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Model
impl Serialize for Model
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Eq for Model
impl StructuralPartialEq for Model
Auto Trait Implementations§
impl Freeze for Model
impl RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl UnsafeUnpin for Model
impl UnwindSafe for Model
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.