Skip to content

Commit

Permalink
details
Browse files Browse the repository at this point in the history
  • Loading branch information
noxware committed Aug 9, 2024
1 parent 68e52f4 commit f468606
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 93 deletions.
2 changes: 1 addition & 1 deletion src/chat/chat_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ impl ChatPanel {
} else if store.chats.loaded_model.is_none() {
State::NoModelSelected
} else {
let is_loading = store.get_currently_loading_model().is_some();
let is_loading = store.chats.model_loader.is_loading();

store.chats.get_current_chat().map_or(
State::ModelSelectedWithEmptyChat { is_loading },
Expand Down
15 changes: 7 additions & 8 deletions src/chat/model_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::{
shared::{actions::ChatAction, utils::format_model_size},
};
use makepad_widgets::*;
use moxin_protocol::data::{File, Model};

use super::{
model_selector_list::{ModelSelectorAction, ModelSelectorListWidgetExt},
Expand Down Expand Up @@ -312,7 +311,7 @@ impl ModelSelector {
}

fn update_loading_model_state(&mut self, cx: &mut Cx, store: &Store) {
if store.get_currently_loading_model().is_some() {
if store.chats.model_loader.is_loading() {
self.model_selector_loading(id!(loading))
.show_and_animate(cx);
} else {
Expand Down Expand Up @@ -361,8 +360,8 @@ impl ModelSelector {
_ => false,
};

let text_enabled_color = hex_rgb_to_vec4_color(0x000000);
let text_disabled_color = hex_rgb_to_vec4_color(0x667085);
let text_enabled_color = hex_rgb_color(0x000000);
let text_disabled_color = hex_rgb_color(0x667085);

let text_color = if is_loaded_file {
text_enabled_color
Expand Down Expand Up @@ -423,17 +422,17 @@ fn options_to_display(store: &Store) -> bool {
}

fn no_active_model(store: &Store) -> bool {
store.get_loaded_downloaded_file().is_none() && store.get_currently_loading_model().is_none()
store.get_loaded_downloaded_file().is_none() && store.get_loading_file().is_none()
}

fn rgb_to_vec4_color(r: u8, g: u8, b: u8) -> Vec4 {
fn rgb_color(r: u8, g: u8, b: u8) -> Vec4 {
vec4(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0, 1.0)
}

fn hex_rgb_to_vec4_color(hex: u32) -> Vec4 {
fn hex_rgb_color(hex: u32) -> Vec4 {
let r = ((hex >> 16) & 0xFF) as u8;
let g = ((hex >> 8) & 0xFF) as u8;
let b = (hex & 0xFF) as u8;

rgb_to_vec4_color(r, g, b)
rgb_color(r, g, b)
}
32 changes: 0 additions & 32 deletions src/data/chats/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@ pub struct Chats {
chats_dir: PathBuf,
}

/// Posible states in which a model can be at runtime.
pub enum ModelStatus {
Unloaded,
Loading,
Loaded,
Failed,
}

impl Chats {
pub fn new(backend: Rc<Backend>) -> Self {
Self {
Expand All @@ -44,30 +36,6 @@ impl Chats {
}
}

/// Obtain the loading status for the model asigned to the current chat.
/// If there is no chat selected, or no model assigned to the chat, it will return `None`.
pub fn current_chat_model_loading_status(&self) -> Option<ModelStatus> {
let current_chat = self.get_current_chat()?.borrow();
let current_chat_model_id = current_chat.last_used_file_id.as_ref()?;

let loading_model_id = self.model_loader.get_loading_file_id();
let loaded_model_id = self.loaded_model.as_ref().map(|m| m.id.clone());

if let Some(loading_model_id) = loading_model_id {
if loading_model_id == *current_chat_model_id {
return Some(ModelStatus::Loading);
}
}

if let Some(loaded_model_id) = loaded_model_id {
if loaded_model_id == *current_chat_model_id {
return Some(ModelStatus::Loaded);
}
}

Some(ModelStatus::Unloaded)
}

pub fn load_chats(&mut self) {
let paths = fs::read_dir(&self.chats_dir).unwrap();

Expand Down
60 changes: 8 additions & 52 deletions src/data/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,14 @@ impl Store {
}

fn update_load_model(&mut self) {
// self.chats.update_load_model();
if self.chats.model_loader.is_loaded() {
self.chats.loaded_model = self
.chats
.model_loader
.file_id()
.map(|id| {
self.downloads
.downloaded_files
.iter()
.find(|df| df.file.id == id)
.map(|df| df.file.clone())
})
.flatten();
.map(|id| self.downloads.get_file(&id))
.flatten()
.cloned();
}

if let Some(file) = &self.chats.loaded_model {
Expand All @@ -121,13 +115,7 @@ impl Store {
pub fn send_chat_message(&mut self, prompt: String) {
if let Some(mut chat) = self.chats.get_current_chat().map(|c| c.borrow_mut()) {
if let Some(file_id) = &chat.last_used_file_id {
if let Some(file) = self
.downloads
.downloaded_files
.iter()
.find(|df| df.file.id == *file_id)
.map(|df| &df.file)
{
if let Some(file) = self.downloads.get_file(file_id) {
chat.send_message_to_model(
prompt,
file,
Expand All @@ -145,40 +133,14 @@ impl Store {
chat.edit_message(message_id, updated_message);
chat.save();
}

// if let Some(chat) = &mut self.get_current_chat() {
// let mut chat = chat.borrow_mut();
// if regenerate {
// if chat.is_streaming {
// chat.cancel_streaming(self.backend.as_ref());
// }

// chat.remove_messages_from(message_id);
// chat.send_message_to_model(
// updated_message,
// file,
// self.model_loader.clone(),
// self.backend.as_ref(),
// );
// } else {
// chat.edit_message(message_id, updated_message);
// }
// chat.save();
// }
}

// Enhancement: Would be ideal to just have a `regenerate_from` function` to be
// used after `edit_chat_message` and keep concerns separated.
pub fn edit_chat_message_regenerating(&mut self, message_id: usize, updated_message: String) {
if let Some(mut chat) = self.chats.get_current_chat().map(|c| c.borrow_mut()) {
if let Some(file_id) = &chat.last_used_file_id {
if let Some(file) = self
.downloads
.downloaded_files
.iter()
.find(|df| df.file.id == *file_id)
.map(|df| &df.file)
{
if let Some(file) = self.downloads.get_file(file_id) {
chat.remove_messages_from(message_id);
chat.send_message_to_model(
updated_message,
Expand All @@ -192,18 +154,12 @@ impl Store {
}
}

pub fn get_currently_loading_model(&self) -> Option<File> {
pub fn get_loading_file(&self) -> Option<&File> {
self.chats
.model_loader
.get_loading_file_id()
.map(|file_id| {
self.downloads
.downloaded_files
.iter()
.find(|df| df.file.id == file_id)
.map(|df| df.file.clone())
.expect("File being loaded not known?")
})
.map(|file_id| self.downloads.get_file(&file_id))
.flatten()
}

pub fn get_loaded_downloaded_file(&self) -> Option<DownloadedFile> {
Expand Down

0 comments on commit f468606

Please sign in to comment.