From 50ff40f9d1b0b4a22aff2c895b8f57f55f816d5a Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Tue, 4 Jun 2024 10:49:28 +0800 Subject: [PATCH] chore: add ai completoin scope (#599) * chore: add ai completoin scope * chore: fix ci to run test --- .github/workflows/integration_test.yml | 2 +- src/api/ai.rs | 2 +- src/api/chat.rs | 1 + src/application.rs | 2 ++ tests/ai_test/complete_text.rs | 2 +- tests/sql_test/chat_test.rs | 12 ++++++------ 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/integration_test.yml b/.github/workflows/integration_test.yml index e184228d..73f74191 100644 --- a/.github/workflows/integration_test.yml +++ b/.github/workflows/integration_test.yml @@ -63,7 +63,7 @@ jobs: matrix: include: - test_service: "appflowy_cloud" - test_cmd: "--workspace --exclude appflowy-history appflowy-ai-client" + test_cmd: "--workspace --exclude appflowy-history --exclude appflowy-ai-client" - test_service: "appflowy_history" test_cmd: "-p appflowy-history" steps: diff --git a/src/api/ai.rs b/src/api/ai.rs index 452da634..ae0becac 100644 --- a/src/api/ai.rs +++ b/src/api/ai.rs @@ -9,7 +9,7 @@ use shared_entity::dto::ai_dto::{ use shared_entity::response::{AppResponse, JsonAppResponse}; use tracing::{error, instrument}; -pub fn ai_tool_scope() -> Scope { +pub fn ai_completion_scope() -> Scope { web::scope("/api/ai/{workspace_id}") .service(web::resource("/complete_text").route(web::post().to(complete_text_handler))) .service(web::resource("/summarize_row").route(web::post().to(summarize_row_handler))) diff --git a/src/api/chat.rs b/src/api/chat.rs index c0ae4646..9cccc2d6 100644 --- a/src/api/chat.rs +++ b/src/api/chat.rs @@ -60,6 +60,7 @@ async fn delete_chat_handler( Ok(AppResponse::Ok().into()) } +#[instrument(level = "info", skip_all, err)] async fn create_chat_message_handler( state: Data, path: web::Path<(String, String)>, diff --git a/src/application.rs b/src/application.rs index 30e09844..6e5114e6 100644 --- a/src/application.rs +++ b/src/application.rs @@ -48,6 +48,7 @@ use std::time::Duration; use tokio::sync::{Mutex, RwLock}; use tonic_proto::history::history_client::HistoryClient; +use crate::api::ai::ai_completion_scope; use crate::api::search::search_scope; use tracing::{info, warn}; use workspace_access::WorkspaceAccessControlImpl; @@ -144,6 +145,7 @@ pub async fn run_actix_server( .service(ws_scope()) .service(file_storage_scope()) .service(chat_scope()) + .service(ai_completion_scope()) .service(history_scope()) .service(metrics_scope()) .service(search_scope()) diff --git a/tests/ai_test/complete_text.rs b/tests/ai_test/complete_text.rs index fbcfd5d3..f75df6d6 100644 --- a/tests/ai_test/complete_text.rs +++ b/tests/ai_test/complete_text.rs @@ -16,5 +16,5 @@ async fn improve_writing_test() { .completion_text(&workspace_id, params) .await .unwrap(); - assert!(resp.text.contains("hungry")); + assert!(!resp.text.is_empty()); } diff --git a/tests/sql_test/chat_test.rs b/tests/sql_test/chat_test.rs index 6cc5aa14..15a37693 100644 --- a/tests/sql_test/chat_test.rs +++ b/tests/sql_test/chat_test.rs @@ -108,9 +108,9 @@ async fn chat_message_crud_test(pool: PgPool) { .unwrap(); txn.commit().await.unwrap(); assert_eq!(result.messages.len(), 3); - assert_eq!(result.messages[0].message_id, 3); + assert_eq!(result.messages[0].message_id, 5); assert_eq!(result.messages[1].message_id, 4); - assert_eq!(result.messages[2].message_id, 5); + assert_eq!(result.messages[2].message_id, 3); assert!(result.has_more); } @@ -138,9 +138,9 @@ async fn chat_message_crud_test(pool: PgPool) { .unwrap(); txn.commit().await.unwrap(); assert_eq!(result_2.messages.len(), 3); - assert_eq!(result_2.messages[0].message_id, 1); + assert_eq!(result_2.messages[0].message_id, 3); assert_eq!(result_2.messages[1].message_id, 2); - assert_eq!(result_2.messages[2].message_id, 3); + assert_eq!(result_2.messages[2].message_id, 1); assert_eq!(result_2.total, 5); assert!(!result_2.has_more); } @@ -168,8 +168,8 @@ async fn chat_message_crud_test(pool: PgPool) { .unwrap(); txn.commit().await.unwrap(); assert_eq!(result_2.messages.len(), 2); - assert_eq!(result_2.messages[0].message_id, 4); - assert_eq!(result_2.messages[1].message_id, 5); + assert_eq!(result_2.messages[0].message_id, 5); + assert_eq!(result_2.messages[1].message_id, 4); assert_eq!(result_2.total, 5); assert!(!result_2.has_more); }