feat: return conversation id

This commit is contained in:
2026-05-11 19:04:14 +02:00
parent b5ef7e4881
commit c976db7063
3 changed files with 13 additions and 7 deletions
+9 -7
View File
@@ -126,7 +126,7 @@ pub async fn chat_completions(
) -> Result<Response, (axum::http::StatusCode, String)> {
tracing::debug!("Received /chat/completion with body {:?}", body);
if matches!(&auth, Auth::Jwt(_)) {
let conversation_id = if matches!(&auth, Auth::Jwt(_)) {
tracing::debug!(
"Is conversation_id existing: {:?}",
body.conversation_id.is_some()
@@ -137,7 +137,7 @@ pub async fn chat_completions(
.await
.map_err(crate::databases::postgres::errors::into_http_response)?;
let conversation_id = match &conversation_state {
let id = match &conversation_state {
ConversationState::Existing(uuid) => *uuid,
ConversationState::Created(uuid) => {
let conversation_id = *uuid;
@@ -161,8 +161,11 @@ pub async fn chat_completions(
}
};
tracing::debug!("Using conversation_id: {:?}", conversation_id);
}
tracing::debug!("Using conversation_id: {:?}", id);
Some(id)
} else {
None
};
if body.base.stream {
let stream = state
@@ -170,17 +173,16 @@ pub async fn chat_completions(
.chat_completions_stream(&body)
.await
.map_err(into_http_response)?;
Ok(Sse::new(stream)
.keep_alive(KeepAlive::default())
.into_response())
} else {
let response = state
let mut response = state
.ollama
.chat_completions(&body)
.await
.map_err(into_http_response)?;
response.conversation_id = conversation_id;
Ok(Json(response).into_response())
}
}