Skip to content

Commit 3b1f41a

Browse files
authored
Merge pull request #16 from hecrj/feature/settings
Settings Screen with Model Folder and Theme Selector
2 parents 7c8a974 + d7e3b78 commit 3b1f41a

File tree

21 files changed

+1103
-272
lines changed

21 files changed

+1103
-272
lines changed

Cargo.lock

Lines changed: 234 additions & 77 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ itertools.workspace = true
1414
log.workspace = true
1515
open.workspace = true
1616
rand.workspace = true
17+
rfd.workspace = true
1718
tokio.workspace = true
1819
tracing-subscriber.workspace = true
1920

@@ -37,7 +38,7 @@ icebreaker_core.path = "./core"
3738

3839
chrono = "0.4"
3940
decoder = "0.0.3"
40-
dirs = "6.0"
41+
directories = "6.0"
4142
function = "0.2"
4243
futures = "0.3"
4344
iced = "0.14.0-dev"
@@ -47,13 +48,15 @@ log = "0.4"
4748
open = "5.2"
4849
rand = "0.9"
4950
reqwest = "0.12"
51+
rfd = "0.15"
5052
scraper = "0.22"
5153
serde = "1.0"
5254
serde_json = "1.0"
5355
sipper = "0.1"
5456
thiserror = "1.0"
5557
tokio = "1.38"
5658
tokio-stream = "0.1"
59+
toml = "0.9"
5760
tracing-subscriber = "0.3"
5861
url = "2.5"
5962
uuid = "1.10"
@@ -68,10 +71,10 @@ large-enum-variant = "allow"
6871

6972
[patch.crates-io]
7073
iced.git = "https://github.com/iced-rs/iced.git"
71-
iced.rev = "148fc77b8fbe0c8ad9b85428aa4c3bdac80c4b19"
74+
iced.rev = "9d56b488cc08b7365fb1839ed47ef92f3ff0fa36"
7275

7376
iced_core.git = "https://github.com/iced-rs/iced.git"
74-
iced_core.rev = "148fc77b8fbe0c8ad9b85428aa4c3bdac80c4b19"
77+
iced_core.rev = "9d56b488cc08b7365fb1839ed47ef92f3ff0fa36"
7578

7679
iced_palace.git = "https://github.com/hecrj/iced_palace"
7780
iced_palace.rev = "cb8f841b638c3886c6582e3d7f2e1de8c67e2e2b"

assets/mcp.svg

Lines changed: 1 addition & 0 deletions
Loading

core/Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ name = "icebreaker_core"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[lints]
7+
workspace = true
8+
69
[dependencies]
710
chrono.workspace = true
811
chrono.features = ["serde"]
@@ -26,14 +29,12 @@ uuid.workspace = true
2629
uuid.features = ["v4", "serde"]
2730

2831
decoder.workspace = true
32+
directories.workspace = true
2933
function.workspace = true
3034
futures.workspace = true
31-
serde_json.workspace = true
32-
scraper.workspace = true
33-
dirs.workspace = true
34-
thiserror.workspace = true
3535
log.workspace = true
36+
scraper.workspace = true
37+
serde_json.workspace = true
3638
sipper.workspace = true
37-
38-
[lints]
39-
workspace = true
39+
thiserror.workspace = true
40+
toml.workspace = true

