Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 20 additions & 9 deletions src/utils/openai.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<String>,
/// Anthropic human readable name.
pub display_name: Option<String>,
}

/// Response from the models endpoint.
Expand All @@ -15,7 +19,6 @@ pub(crate) struct Models {
pub data: Vec<Model>,
}

#[cfg(feature = "api-clients")]
pub(crate) async fn get_models(
client: &reqwest::Client,
url: &str,
Expand Down Expand Up @@ -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,
Expand All @@ -77,12 +79,21 @@ pub(crate) async fn get_bots(

let bots: Vec<Bot> = 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();

Expand Down