37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
use crate::openai;
|
|
use axum::Json;
|
|
use axum_extra::routing::TypedPath;
|
|
use itertools::iproduct;
|
|
use serde::Deserialize;
|
|
use strum::VariantArray;
|
|
|
|
#[derive(Deserialize, TypedPath)]
|
|
#[typed_path("/v1/models")]
|
|
pub struct V1ModelsPath;
|
|
|
|
#[tracing::instrument]
|
|
pub async fn list_models(_: V1ModelsPath) -> Json<openai::models::ListModelsResponse<String>> {
|
|
let shortcuts = super::chat::completions::Shortcut::VARIANTS.iter().cloned();
|
|
let reasoning_efforts = openai::chat::completion::ReasoningEffort::VARIANTS
|
|
.iter()
|
|
.cloned()
|
|
.map(Some)
|
|
.chain(None);
|
|
|
|
let models = iproduct!(shortcuts, reasoning_efforts).map(|(shortcut, reasoning)| {
|
|
openai::models::Model {
|
|
id: super::chat::completions::ShortcutAndMaybeReasoning(shortcut, reasoning)
|
|
.to_string(),
|
|
created: 0,
|
|
object: openai::models::ModelObject::Model,
|
|
owned_by: "nobody".into(),
|
|
shutdown_date: None,
|
|
}
|
|
});
|
|
|
|
Json(openai::models::ListModelsResponse {
|
|
data: models.collect(),
|
|
object: openai::models::ListObject::List,
|
|
})
|
|
}
|