feat: strong typing for complete endpoints
This commit is contained in:
+20
-22
@@ -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>,
|
||||
|
||||
@@ -11,11 +11,12 @@ use axum::{Router, middleware, routing::get, routing::post};
|
||||
// }
|
||||
|
||||
pub fn protected_router() -> Router<AppState> {
|
||||
Router::new().route("/models", get(models::list_models))
|
||||
// .route("/completions", post(chat::completions))
|
||||
// .route("/chat/completions", post(chat::chat_completions))
|
||||
.route("/models/{model}/load", post(models::load_model))
|
||||
.route("/models/{model}/unload", post(models::unload_model))
|
||||
Router::new()
|
||||
.route("/models", get(models::list_models))
|
||||
.route("/completions", post(chat::completions))
|
||||
// .route("/chat/completions", post(chat::chat_completions))
|
||||
.route("/models/{model}/load", post(models::load_model))
|
||||
.route("/models/{model}/unload", post(models::unload_model))
|
||||
}
|
||||
|
||||
pub fn router() -> Router<AppState> {
|
||||
|
||||
@@ -37,7 +37,6 @@ pub async fn unload_model(
|
||||
State(state): State<AppState>,
|
||||
Path(model): Path<String>,
|
||||
) -> Result<Json<api::UnloadModelResponse>, (axum::http::StatusCode, String)> {
|
||||
|
||||
let response = state
|
||||
.ollama
|
||||
.unload_model(&model)
|
||||
|
||||
Reference in New Issue
Block a user