FI/SV/EN kielituki about valmis (testaamatta)
This commit is contained in:
@@ -851,23 +851,29 @@ async fn api_chat_completions(
|
||||
|
||||
let mut rx = state.stats_tx.subscribe();
|
||||
let _ = state.stats_tx.send(msg.to_string());
|
||||
|
||||
while let Ok(msg_str) = rx.recv().await {
|
||||
if let Ok(v) = serde_json::from_str::<serde_json::Value>(&msg_str) {
|
||||
if v["type"].as_str() == Some("llm_done") {
|
||||
if let Some(tid) = v["task_id"].as_str() {
|
||||
if tid == payload.task_id {
|
||||
let res = ChatCompletionResponse {
|
||||
response: v["response"].as_str().unwrap_or("").to_string(),
|
||||
model: v["model"].as_str().unwrap_or("").to_string(),
|
||||
tokens_generated: v["tokens_generated"].as_u64().unwrap_or(0),
|
||||
};
|
||||
return axum::Json(res).into_response();
|
||||
|
||||
let timeout = tokio::time::timeout(std::time::Duration::from_secs(120), async move {
|
||||
while let Ok(msg_str) = rx.recv().await {
|
||||
if let Ok(v) = serde_json::from_str::<serde_json::Value>(&msg_str) {
|
||||
if v["type"].as_str() == Some("llm_done") {
|
||||
if let Some(tid) = v["task_id"].as_str() {
|
||||
if tid == payload.task_id {
|
||||
return Some(ChatCompletionResponse {
|
||||
response: v["response"].as_str().unwrap_or("").to_string(),
|
||||
model: v["model"].as_str().unwrap_or("").to_string(),
|
||||
tokens_generated: v["tokens_generated"].as_u64().unwrap_or(0),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}).await;
|
||||
|
||||
match timeout {
|
||||
Ok(Some(res)) => axum::Json(res).into_response(),
|
||||
Ok(None) => (axum::http::StatusCode::INTERNAL_SERVER_ERROR, "Verkkovirhe: yhteys katkesi").into_response(),
|
||||
Err(_) => (axum::http::StatusCode::GATEWAY_TIMEOUT, "Aikakatkaisu: yksikään solmu ei vastannut 120s sisällä").into_response(),
|
||||
}
|
||||
|
||||
(axum::http::StatusCode::INTERNAL_SERVER_ERROR, "Network Error").into_response()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user