Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
chore: load from env command
Nathan22fed1bfbc44
diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_chat_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_chat_bloc.dartindex c254246213..14da82ec47 100644--- a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_chat_bloc.dart+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/local_ai_chat_bloc.dart@@ -45,7 +45,7 @@ class LocalAISettingPanelBloc);},updateAIState: (LocalAIPB pluginState) {- if (pluginState.isAppDownloaded) {+ if (pluginState.isExecutableReady) {emit(state.copyWith(runningState: pluginState.state,diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/plugin_state.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/plugin_state.dartindex 73fd0f2f42..9e979e9a5a 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/plugin_state.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/plugin_state.dart@@ -223,7 +223,7 @@ class _LackOfResource extends StatelessWidget {desc,maxLines: 3,),- )+ ),],);}diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex de94737ba9..3435fedbb6 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -851,7 +851,7 @@"localAILoading": "Local AI Chat Model is loading...","localAIStopped": "Local AI stopped","localAIRunning": "Local AI is running",- "localAIInitializing": "Local AI is initializing...",+ "localAIInitializing": "Local AI is initializing and may take a few minutes, depending on your device","failToLoadLocalAI": "Failed to start local AI","restartLocalAI": "Restart Local AI","disableLocalAITitle": "Disable local AI",diff --git a/frontend/rust-lib/Cargo.lock b/frontend/rust-lib/Cargo.lockindex be89f620d6..77b46fb6fb 100644--- a/frontend/rust-lib/Cargo.lock+++ b/frontend/rust-lib/Cargo.lock@@ -198,7 +198,7 @@ dependencies = [[[package]]name = "appflowy-local-ai"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-LocalAI?rev=ab121037b42c9b8f3e874598eb4ee72b29ef46b4#ab121037b42c9b8f3e874598eb4ee72b29ef46b4"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-LocalAI?rev=db15d1f1bb387acbb012979951b38e243f35972b#db15d1f1bb387acbb012979951b38e243f35972b"dependencies = ["anyhow","appflowy-plugin",@@ -218,7 +218,7 @@ dependencies = [[[package]]name = "appflowy-plugin"version = "0.1.0"-source = "git+https://github.com/AppFlowy-IO/AppFlowy-LocalAI?rev=ab121037b42c9b8f3e874598eb4ee72b29ef46b4#ab121037b42c9b8f3e874598eb4ee72b29ef46b4"+source = "git+https://github.com/AppFlowy-IO/AppFlowy-LocalAI?rev=db15d1f1bb387acbb012979951b38e243f35972b#db15d1f1bb387acbb012979951b38e243f35972b"dependencies = ["anyhow","cfg-if",diff --git a/frontend/rust-lib/Cargo.toml b/frontend/rust-lib/Cargo.tomlindex 0c70b37e09..7ed22256f4 100644--- a/frontend/rust-lib/Cargo.toml+++ b/frontend/rust-lib/Cargo.toml@@ -152,5 +152,5 @@ collab-importer = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFl# To update the commit ID, run:# scripts/tool/update_local_ai_rev.sh new_rev_id# ⚠️⚠️⚠️️-appflowy-local-ai = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-LocalAI", rev = "ab121037b42c9b8f3e874598eb4ee72b29ef46b4" }-appflowy-plugin = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-LocalAI", rev = "ab121037b42c9b8f3e874598eb4ee72b29ef46b4" }+appflowy-local-ai = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-LocalAI", rev = "db15d1f1bb387acbb012979951b38e243f35972b" }+appflowy-plugin = { version = "0.1", git = "https://github.com/AppFlowy-IO/AppFlowy-LocalAI", rev = "db15d1f1bb387acbb012979951b38e243f35972b" }diff --git a/frontend/rust-lib/flowy-ai/src/entities.rs b/frontend/rust-lib/flowy-ai/src/entities.rsindex f86cf4c743..06de096270 100644--- a/frontend/rust-lib/flowy-ai/src/entities.rs+++ b/frontend/rust-lib/flowy-ai/src/entities.rs@@ -448,7 +448,7 @@ pub enum PendingResourceTypePB {impl From<PendingResource> for PendingResourceTypePB {fn from(value: PendingResource) -> Self {match value {- PendingResource::LocalAIAppNotDownloaded { .. } => PendingResourceTypePB::LocalAIAppRes,+ PendingResource::PluginExecutableNotReady { .. } => PendingResourceTypePB::LocalAIAppRes,_ => PendingResourceTypePB::AIModel,}}@@ -483,7 +483,7 @@ pub struct LocalAIPB {pub enabled: bool,#[pb(index = 2)]- pub is_app_downloaded: bool,+ pub is_executable_ready: bool,#[pb(index = 3, one_of)]pub lack_of_resource: Option<String>,diff --git a/frontend/rust-lib/flowy-ai/src/local_ai/controller.rs b/frontend/rust-lib/flowy-ai/src/local_ai/controller.rsindex 4b52851534..7fe2c93dff 100644--- a/frontend/rust-lib/flowy-ai/src/local_ai/controller.rs+++ b/frontend/rust-lib/flowy-ai/src/local_ai/controller.rs@@ -92,7 +92,7 @@ impl LocalAIController {if let Ok(workspace_id) = cloned_user_service.workspace_id() {let key = local_ai_enabled_key(&workspace_id);info!("[AI Plugin] state: {:?}", state);- let ready = cloned_llm_res.is_app_downloaded();+ let ready = cloned_llm_res.is_plugin_ready();let lack_of_resource = cloned_llm_res.get_lack_of_resource().await;let new_state = RunningStatePB::from(state);@@ -103,7 +103,7 @@ impl LocalAIController {).payload(LocalAIPB {enabled,- is_app_downloaded: ready,+ is_executable_ready: ready,lack_of_resource,state: new_state,})@@ -254,7 +254,7 @@ impl LocalAIController {pub async fn get_local_ai_state(&self) -> LocalAIPB {let start = std::time::Instant::now();let enabled = self.is_enabled();- let is_app_downloaded = self.resource.is_app_downloaded();+ let is_app_downloaded = self.resource.is_plugin_ready();let state = self.ai_plugin.get_plugin_running_state();let lack_of_resource = self.resource.get_lack_of_resource().await;let elapsed = start.elapsed();@@ -265,7 +265,7 @@ impl LocalAIController {);LocalAIPB {enabled,- is_app_downloaded,+ is_executable_ready: is_app_downloaded,state: RunningStatePB::from(state),lack_of_resource,}@@ -439,7 +439,7 @@ impl LocalAIController {).payload(LocalAIPB {enabled,- is_app_downloaded: true,+ is_executable_ready: true,state: RunningStatePB::Stopped,lack_of_resource: None,})@@ -467,7 +467,7 @@ async fn initialize_ai_plugin().payload(LocalAIPB {enabled: true,- is_app_downloaded: true,+ is_executable_ready: true,state: RunningStatePB::ReadyToRun,lack_of_resource: lack_of_resource.clone(),})diff --git a/frontend/rust-lib/flowy-ai/src/local_ai/resource.rs b/frontend/rust-lib/flowy-ai/src/local_ai/resource.rsindex 1825ebea50..2bcdd8c65f 100644--- a/frontend/rust-lib/flowy-ai/src/local_ai/resource.rs+++ b/frontend/rust-lib/flowy-ai/src/local_ai/resource.rs@@ -5,7 +5,7 @@ use flowy_error::{ErrorCode, FlowyError, FlowyResult};use lib_infra::async_trait::async_trait;use crate::entities::LackOfAIResourcePB;-use crate::local_ai::watch::ollama_plugin_path;+use crate::local_ai::watch::{ollama_plugin_command_available, ollama_plugin_path};#[cfg(target_os = "macos")]use crate::local_ai::watch::{watch_offline_app, WatchContext};use crate::notification::{@@ -37,7 +37,7 @@ pub enum WatchDiskEvent {}pub enum PendingResource {- LocalAIAppNotDownloaded,+ PluginExecutableNotReady,OllamaServerNotReady,MissingModel(String),}@@ -45,7 +45,7 @@ pub enum PendingResource {impl PendingResource {pub fn desc(self) -> String {match self {- PendingResource::LocalAIAppNotDownloaded => "The Local AI app was not installed correctly. Please follow the instructions to install the Local AI application".to_string(),+ PendingResource::PluginExecutableNotReady => "The Local AI app was not installed correctly. Please follow the instructions to install the Local AI application".to_string(),PendingResource::OllamaServerNotReady => "Ollama is not ready. Please follow the instructions to install Ollama".to_string(),PendingResource::MissingModel(model) => format!("Cannot find the model: {}. Please use the ollama pull command to install the model", model),}@@ -123,8 +123,8 @@ impl LocalAIResourceController {}}- pub fn is_app_downloaded(&self) -> bool {- ollama_plugin_path().exists()+ pub fn is_plugin_ready(&self) -> bool {+ ollama_plugin_path().exists() || ollama_plugin_command_available()}pub async fn get_plugin_download_link(&self) -> FlowyResult<String> {@@ -164,8 +164,11 @@ impl LocalAIResourceController {let mut resources = vec![];let app_path = ollama_plugin_path();if !app_path.exists() {- trace!("[LLM Resource] offline app not found: {:?}", app_path);- resources.push(PendingResource::LocalAIAppNotDownloaded);+ if !ollama_plugin_command_available() {+ trace!("[LLM Resource] offline app not found: {:?}", app_path);+ resources.push(PendingResource::PluginExecutableNotReady);+ return Ok(resources);+ }}let setting = self.get_llm_setting();@@ -254,6 +257,7 @@ impl LocalAIResourceController {let mut config = OllamaPluginConfig::new(bin_path,+ "ollama_ai_plugin".to_string(),llm_setting.chat_model_name.clone(),llm_setting.embedding_model_name.clone(),Some(llm_setting.ollama_server_url.clone()),diff --git a/frontend/rust-lib/flowy-ai/src/local_ai/watch.rs b/frontend/rust-lib/flowy-ai/src/local_ai/watch.rsindex 11063e43d6..b9db41d663 100644--- a/frontend/rust-lib/flowy-ai/src/local_ai/watch.rs+++ b/frontend/rust-lib/flowy-ai/src/local_ai/watch.rs@@ -1,6 +1,7 @@use crate::local_ai::resource::WatchDiskEvent;use flowy_error::{FlowyError, FlowyResult};use std::path::PathBuf;+use std::process::Command;use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};use tracing::{error, trace};@@ -102,3 +103,18 @@ pub(crate) fn ollama_plugin_path() -> std::path::PathBuf {std::path::PathBuf::from(format!("/usr/local/bin/{}", offline_app))}}++pub(crate) fn ollama_plugin_command_available() -> bool {+ let command = if cfg!(windows) { "where" } else { "command" };+ let args = if cfg!(windows) {+ vec!["/c", "where", "ollama_ai_plugin"]+ } else {+ vec!["-v", "ollama_ai_plugin"]+ };++ let output = Command::new(command).args(args).output();+ match output {+ Ok(output) => !output.stdout.is_empty(),+ Err(_) => false,+ }+}