chore: update response handle (#433)

This commit is contained in:
Medcl
2025-04-24 19:01:56 +08:00
committed by GitHub
parent 79b998da1b
commit 3826346fdf

View File

@@ -139,13 +139,10 @@ pub async fn new_chat<R: Runtime>(
.await
.map_err(|e| format!("Error sending message: {}", e))?;
let text = response
.text()
.await
.map_err(|e| format!("Failed to read response body: {}", e))?;
let body_text = common::http::get_response_body_text(response).await?;
let chat_response: GetResponse =
serde_json::from_str(&text).map_err(|e| format!("Failed to parse response JSON: {}", e))?;
serde_json::from_str(&body_text).map_err(|e| format!("Failed to parse response JSON: {}", e))?;
if chat_response.result != "created" {
return Err(format!("Unexpected result: {}", chat_response.result));
@@ -179,8 +176,8 @@ pub async fn send_message<R: Runtime>(
query_params,
Some(body),
)
.await
.map_err(|e| format!("Error cancel session: {}", e))?;
.await
.map_err(|e| format!("Error cancel session: {}", e))?;
common::http::get_response_body_text(response).await
}
@@ -222,8 +219,8 @@ pub async fn update_session_chat(
None,
Some(reqwest::Body::from(serde_json::to_string(&body).unwrap())),
)
.await
.map_err(|e| format!("Error updating session: {}", e))?;
.await
.map_err(|e| format!("Error updating session: {}", e))?;
Ok(response.status().is_success())
}