feat: add proper typing for api
This commit is contained in:
+48
-48
@@ -18,61 +18,61 @@ 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<Value>,
|
||||
// ) -> Result<Response, (axum::http::StatusCode, String)> {
|
||||
// let wants_stream = body
|
||||
// .get("stream")
|
||||
// .and_then(|v| v.as_bool())
|
||||
// .unwrap_or(false);
|
||||
|
||||
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>,
|
||||
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 chat_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);
|
||||
|
||||
if wants_stream {
|
||||
let stream = state
|
||||
.ollama
|
||||
.chat_completions_stream(body)
|
||||
.await
|
||||
.map_err(ollama_err)?;
|
||||
// if wants_stream {
|
||||
// let stream = state
|
||||
// .ollama
|
||||
// .chat_completions_stream(body)
|
||||
// .await
|
||||
// .map_err(ollama_err)?;
|
||||
|
||||
Ok(Sse::new(stream)
|
||||
.keep_alive(KeepAlive::default())
|
||||
.into_response())
|
||||
} else {
|
||||
let response = state
|
||||
.ollama
|
||||
.chat_completions(body)
|
||||
.await
|
||||
.map_err(ollama_err)?;
|
||||
// Ok(Sse::new(stream)
|
||||
// .keep_alive(KeepAlive::default())
|
||||
// .into_response())
|
||||
// } else {
|
||||
// let response = state
|
||||
// .ollama
|
||||
// .chat_completions(body)
|
||||
// .await
|
||||
// .map_err(ollama_err)?;
|
||||
|
||||
Ok(Json(response).into_response())
|
||||
}
|
||||
}
|
||||
// Ok(Json(response).into_response())
|
||||
// }
|
||||
// }
|
||||
|
||||
fn ollama_err(e: OllamaError) -> (axum::http::StatusCode, String) {
|
||||
match e {
|
||||
|
||||
Reference in New Issue
Block a user