chore: return no content (#523)

This commit is contained in:
Nathan.fooo 2024-05-05 10:52:56 +08:00 committed by GitHub
parent a9d49403ae
commit c115414f5a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 7 deletions

View File

@ -1019,14 +1019,27 @@ async fn summary_row_handler(
return Err(AppError::InvalidRequest("Identity data is not supported".to_string()).into());
},
SummarizeRowData::Content(content) => {
let text = state
.ai_client
.summarize_row(&content)
.await
.map_err(|err| AppError::InvalidRequest(err.to_string()))?
.text;
if content.is_empty() {
return Ok(
AppResponse::Ok()
.with_data(SummarizeRowResponse {
text: "No content".to_string(),
})
.into(),
);
}
let result = state.ai_client.summarize_row(&content).await;
let resp = match result {
Ok(resp) => SummarizeRowResponse { text: resp.text },
Err(err) => {
error!("Failed to summarize row: {:?}", err);
SummarizeRowResponse {
text: "No content".to_string(),
}
},
};
let resp = SummarizeRowResponse { text };
Ok(AppResponse::Ok().with_data(resp).into())
},
}