feat: create conversation

This commit is contained in:
2026-05-11 15:12:15 +02:00
parent 5aa7a6e7e1
commit 1bf4cf2ca3
6 changed files with 137 additions and 3 deletions
+20 -2
View File
@@ -1,12 +1,14 @@
use crate::middlewares::auth::middleware::Auth;
use axum::{
Json,
extract::State,
extract::{Extension, State},
response::{
IntoResponse, Response,
sse::{KeepAlive, Sse},
},
};
use crate::databases::postgres::chat::get_or_create_conversation;
use crate::dto::api;
use crate::providers::ollama::errors::into_http_response;
use crate::state::app_state::AppState;
@@ -115,9 +117,25 @@ pub async fn completions(
)]
pub async fn chat_completions(
State(state): State<AppState>,
Extension(auth): Extension<Auth>,
Json(body): Json<api::ChatRequest>,
) -> Result<Response, (axum::http::StatusCode, String)> {
tracing::debug!("Received /completion with body {:?}", body);
tracing::debug!("Received /chat/completion with body {:?}", body);
if matches!(&auth, Auth::Jwt(_)) {
tracing::debug!(
"Is conversation_id existing: {:?}",
body.conversation_id.is_some()
);
let conversation_id =
get_or_create_conversation(&state.postgres, body.conversation_id, auth.user_id())
.await
.map_err(crate::databases::postgres::errors::into_http_response)?;
tracing::debug!("Using conversation_id: {:?}", conversation_id);
}
if body.base.stream {
let stream = state
.ollama