Skip to content

Commit 944d411

Browse files
authored
Merge pull request #14 from firstbatchxyz/erhant/workflows-install
Use `dkn-workflows` for model parsing logic & its re-export
2 parents 3ba64bd + a8b413b commit 944d411

File tree

19 files changed

+157
-608
lines changed

19 files changed

+157
-608
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "dkn-oracle"
33
description = "Dria Knowledge Network: Oracle Node"
4-
version = "0.1.5"
4+
version = "0.1.6"
55
edition = "2021"
66
license = "Apache-2.0"
77
readme = "README.md"
@@ -20,8 +20,8 @@ tokio = { version = "1.39.2", features = [
2020
] }
2121
lazy_static = "1.5.0"
2222

23-
# compute & workflows
24-
ollama-workflows = { git = "https://github.com/andthattoo/ollama-workflows" }
23+
# workflows
24+
dkn-workflows = { git = "https://github.com/firstbatchxyz/dkn-compute-node" }
2525

2626
# errors & logging & env
2727
env_logger = "0.11.5"

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 logging & release mode
99
launch:
10-
RUST_LOG=none,dkn_oracle=info cargo run --release start
10+
RUST_LOG=none,dkn_oracle=info,dkn_workflows=info cargo run --release start
1111

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

1616
.PHONY: debug # | Run with crate-level DEBUG logging & info-level workflows
1717
debug:
18-
RUST_LOG=none,dkn_oracle=debug,ollama_workflows=info cargo run start
18+
RUST_LOG=none,dkn_oracle=debug,dkn_workflows=debug,ollama_workflows=info cargo run start
1919

2020
###############################################################################
2121
.PHONY: install # | Install to path

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use alloy::{
55
primitives::{B256, U256},
66
};
77
use clap::{Parser, Subcommand};
8+
use dkn_workflows::Model;
89
use eyre::{eyre, Context, Result};
9-
use ollama_workflows::Model;
1010
use reqwest::Url;
1111

1212
/// `value_parser` to parse a `str` to `OracleKind`.

src/commands/coordinator.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
use std::time::Duration;
2+
13
use crate::{
2-
compute::{handle_request, ModelConfig},
4+
compute::handle_request,
35
contracts::{bytes_to_string, string_to_bytes, OracleKind, TaskStatus},
46
DriaOracle,
57
};
68
use alloy::{
79
eips::BlockNumberOrTag,
810
primitives::{utils::format_ether, U256},
911
};
12+
use dkn_workflows::{DriaWorkflowsConfig, Model};
1013
use eyre::{eyre, Context, Result};
1114
use futures_util::StreamExt;
12-
use ollama_workflows::Model;
1315