core/src/assistant.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ impl Assistant {
2424

2525
const HOST_PORT: u64 = 8080;
2626

27-
pub fn boot(file: model::File, backend: Backend) -> impl Straw<Self, BootEvent, Error> {
27+
pub fn boot(
28+
directory: model::Directory,
29+
file: model::File,
30+
backend: Backend,
31+
) -> impl Straw<Self, BootEvent, Error> {
2832
use tokio::io::{self, AsyncBufReadExt};
2933
use tokio::process;
3034
use tokio::task;
@@ -46,7 +50,7 @@ impl Assistant {
4650
sipper(move |sender| async move {
4751
let mut sender = Sender(sender);
4852

49-
let mut download = model::Library::download(file.clone()).pin();
53+
let mut download = file.download(&directory).pin();
5054
let mut last_percent = None;
5155

5256
while let Some(progress) = download.sip().await {
@@ -119,8 +123,6 @@ impl Assistant {
119123

120124
sender.progress("Preparing container...", 0).await;
121125

122-
let library = model::Library::path().await;
123-
124126
let command = match backend {
125127
Backend::Cpu => {
126128
format!(
@@ -130,7 +132,7 @@ impl Assistant {
130132
filename = file.relative_path().display(),
131133
container = Self::LLAMA_CPP_CONTAINER_CPU,
132134
port = Self::HOST_PORT,
133-
volume = library.display(),
135+
volume = directory.path().display(),
134136
)
135137
}
136138
Backend::Cuda => {
@@ -141,7 +143,7 @@ impl Assistant {
141143
filename = file.relative_path().display(),
142144
container = Self::LLAMA_CPP_CONTAINER_CUDA,
143145
port = Self::HOST_PORT,
144-
volume = library.display(),
146+
volume = directory.path().display(),
145147
)
146148
}
147149
Backend::Rocm => {
@@ -154,7 +156,7 @@ impl Assistant {
154156
filename = file.relative_path().display(),
155157
container = Self::LLAMA_CPP_CONTAINER_ROCM,
156158
port = Self::HOST_PORT,
157-
volume = library.display(),
159+
volume = directory.path().display(),
158160
)
159161
}
160162
};
@@ -239,6 +241,7 @@ impl Assistant {
239241
async move {
240242
while let Some(line) = lines.next().await {
241243
if let Ok(log) = line {
244+
log::debug!("{log}");
242245
sender.log(log).await;
243246
}
244247
}

core/src/chat.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod schema;
22

33
use crate::assistant::{self, Assistant, Reply, Token};
4+
use crate::directory;
45
use crate::model;
56
use crate::plan::{self, Plan};
67
use crate::Error;
@@ -339,10 +340,7 @@ impl LastOpened {
339340
}
340341

341342
async fn storage_dir() -> Result<PathBuf, io::Error> {
342-
let directory = dirs::data_local_dir()
343-
.unwrap_or(PathBuf::from("."))
344-
.join("icebreaker")
345-
.join("chats");
343+
let directory = directory::data().join("chats");
346344

347345
fs::create_dir_all(&directory).await?;
348346

core/src/directory.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::path::Path;
2+
use std::sync::LazyLock;
3+
4+
pub fn config() -> &'static Path {
5+
PROJECT
6+
.as_ref()
7+
.map(directories::ProjectDirs::config_dir)
8+
.unwrap_or(Path::new("./config"))
9+
}
10+
11+
pub fn data() -> &'static Path {
12+
PROJECT
13+
.as_ref()
14+
.map(directories::ProjectDirs::data_dir)
15+
.unwrap_or(Path::new("./data"))
16+
}
17+
18+
static PROJECT: LazyLock<Option<directories::ProjectDirs>> =
19+
LazyLock::new(|| directories::ProjectDirs::from("rs.icebreaker", "", "icebreaker"));

core/src/lib.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ pub mod assistant;
22
pub mod chat;
33
pub mod model;
44
pub mod plan;
5+
pub mod settings;
56
pub mod web;
67

78
pub use assistant::Assistant;
89
pub use chat::Chat;
910
pub use model::Model;
1011
pub use plan::Plan;
12+
pub use settings::Settings;
1113
pub use url::Url;
1214

15+
mod directory;
1316
mod request;
1417

1518
use std::io;
@@ -26,8 +29,12 @@ pub enum Error {
2629
DockerFailed(&'static str),
2730
#[error("executor failed: {0}")]
2831
ExecutorFailed(&'static str),
29-
#[error("deserialization failed: {0}")]
30-
SerdeFailed(Arc<serde_json::Error>),
32+
#[error("JSON deserialization failed: {0}")]
33+
InvalidJson(Arc<serde_json::Error>),
34+
#[error("TOML deserialization failed: {0}")]
35+
InvalidToml(Arc<toml::de::Error>),
36+
#[error("TOML serialization impossible: {0}")]
37+
ImpossibleToml(Arc<toml::ser::Error>),
3138
#[error("deserialization failed")]
3239
DecoderFailed(Arc<decoder::Error>),
3340
#[error("task join failed: {0}")]
@@ -50,7 +57,19 @@ impl From<io::Error> for Error {
5057

5158
impl From<serde_json::Error> for Error {
5259
fn from(error: serde_json::Error) -> Self {
53-
Self::SerdeFailed(Arc::new(error))
60+
Self::InvalidJson(Arc::new(error))
61+
}
62+
}
63+
64+
impl From<toml::ser::Error> for Error {
65+
fn from(error: toml::ser::Error) -> Self {
66+
Self::ImpossibleToml(Arc::new(error))
67+
}
68+
}
69+
70+
impl From<toml::de::Error> for Error {
71+
fn from(error: toml::de::Error) -> Self {
72+
Self::InvalidToml(Arc::new(error))
5473
}
5574
}
5675

0 commit comments

Comments
 (0)