Skip to content

Commit 438ad78

Browse files
committed
better package sharing, add configurability to workflows configs
1 parent 7da3a09 commit 438ad78

File tree

10 files changed

+141
-186
lines changed

10 files changed

+141
-186
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ default-members = ["compute"]
77

88
[workspace.package]
99
edition = "2021"
10-
version = "0.2.12"
10+
version = "0.2.13"
1111
license = "Apache-2.0"
1212
readme = "README.md"
1313

@@ -21,7 +21,9 @@ debug = true
2121

2222
[workspace.dependencies]
2323
# async stuff
24-
tokio-util = { version = "0.7.10", features = ["rt"] }
24+
tokio-util = { version = "0.7.10", features = [
25+
"rt",
26+
] } # tokio-util provides CancellationToken
2527
tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal"] }
2628
async-trait = "0.1.81"
2729

@@ -32,7 +34,7 @@ serde_json = "1.0"
3234
# http client
3335
reqwest = "0.12.5"
3436

35-
# env reading
37+
# utilities
3638
dotenvy = "0.15.7"
3739

3840
# randomization

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ trace:
2323

2424
.PHONY: build # | Build
2525
build:
26-
cargo build
26+
cargo build --workspace
2727

2828
.PHONY: profile-cpu # | Profile CPU usage with flamegraph
2929
profile-cpu:

compute/Cargo.toml

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,35 @@ readme = "README.md"
77
authors = ["Erhan Tezcan <[email protected]>"]
88

99
[dependencies]
10-
tokio-util = { version = "0.7.10", features = ["rt"] }
11-
tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal"] }
12-
serde = { version = "1.0", features = ["derive"] }
13-
serde_json = "1.0"
14-
async-trait = "0.1.81"
15-
reqwest = "0.12.5"
10+
# async stuff
11+
tokio-util.workspace = true
12+
tokio.workspace = true
13+
async-trait.workspace = true
14+
15+
# serialize & deserialize
16+
serde.workspace = true
17+
serde_json.workspace = true
18+
19+
# http & networking
20+
reqwest.workspace = true
21+
port_check = "0.2.1"
22+
url = "2.5.0"
23+
urlencoding = "2.1.3"
1624

1725
# utilities
1826
dotenvy.workspace = true
1927
base64 = "0.22.0"
2028
hex = "0.4.3"
2129
hex-literal = "0.4.1"
22-
url = "2.5.0"
23-
urlencoding = "2.1.3"
2430
uuid = { version = "1.8.0", features = ["v4"] }
2531

26-
port_check = "0.2.1"
27-
2832
# logging & errors
2933
rand.workspace = true
3034
env_logger.workspace = true
3135
log.workspace = true
3236
eyre.workspace = true
33-
tracing = { version = "0.1.40" }
34-
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
37+
# tracing = { version = "0.1.40" }
38+
# tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
3539

3640
# encryption (ecies) & signatures (ecdsa) & hashing & bloom-filters
3741
ecies = { version = "0.2", default-features = false, features = ["pure"] }

compute/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl DriaComputeNodeConfig {
8686
log::error!("No models were provided, make sure to restart with at least one model provided within DKN_MODELS.");
8787
panic!("No models provided.");
8888
}
89-
log::info!("Models: {:?}", workflows.models);
89+
log::info!("Configured models: {:?}", workflows.models);
9090

9191
let p2p_listen_addr_str = env::var("DKN_P2P_LISTEN_ADDR")
9292
.map(|addr| addr.trim_matches('"').to_string())

