Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

cli-storage code move to cli crate (#684)

Aleksandr Golokoz0b6764b8073f
diff --git a/CODEOWNERS b/CODEOWNERS
index 58fbc36d3..f35df7d4c 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS
@@ -14,7 +14,7 @@
/crates/benchmarks @uuuvn
/crates/bindings @alexxale
/crates/cli @alexxale
-/crates/cli-storage @eugenebokhan
+/crates/cli/src/storage @eugenebokhan
/crates/cli-release @alexxale
/crates/download-manager @uuuvn @eugenebokhan
/crates/dsl @uuuvn
diff --git a/Cargo.lock b/Cargo.lock
index af32b7466..a3082ef8b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -999,13 +999,17 @@ dependencies = [
"chrono",
"clap",
"comfy-table",
+ "crossterm",
"dirs",
+ "dotenvy",
+ "futures-util",
"indexmap 2.14.0",
"indicatif",
"indoc",
"iocraft",
"jsonschema",
"nagare",
+ "ratatui",
"rocket",
"serde",
"serde_json",
@@ -1014,30 +1018,13 @@ dependencies = [
"thiserror 2.0.18",
"tokio",
"tokio-stream",
+ "tracing",
"unicode-segmentation",
"unicode-width 0.2.2",
"uuid",
"uzu",
]
-[[package]]
-name = "cli-storage"
-version = "0.5.14"
-dependencies = [
- "clap",
- "crossterm",
- "dotenvy",
- "download-manager",
- "futures-util",
- "ratatui",
- "shoji",
- "tokio",
- "tracing",
- "tracing-appender",
- "tracing-subscriber",
- "uzu",
-]
-
[[package]]
name = "cli-tools"
version = "0.5.14"
diff --git a/Cargo.toml b/Cargo.toml
index 4d2af9345..28cff6fee 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,7 +14,6 @@ members = [
"crates/mock-registry",
"crates/uzu",
"crates/cli",
- "crates/cli-storage",
"crates/cli-tools",
"crates/test-runner",
"crates/keisoku",
diff --git a/crates/cli-storage/Cargo.toml b/crates/cli-storage/Cargo.toml
deleted file mode 100644
index 9b9899c20..000000000
--- a/crates/cli-storage/Cargo.toml
+++ /dev/null
@@ -1,30 +0,0 @@
-[package]
-name = "cli-storage"
-edition.workspace = true
-rust-version.workspace = true
-version.workspace = true
-authors.workspace = true
-homepage.workspace = true
-repository.workspace = true
-license.workspace = true
-
-[[bin]]
-name = "cli-storage"
-path = "src/main.rs"
-
-[dependencies]
-shoji.workspace = true
-uzu = { workspace = true, features = ["backend-cpu"] }
-tokio = { workspace = true, features = ["full"] }
-futures-util.workspace = true
-crossterm.workspace = true
-ratatui.workspace = true
-tracing.workspace = true
-tracing-subscriber.workspace = true
-tracing-appender.workspace = true
-dotenvy.workspace = true
-clap.workspace = true
-download-manager.workspace = true
-
-[lints]
-workspace = true
diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml
index 22ef6e1dc..5ee2f98cd 100644
--- a/crates/cli/Cargo.toml
+++ b/crates/cli/Cargo.toml
@@ -24,13 +24,17 @@ backend-uzu.workspace = true
chrono.workspace = true
clap.workspace = true
comfy-table.workspace = true
+crossterm.workspace = true
dirs.workspace = true
+dotenvy.workspace = true
+futures-util.workspace = true
indexmap.workspace = true
indicatif.workspace = true
indoc.workspace = true
iocraft.workspace = true
jsonschema.workspace = true
nagare.workspace = true
+ratatui.workspace = true
rocket.workspace = true
serde.workspace = true
serde_json.workspace = true
@@ -39,6 +43,7 @@ sysinfo.workspace = true
thiserror.workspace = true
tokio = { workspace = true, features = ["full"] }
tokio-stream.workspace = true
+tracing.workspace = true
unicode-segmentation.workspace = true
unicode-width.workspace = true
uuid.workspace = true
diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs
index 376d1ed00..5564d6ab7 100644
--- a/crates/cli/src/main.rs
+++ b/crates/cli/src/main.rs
@@ -4,6 +4,7 @@ use clap::{Parser, Subcommand};
mod bench;
mod interactive;
mod server;
+mod storage;
#[derive(Parser)]
#[command(name = "cli", bin_name = "cli")]
@@ -30,6 +31,10 @@ enum Commands {
#[arg(long, default_value = "127.0.0.1")]
host: String,
},
+ Storage {
+ #[arg(long, value_enum, default_value_t = storage::DownloadManagerCliType::default())]
+ download_manager: storage::DownloadManagerCliType,
+ },
}
#[tokio::main]
@@ -47,6 +52,9 @@ async fn main() -> Result<()> {
port,
host,
}) => server::run_server(model, host, port).await?,
+ Some(Commands::Storage {
+ download_manager,
+ }) => storage::run(download_manager).await?,
None => run_interactive(cli.model).await?,
}
diff --git a/crates/cli-storage/src/app.rs b/crates/cli/src/storage/app.rs
similarity index 99%
rename from crates/cli-storage/src/app.rs
rename to crates/cli/src/storage/app.rs
index 50cf7761c..6de1272f4 100644
--- a/crates/cli-storage/src/app.rs
+++ b/crates/cli/src/storage/app.rs
@@ -7,7 +7,7 @@ use shoji::types::model::Model;
use tokio::{sync::Mutex as TokioMutex, task::JoinHandle};
use uzu::{engine::Engine, storage::types::DownloadState};
-use crate::{events::AppEvent, models::ModelOrganizer, sections::Section};
+use super::{events::AppEvent, models::ModelOrganizer, sections::Section};
/// Holds a Model handle and its cached state for UI rendering
#[derive(Clone)]
diff --git a/crates/cli-storage/src/events.rs b/crates/cli/src/storage/events.rs
similarity index 100%
rename from crates/cli-storage/src/events.rs
rename to crates/cli/src/storage/events.rs
diff --git a/crates/cli-storage/src/main.rs b/crates/cli/src/storage/mod.rs
similarity index 81%
rename from crates/cli-storage/src/main.rs
rename to crates/cli/src/storage/mod.rs
index 26aadbe3c..57a4b0f0f 100644
--- a/crates/cli-storage/src/main.rs
+++ b/crates/cli/src/storage/mod.rs
@@ -1,5 +1,3 @@
-#![cfg(target_os = "macos")]
-
mod app;
mod events;
mod models;
@@ -8,7 +6,8 @@ mod ui;
use std::{io, sync::Arc};
-use clap::{Parser, ValueEnum};
+use anyhow::Result;
+use clap::ValueEnum;
use crossterm::{
execute,
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
@@ -16,16 +15,11 @@ use crossterm::{
use ratatui::{Terminal, backend::CrosstermBackend};
use uzu::engine::{DownloadManagerType, Engine, EngineConfig};
-use crate::{app::App, events::EventHandler};
-
-#[derive(Debug, Clone, Parser)]
-struct Cli {
- #[arg(long, value_enum, default_value_t = DownloadManagerCliType::default())]
- download_manager: DownloadManagerCliType,
-}
+use self::{app::App, events::EventHandler};
#[derive(Debug, Clone, Copy, ValueEnum)]
-enum DownloadManagerCliType {
+pub(crate) enum DownloadManagerCliType {
+ #[cfg(target_vendor = "apple")]
Native,
Universal,
}
@@ -39,6 +33,7 @@ impl Default for DownloadManagerCliType {
impl From<DownloadManagerType> for DownloadManagerCliType {
fn from(download_manager_type: DownloadManagerType) -> Self {
match download_manager_type {
+ #[cfg(target_vendor = "apple")]
DownloadManagerType::Native => Self::Native,
DownloadManagerType::Universal => Self::Universal,
}
@@ -48,18 +43,19 @@ impl From<DownloadManagerType> for DownloadManagerCliType {
impl From<DownloadManagerCliType> for DownloadManagerType {
fn from(download_manager_type: DownloadManagerCliType) -> Self {
match download_manager_type {
+ #[cfg(target_vendor = "apple")]
DownloadManagerCliType::Native => Self::Native,
DownloadManagerCliType::Universal => Self::Universal,
}
}
}
-#[tokio::main]
-async fn main() -> Result<(), Box<dyn std::error::Error>> {
- let cli = Cli::parse();
+pub(crate) async fn run(download_manager: DownloadManagerCliType) -> Result<()> {
dotenvy::dotenv().ok();
let runtime = tokio::runtime::Handle::current();
- let config = EngineConfig::default().with_download_manager_type(cli.download_manager.into());
+ let config = EngineConfig::default()
+ .with_application_identifier("com.trymirai.cli".to_string())
+ .with_download_manager_type(download_manager.into());
let engine = Arc::new(Engine::new(config).await?);
// Setup terminal
@@ -81,8 +77,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;
terminal.show_cursor()?;
- if let Err(e) = res {
- tracing::error!("Application error: {:?}", e);
+ if let Err(error) = res {
+ tracing::error!("Application error: {error:?}");
}
Ok(())
diff --git a/crates/cli-storage/src/models.rs b/crates/cli/src/storage/models.rs
similarity index 93%
rename from crates/cli-storage/src/models.rs
rename to crates/cli/src/storage/models.rs
index 0b0934ce4..5c0fbbbd7 100644
--- a/crates/cli-storage/src/models.rs
+++ b/crates/cli/src/storage/models.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
-use crate::{app::ModelWithState, sections::Section};
+use super::{app::ModelWithState, sections::Section};
pub struct ModelOrganizer;
diff --git a/crates/cli-storage/src/sections.rs b/crates/cli/src/storage/sections.rs
similarity index 97%
rename from crates/cli-storage/src/sections.rs
rename to crates/cli/src/storage/sections.rs
index 0445f1936..d10ffbdc5 100644
--- a/crates/cli-storage/src/sections.rs
+++ b/crates/cli/src/storage/sections.rs
@@ -1,6 +1,6 @@
use uzu::storage::types::DownloadPhase;
-use crate::app::ModelWithState;
+use super::app::ModelWithState;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Section {
diff --git a/crates/cli-storage/src/ui.rs b/crates/cli/src/storage/ui.rs
similarity index 99%
rename from crates/cli-storage/src/ui.rs
rename to crates/cli/src/storage/ui.rs
index dfa1d9b7d..34140f8ae 100644
--- a/crates/cli-storage/src/ui.rs
+++ b/crates/cli/src/storage/ui.rs
@@ -5,7 +5,7 @@ use ratatui::{
widgets::{Block, Borders, Gauge, List, ListItem, Paragraph},
};
-use crate::{
+use super::{
app::{App, ModelWithState},
models::ModelOrganizer,
sections::Section,