Skip to content

Commit

Permalink
chore: using env to control ai test
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy committed Aug 12, 2024
1 parent 7878a01 commit 0ea065b
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 112 deletions.
150 changes: 75 additions & 75 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ edition = "2021"
actix.workspace = true
actix-web.workspace = true
actix-http = { workspace = true, default-features = false, features = [
"openssl",
"compress-brotli",
"compress-gzip",
"openssl",
"compress-brotli",
"compress-gzip",
] }
actix-rt = "2.9.0"
actix-web-actors = { version = "4.3" }
Expand All @@ -27,31 +27,31 @@ serde_repr.workspace = true
serde.workspace = true

tokio = { workspace = true, features = [
"macros",
"rt-multi-thread",
"sync",
"fs",
"time",
"full",
"macros",
"rt-multi-thread",
"sync",
"fs",
"time",
"full",
] }
tokio-stream.workspace = true
tokio-util = { version = "0.7.10", features = ["io"] }
futures-util = { workspace = true, features = ["std", "io"] }
once_cell = "1.19.0"
chrono = { version = "0.4.37", features = [
"serde",
"clock",
"serde",
"clock",
], default-features = false }
derive_more = { version = "0.99" }
secrecy.workspace = true
rand = { version = "0.8", features = ["std_rng"] }
anyhow = "1.0.79"
thiserror = "1.0.56"
reqwest = { workspace = true, features = [
"json",
"rustls-tls",
"cookies",
"stream",
"json",
"rustls-tls",
"cookies",
"stream",
] }
unicode-segmentation = "1.10"
lazy_static.workspace = true
Expand All @@ -61,31 +61,31 @@ bytes = "1.5.0"
rcgen = { version = "0.10.0", features = ["pem", "x509-parser"] }
mime = "0.3.17"
aws-sdk-s3 = { version = "1.36.0", features = [
"behavior-version-latest",
"rt-tokio",
"behavior-version-latest",
"rt-tokio",
] }
aws-config = { version = "1.5.1", features = ["behavior-version-latest"] }
redis = { workspace = true, features = [
"json",
"tokio-comp",
"connection-manager",
"json",
"tokio-comp",
"connection-manager",
] }
tracing = { version = "0.1.40", features = ["log"] }
tracing-subscriber = { version = "0.3.18", features = [
"registry",
"env-filter",
"ansi",
"json",
"tracing-log",
"registry",
"env-filter",
"ansi",
"json",
"tracing-log",
] }
tracing-bunyan-formatter = "0.3.9"
sqlx = { workspace = true, default-features = false, features = [
"runtime-tokio-rustls",
"macros",
"postgres",
"uuid",
"chrono",
"migrate",
"runtime-tokio-rustls",
"macros",
"postgres",
"uuid",
"chrono",
"migrate",
] }
async-trait.workspace = true
prometheus-client.workspace = true
Expand Down Expand Up @@ -127,10 +127,10 @@ authentication.workspace = true
access-control.workspace = true
workspace-access.workspace = true
app-error = { workspace = true, features = [
"sqlx_error",
"actix_web_error",
"tokio_error",
"appflowy_ai_error",
"sqlx_error",
"actix_web_error",
"tokio_error",
"appflowy_ai_error",
] }
shared-entity = { path = "libs/shared-entity", features = ["cloud"] }
workspace-template = { workspace = true }
Expand All @@ -152,11 +152,11 @@ assert-json-diff = "2.0.2"
scraper = "0.17.1"
client-api-test = { path = "libs/client-api-test", features = ["collab-sync"] }
client-api = { path = "libs/client-api", features = [
"collab-sync",
"test_util",
"sync_verbose_log",
"test_fast_sync",
"enable_brotli",
"collab-sync",
"test_util",
"sync_verbose_log",
"test_fast_sync",
"enable_brotli",
] }
opener = "0.6.1"
image = "0.23.14"
Expand All @@ -175,37 +175,37 @@ path = "src/lib.rs"

