Skip to content

Commit 7ee29dc

Browse files
committed
chore: return model desc
1 parent d348361 commit 7ee29dc

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ impl AIModel {
6565
}
6666
}
6767

68-
const DEFAULT_MODEL_NAME: &str = "Auto";
68+
pub const DEFAULT_AI_MODEL_NAME: &str = "Auto";
6969
impl Default for AIModel {
7070
fn default() -> Self {
7171
Self {
72-
name: DEFAULT_MODEL_NAME.to_string(),
72+
name: DEFAULT_AI_MODEL_NAME.to_string(),
7373
is_local: false,
7474
desc: "".to_string(),
7575
}

frontend/rust-lib/flowy-ai/src/ai_manager.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use std::collections::HashMap;
1010

1111
use appflowy_plugin::manager::PluginManager;
1212
use dashmap::DashMap;
13-
use flowy_ai_pub::cloud::{AIModel, ChatCloudService, ChatSettings, UpdateChatParams};
13+
use flowy_ai_pub::cloud::{
14+
AIModel, ChatCloudService, ChatSettings, UpdateChatParams, DEFAULT_AI_MODEL_NAME,
15+
};
1416
use flowy_error::{FlowyError, FlowyResult};
1517
use flowy_sqlite::kv::KVStorePreferences;
1618
use flowy_sqlite::DBConnection;
@@ -275,6 +277,10 @@ impl AIManager {
275277
.cloud_service_wm
276278
.get_workspace_default_model(&workspace_id)
277279
.await?;
280+
281+
if model.is_empty() {
282+
return Ok(DEFAULT_AI_MODEL_NAME.to_string());
283+
}
278284
Ok(model)
279285
}
280286

@@ -387,6 +393,8 @@ impl AIManager {
387393
.map(|m| AIModel::from(m))
388394
.collect();
389395

396+
trace!("[Model Selection]: Available models: {:?}", models);
397+
390398
// If user enable local ai, then add local ai model to the list.
391399
if let Some(local_model) = self.local_ai.get_plugin_chat_model() {
392400
models.push(AIModel::local(local_model, "".to_string()));
@@ -400,13 +408,18 @@ impl AIManager {
400408
}
401409

402410
// Global active model is the model selected by the user in the workspace settings.
403-
let global_active_model = self
411+
let server_active_model = self
404412
.get_workspace_select_model()
405413
.await
406414
.map(|m| AIModel::server(m, "".to_string()))
407415
.unwrap_or_else(|_| AIModel::default());
408416

409-
let mut user_selected_model = global_active_model.clone();
417+
trace!(
418+
"[Model Selection] server active model: {:?}",
419+
server_active_model
420+
);
421+
422+
let mut user_selected_model = server_active_model.clone();
410423
let source_key = ai_available_models_key(&source);
411424

412425
// If source is provided, try to get the user-selected model from the store. User selected
@@ -419,6 +432,7 @@ impl AIManager {
419432
}
420433
},
421434
Some(model) => {
435+
trace!("[Model Selection] user select model: {:?}", model);
422436
user_selected_model = model;
423437
},
424438
}
@@ -428,7 +442,7 @@ impl AIManager {
428442
.iter()
429443
.find(|m| m.name == user_selected_model.name)
430444
.cloned()
431-
.or_else(|| Some(AIModel::from(global_active_model)));
445+
.or_else(|| Some(AIModel::from(server_active_model)));
432446

433447
// Update the stored preference if a different model is used.
434448
if let Some(ref active_model) = active_model {
@@ -439,6 +453,7 @@ impl AIManager {
439453
}
440454
}
441455

456+
trace!("[Model Selection] final active model: {:?}", active_model);
442457
let selected_model = AIModelPB::from(active_model.unwrap_or_default());
443458
Ok(AvailableModelsPB {
444459
models: models.into_iter().map(|m| m.into()).collect(),

0 commit comments

Comments
 (0)