Skip to main content

aither_core/llm/
provider.rs

1use core::future::Future;
2
3use alloc::{string::String, vec::Vec};
4
5use crate::{LanguageModel, llm::model};
6
7/// Trait for AI service providers that can list and provide language models.
8pub trait LanguageModelProvider {
9    /// The type of language model this provider creates.
10    type Model: LanguageModel;
11    /// The error type returned by this provider.
12    type Error: core::error::Error;
13
14    /// Lists all available models from this provider.
15    fn list_models(&self) -> impl Future<Output = Result<Vec<model::Profile>, Self::Error>> + Send;
16
17    /// Gets a specific model by name from this provider.
18    fn get_model(
19        &self,
20        name: &str,
21    ) -> impl Future<Output = Result<Self::Model, Self::Error>> + Send;
22
23    /// Returns the provider's profile information.
24    fn profile() -> Profile;
25}
26
27/// Provider profile information.
28#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
29#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30pub struct Profile {
31    name: String,
32    description: String,
33}
34
35impl Profile {
36    /// Creates a new profile with the given name and description.
37    pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
38        Self {
39            name: name.into(),
40            description: description.into(),
41        }
42    }
43
44    /// Returns the provider's name.
45    #[must_use]
46    pub const fn name(&self) -> &str {
47        self.name.as_str()
48    }
49
50    /// Returns the provider's description.
51    #[must_use]
52    pub const fn description(&self) -> &str {
53        self.description.as_str()
54    }
55}