diff --git a/src/utils.rs b/src/utils.rs index 973fa70..b3937f7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -3,6 +3,7 @@ pub mod asynchronous; #[cfg(feature = "http")] pub mod http; +#[cfg(feature = "api-clients")] pub(crate) mod openai; pub(crate) mod platform; pub(crate) mod serde; diff --git a/src/utils/openai.rs b/src/utils/openai.rs index 3f8b7d1..7d86f8d 100644 --- a/src/utils/openai.rs +++ b/src/utils/openai.rs @@ -1,4 +1,4 @@ -//! Shared definitions and utilities for the OpenAI spec. +//! Shared definitions and utilities for the OpenAI spec (and extensions). use crate::protocol::*; use serde::Deserialize; @@ -7,6 +7,10 @@ use serde::Deserialize; #[derive(Clone, Debug, Deserialize, PartialEq)] pub(crate) struct Model { pub id: String, + /// OpenRouter human readable name. + pub name: Option, + /// Anthropic human readable name. + pub display_name: Option, } /// Response from the models endpoint. @@ -15,7 +19,6 @@ pub(crate) struct Models { pub data: Vec, } -#[cfg(feature = "api-clients")] pub(crate) async fn get_models( client: &reqwest::Client, url: &str, @@ -66,7 +69,6 @@ pub(crate) async fn get_models( Ok(models.data) } -#[cfg(feature = "api-clients")] pub(crate) async fn get_bots( client: &reqwest::Client, url: &str, @@ -77,12 +79,21 @@ pub(crate) async fn get_bots( let bots: Vec = models .iter() - .map(|m| Bot { - id: BotId::new(&m.id), - name: m.id.clone(), - avatar: EntityAvatar::from_first_grapheme(&m.id.to_uppercase()) - .unwrap_or_else(|| EntityAvatar::Text("?".into())), - capabilities: capabilities.clone(), + .map(|m| { + let name = m + .name + .as_ref() + .or(m.display_name.as_ref()) + .cloned() + .unwrap_or_else(|| m.id.clone()); + + Bot { + id: BotId::new(&m.id), + name, + avatar: EntityAvatar::from_first_grapheme(&m.id.to_uppercase()) + .unwrap_or_else(|| EntityAvatar::Text("?".into())), + capabilities: capabilities.clone(), + } }) .collect();