mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: AI translation in Database (#5515)
* chore: add tranlate field type * chore: integrate ai translate * chore: integrate client api * chore: implement UI
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
use anyhow::Error;
|
||||
use client_api::entity::ai_dto::{SummarizeRowData, SummarizeRowParams};
|
||||
use client_api::entity::ai_dto::{
|
||||
SummarizeRowData, SummarizeRowParams, TranslateRowData, TranslateRowParams,
|
||||
};
|
||||
use client_api::entity::QueryCollabResult::{Failed, Success};
|
||||
use client_api::entity::{QueryCollab, QueryCollabParams};
|
||||
use client_api::error::ErrorCode::RecordNotFound;
|
||||
@ -12,6 +14,7 @@ use tracing::{error, instrument};
|
||||
|
||||
use flowy_database_pub::cloud::{
|
||||
CollabDocStateByOid, DatabaseCloudService, DatabaseSnapshot, SummaryRowContent,
|
||||
TranslateRowContent, TranslateRowResponse,
|
||||
};
|
||||
use lib_infra::future::FutureResult;
|
||||
|
||||
@ -139,4 +142,26 @@ where
|
||||
Ok(data.text)
|
||||
})
|
||||
}
|
||||
|
||||
fn translate_database_row(
|
||||
&self,
|
||||
workspace_id: &str,
|
||||
translate_row: TranslateRowContent,
|
||||
language: &str,
|
||||
) -> FutureResult<TranslateRowResponse, Error> {
|
||||
let language = language.to_string();
|
||||
let workspace_id = workspace_id.to_string();
|
||||
let try_get_client = self.inner.try_get_client();
|
||||
FutureResult::new(async move {
|
||||
let data = TranslateRowData {
|
||||
cells: translate_row,
|
||||
language,
|
||||
include_header: false,
|
||||
};
|
||||
|
||||
let params = TranslateRowParams { workspace_id, data };
|
||||
let data = try_get_client?.translate_row(params).await?;
|
||||
Ok(data)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use yrs::{Any, MapPrelim};
|
||||
|
||||
use flowy_database_pub::cloud::{
|
||||
CollabDocStateByOid, DatabaseCloudService, DatabaseSnapshot, SummaryRowContent,
|
||||
TranslateRowContent, TranslateRowResponse,
|
||||
};
|
||||
use lib_infra::future::FutureResult;
|
||||
|
||||
@ -85,4 +86,14 @@ impl DatabaseCloudService for LocalServerDatabaseCloudServiceImpl {
|
||||
// TODO(lucas): local ai
|
||||
FutureResult::new(async move { Ok("".to_string()) })
|
||||
}
|
||||
|
||||
fn translate_database_row(
|
||||
&self,
|
||||
_workspace_id: &str,
|
||||
_translate_row: TranslateRowContent,
|
||||
_language: &str,
|
||||
) -> FutureResult<TranslateRowResponse, Error> {
|
||||
// TODO(lucas): local ai
|
||||
FutureResult::new(async move { Ok(TranslateRowResponse::default()) })
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use tokio::sync::oneshot::channel;
|
||||
|
||||
use flowy_database_pub::cloud::{
|
||||
CollabDocStateByOid, DatabaseCloudService, DatabaseSnapshot, SummaryRowContent,
|
||||
TranslateRowContent, TranslateRowResponse,
|
||||
};
|
||||
use lib_dispatch::prelude::af_spawn;
|
||||
use lib_infra::future::FutureResult;
|
||||
@ -105,4 +106,13 @@ where
|
||||
) -> FutureResult<String, Error> {
|
||||
FutureResult::new(async move { Ok("".to_string()) })
|
||||
}
|
||||
|
||||
fn translate_database_row(
|
||||
&self,
|
||||
_workspace_id: &str,
|
||||
_translate_row: TranslateRowContent,
|
||||
_language: &str,
|
||||
) -> FutureResult<TranslateRowResponse, Error> {
|
||||
FutureResult::new(async move { Ok(TranslateRowResponse::default()) })
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user