[workspace]
members = [
# libs
"libs/snowflake",
"libs/collab-rt-entity",
"libs/database",
"libs/database-entity",
"libs/client-api",
"libs/infra",
"libs/shared-entity",
"libs/gotrue",
"libs/gotrue-entity",
"admin_frontend",
"libs/app-error",
"libs/workspace-access",
"libs/workspace-template",
"libs/encrypt",
"libs/authentication",
"libs/access-control",
"libs/collab-rt-protocol",
"libs/collab-stream",
"libs/client-websocket",
"libs/client-api-test",
"libs/wasm-test",
"libs/client-api-wasm",
"libs/appflowy-ai-client",
"libs/client-api-entity",
# services
"services/appflowy-history",
"services/appflowy-collaborate",
# xtask
"xtask",
"libs/tonic-proto",
# libs
"libs/snowflake",
"libs/collab-rt-entity",
"libs/database",
"libs/database-entity",
"libs/client-api",
"libs/infra",
"libs/shared-entity",
"libs/gotrue",
"libs/gotrue-entity",
"admin_frontend",
"libs/app-error",
"libs/workspace-access",
"libs/workspace-template",
"libs/encrypt",
"libs/authentication",
"libs/access-control",
"libs/collab-rt-protocol",
"libs/collab-stream",
"libs/client-websocket",
"libs/client-api-test",
"libs/wasm-test",
"libs/client-api-wasm",
"libs/appflowy-ai-client",
"libs/client-api-entity",
# services
"services/appflowy-history",
"services/appflowy-collaborate",
# xtask
"xtask",
"libs/tonic-proto",
]

[workspace.dependencies]
Expand Down Expand Up @@ -234,9 +234,9 @@ uuid = { version = "1.6.1", features = ["v4"] }
anyhow = "1.0.79"
actix = "0.13.3"
actix-web = { version = "4.5.1", default-features = false, features = [
"openssl",
"compress-brotli",
"compress-gzip",
"openssl",
"compress-brotli",
"compress-gzip",
] }
actix-http = { version = "3.6.0", default-features = false }
tokio = { version = "1.36.0", features = ["sync"] }
Expand Down Expand Up @@ -287,4 +287,4 @@ collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev

[features]
history = []
ai-test-enabled = []
ai-test-enabled = ["client-api-test/ai-test-enabled"]
1 change: 1 addition & 0 deletions deploy.env
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ APPFLOWY_AI_OPENAI_API_KEY=
APPFLOWY_AI_SERVER_PORT=5001
APPFLOWY_AI_SERVER_HOST=ai
APPFLOWY_AI_DATABASE_URL=postgresql+psycopg://postgres:password@postgres:5432/postgres
APPFLOWY_LOCAL_AI_TEST_ENABLED=false

# AppFlowy History
APPFLOWY_HISTORY_URL=http://localhost:50051
Expand Down
1 change: 1 addition & 0 deletions dev.env
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ APPFLOWY_AI_OPENAI_API_KEY=
APPFLOWY_AI_SERVER_PORT=5001
APPFLOWY_AI_SERVER_HOST=localhost
APPFLOWY_AI_DATABASE_URL=postgresql+psycopg://postgres:password@postgres:5432/postgres
APPFLOWY_LOCAL_AI_TEST_ENABLED=false

# AppFlowy History
APPFLOWY_HISTORY_URL=http://localhost:50051
Expand Down
15 changes: 13 additions & 2 deletions libs/appflowy-ai-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,19 @@ impl AppFlowyAIClient {
.into_data()
}

