feat: add models list endpoint

This commit is contained in:
2026-04-09 20:51:20 +02:00
parent b429f6256b
commit 8d26907c89
9 changed files with 467 additions and 43 deletions
+1
View File
@@ -0,0 +1 @@
pub mod v1;
+12
View File
@@ -0,0 +1,12 @@
pub mod models;
use crate::auth::middleware::auth_middleware;
use crate::routes::v1::models::list_models;
use crate::state::app_state::AppState;
use axum::{Router, middleware, routing::get};
pub fn router() -> Router<AppState> {
Router::new()
.route("/models", get(list_models))
.layer(middleware::from_fn(auth_middleware))
}
+16
View File
@@ -0,0 +1,16 @@
use axum::{Json, extract::State};
use serde_json::Value;
use crate::state::app_state::AppState;
pub async fn list_models(
State(state): State<AppState>,
) -> Result<Json<Value>, (axum::http::StatusCode, String)> {
match state.ollama.list_models().await {
Ok(models) => Ok(Json(models)),
Err(err) => Err((
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
err.to_string(),
)),
}
}