Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: find question message from reply message #1085

Merged
merged 5 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore: apply code suggestions to 2 files
  • Loading branch information
richardshiue committed Dec 18, 2024
commit 3e583315b31e2aa674548195ba786ca0014b9459
6 changes: 2 additions & 4 deletions libs/client-api/src/http_chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,15 @@ impl Client {
chat_id: &str,
answer_message_id: i64,
) -> Result<Option<ChatMessage>, AppResponseError> {
let mut url = format!(
let url = format!(
"{}/api/chat/{workspace_id}/{chat_id}/message/find_question",
self.base_url
);
let query_params = vec![("answer_message_id", answer_message_id.to_string())];

let query = serde_urlencoded::to_string(&query_params).unwrap();
url = format!("{}?{}", url, query);
let resp = self
.http_client_with_auth(Method::GET, &url)
.await?
richardshiue marked this conversation as resolved.
Show resolved Hide resolved
.query(&[("answer_message_id", answer_message_id)])
.send()
.await?;
AppResponse::<Option<ChatMessage>>::from_response(resp)
Expand Down
15 changes: 8 additions & 7 deletions src/api/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::biz::chat::ops::{
use crate::state::AppState;
use actix_web::web::{Data, Json};
use actix_web::{web, HttpRequest, HttpResponse, Scope};
use serde::Deserialize;

use crate::api::util::ai_model_from_header;
use app_error::AppError;
Expand Down Expand Up @@ -356,16 +357,11 @@ async fn get_chat_message_handler(
#[instrument(level = "debug", skip_all, err)]
async fn get_chat_question_message_handler(
path: web::Path<(String, String)>,
query: web::Query<HashMap<String, String>>,
query: web::Query<FindQuestionParams>,
state: Data<AppState>,
) -> actix_web::Result<JsonAppResponse<Option<ChatMessage>>> {
let answer_message_id = query
.get("answer_message_id")
.and_then(|s| s.parse::<i64>().ok())
.ok_or_else(|| AppError::InvalidRequest(serde_json::to_string(&query.0).unwrap()))?;

let (_workspace_id, chat_id) = path.into_inner();
let message = get_question_message(&state.pg_pool, &chat_id, answer_message_id).await?;
let message = get_question_message(&state.pg_pool, &chat_id, query.0.answer_message_id).await?;
Ok(AppResponse::Ok().with_data(message).into())
}

Expand Down Expand Up @@ -521,3 +517,8 @@ where
}
}
}

#[derive(Debug, Deserialize)]
struct FindQuestionParams {
answer_message_id: i64,
}
Loading