pub async fn get_local_ai_config(&self, platform: &str) -> Result<LocalAIConfig, AIError> {
let url = format!("{}/local_ai/config?platform={platform}", self.url);
pub async fn get_local_ai_config(
&self,
platform: &str,
app_version: Option<String>,
) -> Result<LocalAIConfig, AIError> {
// Start with the base URL including the platform parameter
let mut url = format!("{}/local_ai/config?platform={}", self.url, platform);

// If app_version is provided, append it as a query parameter
if let Some(version) = app_version {
url = format!("{}&app_version={}", url, version);
}

let resp = self.http_client(Method::GET, &url)?.send().await?;
AIResponse::<LocalAIConfig>::from_response(resp)
.await?
Expand Down
5 changes: 4 additions & 1 deletion libs/appflowy-ai-client/tests/chat_test/qa_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ async fn download_package_test() {
#[tokio::test]
async fn get_local_ai_config_test() {
let client = appflowy_ai_client();
let config = client.get_local_ai_config("macos").await.unwrap();
let config = client
.get_local_ai_config("macos", Some("0.6.10".to_string()))
.await
.unwrap();
assert!(!config.models.is_empty());

assert!(!config.models[0].embedding_model.download_url.is_empty());
Expand Down
3 changes: 2 additions & 1 deletion libs/client-api-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ web-sys = { version = "0.3", features = ["console"] }


[features]
collab-sync = ["client-api/collab-sync"]
collab-sync = ["client-api/collab-sync"]
ai-test-enabled = []
24 changes: 24 additions & 0 deletions libs/client-api-test/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use tracing::trace;
#[cfg(not(target_arch = "wasm32"))]
use {
std::sync::Once,
Expand All @@ -16,6 +17,29 @@ fn get_bool_from_env_var(env_var_name: &str) -> bool {
}
}

pub fn load_env() {
// load once
static START: Once = Once::new();
START.call_once(|| {
dotenvy::dotenv().ok();
});
}

pub fn local_ai_test_enabled() -> bool {
if cfg!(feature = "ai-test-enabled") {
return true;
}

load_env();

// local ai test is disable by default
let enabled = get_bool_from_env_var("APPFLOWY_LOCAL_AI_TEST_ENABLED");
if enabled {
trace!("Local AI test is enabled");
}
enabled
}

#[cfg(not(target_arch = "wasm32"))]
pub fn setup_log() {
if get_bool_from_env_var("DISABLE_CI_TEST_LOG") {
Expand Down
3 changes: 2 additions & 1 deletion libs/client-api-test/src/test_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{localhost_client_with_device_id, setup_log};
use crate::{load_env, localhost_client_with_device_id, setup_log};
use anyhow::{anyhow, Error};
use assert_json_diff::{
assert_json_eq, assert_json_include, assert_json_matches_no_panic, CompareMode, Config,
Expand Down Expand Up @@ -56,6 +56,7 @@ pub struct TestCollab {
}
impl TestClient {
pub async fn new(registered_user: User, start_ws_conn: bool) -> Self {
load_env();
setup_log();
let device_id = Uuid::new_v4().to_string();
Self::new_with_device_id(&device_id, registered_user, start_ws_conn).await
Expand Down
12 changes: 6 additions & 6 deletions libs/client-api/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ impl Client {
) -> Self {
let reqwest_client = reqwest::Client::new();
let client_version = Version::parse(client_id).unwrap_or_else(|_| {
warn!("Failed to parse client version, defaulting to 0.6.3");
Version::new(0, 6, 3)
warn!("Failed to parse client version, defaulting to 0.6.6");
Version::new(0, 6, 6)
});

// The latest version of appflowy frontend application is 0.6.3.
// Ensure the client version is at least 0.6.3. Just in case client passes a lower version.
let min_version = Version::new(0, 6, 3);
// The latest version of appflowy frontend application is 0.6.6.
// Ensure the client version is at least 0.6.6. Just in case client passes a lower version.
let min_version = Version::new(0, 6, 6);
let client_version = if client_version < min_version {
warn!("Client version is less than 0.6.3, setting it to 0.6.3");
warn!("Client version is less than 0.6.6, setting it to 0.6.6");
min_version
} else {
client_version
Expand Down
3 changes: 2 additions & 1 deletion libs/client-api/src/http_ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ impl Client {
workspace_id: &str,
platform: &str,
) -> Result<LocalAIConfig, AppResponseError> {
let client_version = self.client_version.to_string();
let url = format!(
"{}/api/ai/{}/local/config?platform={platform}",
"{}/api/ai/{}/local/config?platform={platform}&app_version={client_version}",
self.base_url, workspace_id
);
let resp = self
Expand Down
Loading

0 comments on commit 0ea065b

Please sign in to comment.