compute/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ async fn main() -> Result<()> {
3434
let cancellation_token = token.clone();
3535
tokio::spawn(async move {
3636
if let Some(timeout_str) = env::var("DKN_EXIT_TIMEOUT").ok() {
37-
// add cancellation check
3837
let duration_secs = timeout_str.parse().unwrap_or(120);
38+
log::warn!("Waiting for {} seconds before exiting.", duration_secs);
3939
tokio::time::sleep(tokio::time::Duration::from_secs(duration_secs)).await;
4040
cancellation_token.cancel();
4141
} else {

workflows/Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,26 @@ authors = ["Erhan Tezcan <[email protected]>"]
1111
# ollama-rs is re-exported from ollama-workflows as well
1212
ollama-workflows = { git = "https://github.com/andthattoo/ollama-workflows" }
1313

14+
# async stuff
1415
tokio-util.workspace = true
1516
tokio.workspace = true
17+
async-trait.workspace = true
18+
19+
# serialize & deserialize
1620
serde.workspace = true
1721
serde_json.workspace = true
18-
async-trait.workspace = true
22+
23+
# http & networking
1924
reqwest.workspace = true
25+
26+
# utilities
2027
rand.workspace = true
28+
29+
# logging & errors
2130
log.workspace = true
2231
eyre.workspace = true
2332

2433
[dev-dependencies]
34+
# only used for tests
2535
env_logger.workspace = true
2636
dotenvy.workspace = true

workflows/src/config.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct DriaWorkflowsConfig {
1616
}
1717

1818
impl DriaWorkflowsConfig {
19+
/// Creates a new config with the given models.
1920
pub fn new(models: Vec<Model>) -> Self {
2021
let models_and_providers = models
2122
.into_iter()
@@ -28,6 +29,19 @@ impl DriaWorkflowsConfig {
2829
ollama: OllamaConfig::new(),
2930
}
3031
}
32+
33+
/// Sets the Ollama configuration for the Workflows config.
34+
pub fn with_ollama_config(mut self, ollama: OllamaConfig) -> Self {
35+
self.ollama = ollama;
36+
self
37+
}
38+
39+
/// Sets the OpenAI configuration for the Workflows config.
40+
pub fn with_openai_config(mut self, openai: OpenAIConfig) -> Self {
41+
self.openai = openai;
42+
self
43+
}
44+
3145
/// Parses Ollama-Workflows compatible models from a comma-separated values string.
3246
pub fn new_from_csv(input: &str) -> Self {
3347
let models_str = split_csv_line(input);
@@ -40,7 +54,7 @@ impl DriaWorkflowsConfig {
4054
Self::new(models)
4155
}
4256

43-
/// Returns the models that belong to a given providers from the config.
57+
/// Returns the models from the config that belongs to a given provider.
4458
pub fn get_models_for_provider(&self, provider: ModelProvider) -> Vec<Model> {
4559
self.models
4660
.iter()

workflows/src/providers/ollama.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ impl OllamaConfig {
7979
}
8080
}
8181

82+
/// Sets the timeout duration for checking model performance during a generation.
83+
pub fn with_timeout(mut self, timeout: Duration) -> Self {
84+
self.timeout = timeout;
85+
self
86+
}
87+
88+
/// Sets the minimum tokens per second (TPS) for checking model performance during a generation.
89+
pub fn with_min_tps(mut self, min_tps: f64) -> Self {
90+
self.min_tps = min_tps;
91+
self
92+
}
93+
94+
/// Sets the auto-pull flag for Ollama models.
95+
pub fn with_auto_pull(mut self, auto_pull: bool) -> Self {
96+
self.auto_pull = auto_pull;
97+
self
98+
}
99+
82100
/// Check if requested models exist in Ollama, and then tests them using a workflow.
83101
pub async fn check(&self, external_models: Vec<Model>) -> Result<Vec<Model>> {
84102
log::info!(

workflows/src/providers/openai.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ impl OpenAIConfig {
4343
}
4444
}
4545

46+
/// Sets the API key for OpenAI.
47+
pub fn with_api_key(mut self, api_key: String) -> Self {
48+
self.api_key = Some(api_key);
49+
self
50+
}
51+
4652
/// Check if requested models exist & are available in the OpenAI account.
4753
pub async fn check(&self, models: Vec<Model>) -> Result<Vec<Model>> {
4854
log::info!("Checking OpenAI requirements");

0 commit comments

Comments
 (0)