feat: strong typing for complete endpoints

This commit is contained in:
2026-04-10 18:27:02 +02:00
parent 562d154480
commit d5856557b4
9 changed files with 609 additions and 158 deletions
+20 -22
View File
@@ -8,6 +8,7 @@ use axum::{
};
use serde_json::Value;
use crate::dto::api;
use crate::errors::OllamaError;
use crate::state::app_state::AppState;
@@ -18,31 +19,28 @@ use crate::state::app_state::AppState;
(status = 200, description = "Chat completion", body = Value),
)
)]
// pub async fn completions(
// State(state): State<AppState>,
// Json(body): Json<Value>,
// ) -> Result<Response, (axum::http::StatusCode, String)> {
// let wants_stream = body
// .get("stream")
// .and_then(|v| v.as_bool())
// .unwrap_or(false);
pub async fn completions(
State(state): State<AppState>,
Json(body): Json<api::CompletionRequest>,
) -> Result<Response, (axum::http::StatusCode, String)> {
let wants_stream = body.base.stream;
// if wants_stream {
// let stream = state
// .ollama
// .completions_stream(body)
// .await
// .map_err(ollama_err)?;
if wants_stream {
let stream = state
.ollama
.completions_stream(&body)
.await
.map_err(ollama_err)?;
// Ok(Sse::new(stream)
// .keep_alive(KeepAlive::default())
// .into_response())
// } else {
// let response = state.ollama.completions(body).await.map_err(ollama_err)?;
Ok(Sse::new(stream)
.keep_alive(KeepAlive::default())
.into_response())
} else {
let response = state.ollama.completions(&body).await.map_err(ollama_err)?;
// Ok(Json(response).into_response())
// }
// }
Ok(Json(response).into_response())
}
}
// pub async fn chat_completions(
// State(state): State<AppState>,