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: display ai model desc and fix flashing when select model
Nathanff70595a15f7
diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/settings_ai_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/settings_ai_bloc.dartindex 1d50cde480..4383e0dbef 100644--- a/frontend/appflowy_flutter/lib/workspace/application/settings/ai/settings_ai_bloc.dart+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/ai/settings_ai_bloc.dart@@ -11,13 +11,15 @@ import 'package:freezed_annotation/freezed_annotation.dart';part 'settings_ai_bloc.freezed.dart';+const String aiModelsGlobalActiveModel = "ai_models_global_active_model";+class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {SettingsAIBloc(this.userProfile,this.workspaceId,) : _userListener = UserListener(userProfile: userProfile),_aiModelSwitchListener =- AIModelSwitchListener(objectId: "ai_models_global_active_model"),+ AIModelSwitchListener(objectId: aiModelsGlobalActiveModel),super(SettingsAIState(userProfile: userProfile,@@ -58,6 +60,7 @@ class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {},);_loadModelList();+ _loadUserWorkspaceSetting();},didReceiveUserProfile: (userProfile) {emit(state.copyWith(userProfile: userProfile));@@ -75,6 +78,12 @@ class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {if (!model.isLocal) {await _updateUserWorkspaceSetting(model: model.name);}+ await AIEventUpdateSelectedModel(+ UpdateSelectedModelPB(+ source: aiModelsGlobalActiveModel,+ selectedModel: model,+ ),+ ).send();},didLoadAISetting: (UseAISettingPB settings) {emit(@@ -135,6 +144,19 @@ class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {});});}++ void _loadUserWorkspaceSetting() {+ final payload = UserWorkspaceIdPB(workspaceId: workspaceId);+ UserEventGetWorkspaceSetting(payload).send().then((result) {+ result.fold((settings) {+ if (!isClosed) {+ add(SettingsAIEvent.didLoadAISetting(settings));+ }+ }, (err) {+ Log.error(err);+ });+ });+ }}@freezeddiff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/model_selection.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/model_selection.dartindex 2c4c4fa920..05db831e04 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/model_selection.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/model_selection.dart@@ -12,13 +12,19 @@ import 'package:flutter_bloc/flutter_bloc.dart';class AIModelSelection extends StatelessWidget {const AIModelSelection({super.key});+ static const double height = 49;@overrideWidget build(BuildContext context) {return BlocBuilder<SettingsAIBloc, SettingsAIState>(+ buildWhen: (previous, current) =>+ previous.availableModels != current.availableModels,builder: (context, state) {if (state.availableModels == null) {- return const SizedBox.shrink();+ return const SizedBox(+ // Using same height as SettingsDropdown to avoid layout shift+ height: height,+ );}return Padding(@@ -47,7 +53,7 @@ class AIModelSelection extends StatelessWidget {value: model,label: model.i18n,subLabel: model.desc,- maximumHeight: 49,+ maximumHeight: height,),).toList(),diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/settings_ai_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/settings_ai_view.dartindex 0fc1ef293c..efb969700e 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/settings_ai_view.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/settings_ai_view.dart@@ -44,22 +44,14 @@ class SettingsAIView extends StatelessWidget {return BlocProvider<SettingsAIBloc>(create: (_) => SettingsAIBloc(userProfile, workspaceId)..add(const SettingsAIEvent.started()),- child: BlocBuilder<SettingsAIBloc, SettingsAIState>(- builder: (context, state) {- final children = <Widget>[- const AIModelSelection(),- ];-- children.add(const _AISearchToggle(value: false));- children.add(const LocalAISetting());-- return SettingsBody(- title: LocaleKeys.settings_aiPage_title.tr(),- description:- LocaleKeys.settings_aiPage_keys_aiSettingsDescription.tr(),- children: children,- );- },+ child: SettingsBody(+ title: LocaleKeys.settings_aiPage_title.tr(),+ description: LocaleKeys.settings_aiPage_keys_aiSettingsDescription.tr(),+ children: [+ const AIModelSelection(),+ const _AISearchToggle(value: false),+ const LocalAISetting(),+ ],),);}diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dartindex 5165744627..2cf83276b4 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart@@ -141,7 +141,7 @@ class SettingsDialog extends StatelessWidget {case SettingsPage.ai:if (user.authenticator == AuthenticatorPB.AppFlowyCloud) {return SettingsAIView(- key: ValueKey(user.hashCode),+ key: ValueKey(workspaceId),userProfile: user,currentWorkspaceMemberRole: currentWorkspaceMemberRole,workspaceId: workspaceId,diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/shared/af_dropdown_menu_entry.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/shared/af_dropdown_menu_entry.dartindex 1d1e58626c..720f7793f2 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/shared/af_dropdown_menu_entry.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/shared/af_dropdown_menu_entry.dart@@ -9,7 +9,7 @@ DropdownMenuEntry<T> buildDropdownMenuEntry<T>(BuildContext context, {required T value,required String label,- String? subLabel,+ String subLabel = '',T? selectedValue,Widget? leadingWidget,Widget? trailingWidget,@@ -20,7 +20,7 @@ DropdownMenuEntry<T> buildDropdownMenuEntry<T>(? getGoogleFontSafely(fontFamily).fontFamily ?? defaultFontFamily: defaultFontFamily;Widget? labelWidget;- if (subLabel != null) {+ if (subLabel.isNotEmpty) {labelWidget = Column(crossAxisAlignment: CrossAxisAlignment.start,children: [diff --git a/frontend/rust-lib/build-tool/flowy-codegen/src/protobuf_file/mod.rs b/frontend/rust-lib/build-tool/flowy-codegen/src/protobuf_file/mod.rsindex 8baa78c096..677e7bcddf 100644--- a/frontend/rust-lib/build-tool/flowy-codegen/src/protobuf_file/mod.rs+++ b/frontend/rust-lib/build-tool/flowy-codegen/src/protobuf_file/mod.rs@@ -76,64 +76,64 @@ pub fn dart_gen(crate_name: &str) {}}-#[allow(unused_variables)]-fn ts_gen(crate_name: &str, dest_folder_name: &str, project: Project) {- // 1. generate the proto files to proto_file_dir- #[cfg(feature = "proto_gen")]- let proto_crates = gen_proto_files(crate_name);-- for proto_crate in proto_crates {- let mut proto_file_paths = vec![];- let mut file_names = vec![];- let proto_file_output_path = proto_crate- .proto_output_path()- .to_str()- .unwrap()- .to_string();- let protobuf_output_path = proto_crate- .protobuf_crate_path()- .to_str()- .unwrap()- .to_string();-- for (path, file_name) in WalkDir::new(&proto_file_output_path)- .into_iter()- .filter_map(|e| e.ok())- .map(|e| {- let path = e.path().to_str().unwrap().to_string();- let file_name = e.path().file_stem().unwrap().to_str().unwrap().to_string();- (path, file_name)- })- {- if path.ends_with(".proto") {- // https://stackoverflow.com/questions/49077147/how-can-i-force-build-rs-to-run-again-without-cleaning-my-whole-project- println!("cargo:rerun-if-changed={}", path);- proto_file_paths.push(path);- file_names.push(file_name);- }- }- let protoc_bin_path = protoc_bin_vendored::protoc_bin_path().unwrap();-- // 2. generate the protobuf files(Dart)- #[cfg(feature = "ts")]- generate_ts_protobuf_files(- dest_folder_name,- &proto_file_output_path,- &proto_file_paths,- &file_names,- &protoc_bin_path,- &project,- );-- // 3. generate the protobuf files(Rust)- generate_rust_protobuf_files(- &protoc_bin_path,- &proto_file_paths,- &proto_file_output_path,- &protobuf_output_path,- );- }-}+// #[allow(unused_variables)]+// fn ts_gen(crate_name: &str, dest_folder_name: &str, project: Project) {+// // 1. generate the proto files to proto_file_dir+// #[cfg(feature = "proto_gen")]+// let proto_crates = gen_proto_files(crate_name);+//+// for proto_crate in proto_crates {+// let mut proto_file_paths = vec![];+// let mut file_names = vec![];+// let proto_file_output_path = proto_crate+// .proto_output_path()+// .to_str()+// .unwrap()+// .to_string();+// let protobuf_output_path = proto_crate+// .protobuf_crate_path()+// .to_str()+// .unwrap()+// .to_string();+//+// for (path, file_name) in WalkDir::new(&proto_file_output_path)+// .into_iter()+// .filter_map(|e| e.ok())+// .map(|e| {+// let path = e.path().to_str().unwrap().to_string();+// let file_name = e.path().file_stem().unwrap().to_str().unwrap().to_string();+// (path, file_name)+// })+// {+// if path.ends_with(".proto") {+// // https://stackoverflow.com/questions/49077147/how-can-i-force-build-rs-to-run-again-without-cleaning-my-whole-project+// println!("cargo:rerun-if-changed={}", path);+// proto_file_paths.push(path);+// file_names.push(file_name);+// }+// }+// let protoc_bin_path = protoc_bin_vendored::protoc_bin_path().unwrap();+//+// // 2. generate the protobuf files(Dart)+// #[cfg(feature = "ts")]+// generate_ts_protobuf_files(+// dest_folder_name,+// &proto_file_output_path,+// &proto_file_paths,+// &file_names,+// &protoc_bin_path,+// &project,+// );+//+// // 3. generate the protobuf files(Rust)+// generate_rust_protobuf_files(+// &protoc_bin_path,+// &proto_file_paths,+// &proto_file_output_path,+// &protobuf_output_path,+// );+// }+// }fn generate_rust_protobuf_files(protoc_bin_path: &Path,