Skip to content

Commit ea74fdf

Browse files
committed
use workflows subcrate in compute
1 parent 96a5ef3 commit ea74fdf

File tree

20 files changed

+75
-744
lines changed

20 files changed

+75
-744
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ parking_lot = "0.12.2"
1616
serde = { version = "1.0", features = ["derive"] }
1717
serde_json = "1.0"
1818
async-trait = "0.1.81"
19+
dotenvy = "0.15.7"
1920
reqwest = "0.12.5"
2021
rand = "0.8.5"
2122
env_logger = "0.11.3"

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ endif
77
###############################################################################
88
.PHONY: launch # | Run with INFO logs in release mode
99
launch:
10-
RUST_LOG=none,dkn_compute=info cargo run --release
10+
RUST_LOG=none,dkn_compute=info,dkn_workflows=info cargo run --release
1111

1212
.PHONY: run # | Run with INFO logs
1313
run:
14-
RUST_LOG=none,dkn_compute=info cargo run
14+
RUST_LOG=none,dkn_compute=info,dkn_workflows=info cargo run
1515

1616
.PHONY: debug # | Run with DEBUG logs with INFO log-level workflows
1717
debug:
18-
RUST_LOG=warn,dkn_compute=debug,ollama_workflows=info cargo run
18+
RUST_LOG=warn,dkn_compute=debug,,dkn_workflows=debug,ollama_workflows=info cargo run
1919

2020
.PHONY: trace # | Run with TRACE logs
2121
trace:

compute/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ sha2 = "0.10.8"
5252
sha3 = "0.10.8"
5353
fastbloom-rs = "0.5.9"
5454

55-
# workflows
56-
ollama-workflows = { git = "https://github.com/andthattoo/ollama-workflows" }
57-
58-
# p2p
55+
# dria subcrates
5956
dkn-p2p = { path = "../p2p" }
57+
dkn-workflows = { path = "../workflows" }
6058

6159
# Vendor OpenSSL so that its easier to build cross-platform packages
6260
[dependencies.openssl]

compute/src/config/mod.rs

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
mod models;
2-
mod ollama;
3-
mod openai;
4-
51
use crate::utils::{address_in_use, crypto::to_address};
62
use dkn_p2p::libp2p::Multiaddr;
3+
use dkn_workflows::ModelConfig;
74
use eyre::{eyre, Result};
85
use libsecp256k1::{PublicKey, SecretKey};
9-
use models::ModelConfig;
10-
use ollama::OllamaConfig;
11-
use ollama_workflows::ModelProvider;
12-
use openai::OpenAIConfig;
13-
14-
use std::{env, str::FromStr, time::Duration};
15-
16-
/// Timeout duration for checking model performance during a generation.
17-
const CHECK_TIMEOUT_DURATION: Duration = Duration::from_secs(80);
186

19-
/// Minimum tokens per second (TPS) for checking model performance during a generation.
20-
const CHECK_TPS: f64 = 15.0;
7+
use std::{env, str::FromStr};
218

229
#[derive(Debug, Clone)]
2310
pub struct DriaComputeNodeConfig {
@@ -33,11 +20,6 @@ pub struct DriaComputeNodeConfig {
3320
pub p2p_listen_addr: Multiaddr,
3421
/// Available LLM models & providers for the node.
3522
pub model_config: ModelConfig,
36-
/// Even if Ollama is not used, we store the host & port here.
37-
/// If Ollama is used, this config will be respected during its instantiations.
38-
pub ollama_config: OllamaConfig,
39-
/// OpenAI API key & its service check implementation.
40-
pub openai_config: OpenAIConfig,
4123
}
4224

4325
/// The default P2P network listen address.
@@ -97,7 +79,7 @@ impl DriaComputeNodeConfig {
9779
let address = to_address(&public_key);
9880
log::info!("Node Address: 0x{}", hex::encode(address));
9981

100-
let model_config = ModelConfig::new_from_csv(env::var("DKN_MODELS").ok());
82+
let model_config = ModelConfig::new_from_csv(&env::var("DKN_MODELS").unwrap_or_default());
10183
#[cfg(not(test))]
10284
if model_config.models.is_empty() {
10385
log::error!("No models were provided, make sure to restart with at least one model provided within DKN_MODELS.");
@@ -118,72 +100,11 @@ impl DriaComputeNodeConfig {
118100
address,
119101
model_config,
120102
p2p_listen_addr,
121-
ollama_config: OllamaConfig::new(),
122-
openai_config: OpenAIConfig::new(),
123-
}
124-
}
125-
126-
/// Check if the required compute services are running.
127-
/// This has several steps:
128-
///
129-
/// - If Ollama models are used, hardcoded models are checked locally, and for
130-
/// external models, the workflow is tested with a simple task with timeout.
131-
/// - If OpenAI models are used, the API key is checked and the models are tested
132-
///
133-
/// If both type of models are used, both services are checked.
134-
/// In the end, bad models are filtered out and we simply check if we are left if any valid models at all.
135-
/// If not, an error is returned.
136-
pub async fn check_services(&mut self) -> Result<()> {
137-
log::info!("Checking configured services.");
138-
139-
// TODO: can refactor (provider, model) logic here
140-
let unique_providers = self.model_config.get_providers();
141-
142-
let mut good_models = Vec::new();
143-
144-
// if Ollama is a provider, check that it is running & Ollama models are pulled (or pull them)
145-
if unique_providers.contains(&ModelProvider::Ollama) {
146-
let ollama_models = self
147-
.model_config
148-
.get_models_for_provider(ModelProvider::Ollama);
149-
150-
// ensure that the models are pulled / pull them if not
151-
let good_ollama_models = self
152-
.ollama_config
153-
.check(ollama_models, CHECK_TIMEOUT_DURATION, CHECK_TPS)
154-
.await?;
155-
good_models.extend(
156-
good_ollama_models
157-
.into_iter()
158-
.map(|m| (ModelProvider::Ollama, m)),
159-
);
160-
}
161-
162-
// if OpenAI is a provider, check that the API key is set
163-
if unique_providers.contains(&ModelProvider::OpenAI) {
164-
let openai_models = self
165-
.model_config
166-
.get_models_for_provider(ModelProvider::OpenAI);
167-
168-
let good_openai_models = self.openai_config.check(openai_models).await?;
169-
good_models.extend(
170-
good_openai_models
171-
.into_iter()
172-
.map(|m| (ModelProvider::OpenAI, m)),
173-
);
174-
}
175-
176-
// update good models
177-
if good_models.is_empty() {
178-
Err(eyre!("No good models found, please check logs for errors."))
179-
} else {
180-
self.model_config.models = good_models;
181-
Ok(())
182103
}
183104
}
184105

185-
// ensure that listen address is free
186-
pub fn check_address_in_use(&self) -> Result<()> {
106+
/// Asserts that the configured listen address is free.
107+
pub fn assert_address_not_in_use(&self) -> Result<()> {
187108
if address_in_use(&self.p2p_listen_addr) {
188109
return Err(eyre!(
189110
"Listen address {} is already in use.",

compute/src/config/models.rs

Lines changed: 0 additions & 189 deletions
This file was deleted.

0 commit comments

Comments
 (0)