1416
/// Runs the main loop of the oracle node.
1517
pub async fn run_oracle(
@@ -35,11 +37,17 @@ pub async fn run_oracle(
3537
}
3638

3739
// prepare model config
38-
let model_config = ModelConfig::new(models);
39-
if model_config.models_providers.is_empty() {
40+
let mut model_config = DriaWorkflowsConfig::new(models);
41+
if model_config.models.is_empty() {
4042
return Err(eyre!("No models provided."))?;
4143
}
42-
model_config.check_providers().await?;
44+
let ollama_config = model_config.ollama.clone();
45+
model_config = model_config.with_ollama_config(
46+
ollama_config
47+
.with_min_tps(5.0)
48+
.with_timeout(Duration::from_secs(150)),
49+
);
50+
model_config.check_services().await?;
4351

4452
// check previous tasks
4553
if from_block.clone().into() != BlockNumberOrTag::Latest {

src/compute/handlers/generation.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use crate::{
22
compute::WorkflowsExt,
33
contracts::{bytes32_to_string, bytes_to_string},
44
data::Arweave,
5-
mine_nonce, DriaOracle, ModelConfig,
5+
mine_nonce, DriaOracle,
66
};
77
use alloy::{
88
primitives::{FixedBytes, U256},
99
rpc::types::TransactionReceipt,
1010
};
11+
use dkn_workflows::{DriaWorkflowsConfig, Executor};
1112
use eyre::{Context, Result};
12-
use ollama_workflows::Executor;
1313

1414
/// Handles a generation request.
1515
///
@@ -19,7 +19,7 @@ use ollama_workflows::Executor;
1919
/// 2. Then, we check if our models are compatible with the request. If not, we return an error.
2020
pub async fn handle_generation(
2121
node: &DriaOracle,
22-
models: &ModelConfig,
22+
workflows: &DriaWorkflowsConfig,
2323
task_id: U256,
2424
protocol: FixedBytes<32>,
2525
) -> Result<Option<TransactionReceipt>> {
@@ -43,7 +43,8 @@ pub async fn handle_generation(
4343
// choose model based on the request
4444
log::debug!("Choosing model to use");
4545
let models_string = bytes_to_string(&request.models)?;
46-
let (_, model) = models.get_any_matching_model_from_csv(&models_string)?;
46+
let models_vec = models_string.split(',').map(|s| s.to_string()).collect();
47+
let (_, model) = workflows.get_any_matching_model(models_vec)?;
4748
log::debug!("Using model: {} from {}", model, models_string);
4849

4950
// execute task

src/compute/handlers/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use super::ModelConfig;
21
use crate::{
32
contracts::{OracleCoordinator::StatusUpdate, OracleKind, TaskStatus},
43
DriaOracle,
54
};
65
use alloy::rpc::types::TransactionReceipt;
6+
use dkn_workflows::DriaWorkflowsConfig;
77
use eyre::Result;
88

99
mod generation;
@@ -21,15 +21,15 @@ use validation::*;
2121
pub async fn handle_request(
2222
node: &DriaOracle,
2323
kinds: &[OracleKind],
24-
model_config: &ModelConfig,
24+
workflows: &DriaWorkflowsConfig,
2525
event: StatusUpdate,
2626
) -> Result<Option<TransactionReceipt>> {
2727
log::debug!("Received event for task {} ()", event.taskId);
2828

2929
let response_tx_hash = match TaskStatus::try_from(event.statusAfter)? {
3030
TaskStatus::PendingGeneration => {
3131
if kinds.contains(&OracleKind::Generator) {
32-
handle_generation(node, model_config, event.taskId, event.protocol).await?
32+
handle_generation(node, workflows, event.taskId, event.protocol).await?
3333
} else {
3434
log::debug!(
3535
"Ignoring generation task {} as you are not generator.",
@@ -40,7 +40,7 @@ pub async fn handle_request(
4040
}
4141
TaskStatus::PendingValidation => {
4242
if kinds.contains(&OracleKind::Validator) {
43-
handle_validation(node, model_config, event.taskId).await?
43+
handle_validation(node, workflows, event.taskId).await?
4444
} else {
4545
log::debug!(
4646
"Ignoring generation task {} as you are not validator.",

src/compute/handlers/validation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use super::ModelConfig;
21
use crate::{mine_nonce, DriaOracle};
32
use alloy::{
43
primitives::{utils::parse_ether, Bytes, U256},
54
rpc::types::TransactionReceipt,
65
};
6+
use dkn_workflows::DriaWorkflowsConfig;
77
use eyre::{eyre, Context, Result};
88

99
/// Handles a validation request.
1010
#[allow(unused)]
1111
pub async fn handle_validation(
1212
node: &DriaOracle,
13-
models: &ModelConfig,
13+
workflows: &DriaWorkflowsConfig,
1414
task_id: U256,
1515
) -> Result<Option<TransactionReceipt>> {
1616
log::info!("Handling validation task {}", task_id);

src/compute/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ mod nonce;
55
pub use nonce::mine_nonce;
66

77
mod workflows;
8-
pub use workflows::{ModelConfig, WorkflowsExt};
8+
pub use workflows::WorkflowsExt;

src/compute/workflows/executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloy::primitives::Bytes;
22
use async_trait::async_trait;
3+
use dkn_workflows::{Entry, Executor, ProgramMemory, Workflow};
34
use eyre::{Context, Result};
4-
use ollama_workflows::{Entry, Executor, ProgramMemory, Workflow};
55

66
use super::postprocess::*;
77
use crate::data::{Arweave, OracleExternalData};

src/compute/workflows/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
mod executor;
22
pub use executor::WorkflowsExt;
33

4-
mod models;
5-
pub use models::ModelConfig;
6-
7-
mod providers;
8-
pub use providers::*;
9-
104
mod postprocess;
115

126
#[cfg(test)]
137
mod tests {
148
use super::*;
159
use alloy::primitives::Bytes;
16-
use ollama_workflows::{Entry, Executor, Model, ProgramMemory};
10+
use dkn_workflows::{Entry, Executor, Model, ProgramMemory};
1711

1812
#[tokio::test]
1913
#[ignore = "run this manually"]

0 commit comments

Comments
 (0)