Skip to content

Commit 529b5e5

Browse files
committed
refactor: Model select (#7875)
* refactor: model select * refactor: add test * fix: add source * fix: add source * chore: notify all unset source * chore: fix test
1 parent 4e2723f commit 529b5e5

File tree

17 files changed

+1196
-268
lines changed

17 files changed

+1196
-268
lines changed

frontend/appflowy_flutter/lib/workspace/application/settings/ai/settings_ai_bloc.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';
1111

1212
part 'settings_ai_bloc.freezed.dart';
1313

14-
const String aiModelsGlobalActiveModel = "ai_models_global_active_model";
14+
const String aiModelsGlobalActiveModel = "global_active_model";
1515

1616
class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {
1717
SettingsAIBloc(
@@ -75,9 +75,6 @@ class SettingsAIBloc extends Bloc<SettingsAIEvent, SettingsAIState> {
7575
);
7676
},
7777
selectModel: (AIModelPB model) async {
78-
if (!model.isLocal) {
79-
await _updateUserWorkspaceSetting(model: model.name);
80-
}
8178
await AIEventUpdateSelectedModel(
8279
UpdateSelectedModelPB(
8380
source: aiModelsGlobalActiveModel,

frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/setting_ai_view/model_selection.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class AIModelSelection extends StatelessWidget {
1717
@override
1818
Widget build(BuildContext context) {
1919
return BlocBuilder<SettingsAIBloc, SettingsAIState>(
20-
buildWhen: (previous, current) =>
21-
previous.availableModels != current.availableModels,
2220
builder: (context, state) {
2321
final models = state.availableModels?.models;
2422
if (models == null) {
@@ -44,7 +42,7 @@ class AIModelSelection extends StatelessWidget {
4442
),
4543
Flexible(
4644
child: SettingsDropdown<AIModelPB>(
47-
key: const Key('_AIModelSelection'),
45+
key: ValueKey(selectedModel.name),
4846
onChanged: (model) => context
4947
.read<SettingsAIBloc>()
5048
.add(SettingsAIEvent.selectModel(model)),

frontend/rust-lib/flowy-ai-pub/src/cloud.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ pub struct AIModel {
3333
pub desc: String,
3434
}
3535

36+
impl AIModel {
37+
/// Create a new model instance
38+
pub fn new(name: impl Into<String>, description: impl Into<String>, is_local: bool) -> Self {
39+
Self {
40+
name: name.into(),
41+
desc: description.into(),
42+
is_local,
43+
}
44+
}
45+
}
46+
3647
impl From<AvailableModel> for AIModel {
3748
fn from(value: AvailableModel) -> Self {
3849
let desc = value
@@ -175,4 +186,9 @@ pub trait ChatCloudService: Send + Sync + 'static {
175186

176187
async fn get_available_models(&self, workspace_id: &Uuid) -> Result<ModelList, FlowyError>;
177188
async fn get_workspace_default_model(&self, workspace_id: &Uuid) -> Result<String, FlowyError>;
189+
async fn set_workspace_default_model(
190+
&self,
191+
workspace_id: &Uuid,
192+
model: &str,
193+
) -> Result<(), FlowyError>;
178194
}

0 commit comments

Comments
 (0)