Skip to content

Commit 3fe904d

Browse files
authored
Merge pull request #96 from firstbatchxyz/erhant/peer-print-and-openai-check
openai checks & better error report & update libp2p
2 parents e63fd18 + 010d3d7 commit 3fe904d

File tree

8 files changed

+223
-82
lines changed

8 files changed

+223
-82
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55
license = "Apache-2.0"
66
readme = "README.md"
77

8+
# profiling build for flamegraphs
89
[profile.profiling]
910
inherits = "release"
1011
debug = true
@@ -43,7 +44,7 @@ fastbloom-rs = "0.5.9"
4344
ollama-workflows = { git = "https://github.com/andthattoo/ollama-workflows", rev = "25467d2" }
4445

4546
# peer-to-peer
46-
libp2p = { git = "https://github.com/anilaltuner/rust-libp2p.git", rev = "84b6d6f", features = [
47+
libp2p = { git = "https://github.com/anilaltuner/rust-libp2p.git", rev = "c5cefa1", features = [
4748
"dcutr",
4849
"ping",
4950
"relay",
@@ -65,9 +66,6 @@ tracing = { version = "0.1.40" }
6566
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
6667
public-ip = "0.2.2"
6768

68-
# TODO: solves ecies dependency issue
69-
# getrandom = "0.2.15"
70-
7169

7270
[dev-dependencies]
7371
colored = "2.1.0"

src/config/mod.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
mod models;
22
mod ollama;
3+
mod openai;
34

45
use crate::utils::crypto::to_address;
56
use libsecp256k1::{PublicKey, SecretKey};
67
use models::ModelConfig;
78
use ollama::OllamaConfig;
89
use ollama_workflows::ModelProvider;
10+
use openai::OpenAIConfig;
911

1012
use std::env;
1113

@@ -26,6 +28,8 @@ pub struct DriaComputeNodeConfig {
2628
/// Even if Ollama is not used, we store the host & port here.
2729
/// If Ollama is used, this config will be respected during its instantiations.
2830
pub ollama_config: OllamaConfig,
31+
/// OpenAI API key & its service check implementation.
32+
pub openai_config: OpenAIConfig,
2933
}
3034

3135
/// The default P2P network listen address.
@@ -88,16 +92,15 @@ impl DriaComputeNodeConfig {
8892
let p2p_listen_addr =
8993
env::var("DKN_P2P_LISTEN_ADDR").unwrap_or(DEFAULT_P2P_LISTEN_ADDR.to_string());
9094

91-
let ollama_config = OllamaConfig::new();
92-
9395
Self {
9496
admin_public_key,
9597
secret_key,
9698
public_key,
9799
address,
98100
model_config,
99101
p2p_listen_addr,
100-
ollama_config,
102+
ollama_config: OllamaConfig::new(),
103+
openai_config: OpenAIConfig::new(),
101104
}
102105
}
103106

@@ -120,12 +123,12 @@ impl DriaComputeNodeConfig {
120123

121124
// if OpenAI is a provider, check that the API key is set
122125
if unique_providers.contains(&ModelProvider::OpenAI) {
123-
log::info!("Checking OpenAI requirements");
124-
const OPENAI_API_KEY: &str = "OPENAI_API_KEY";
125-
126-
if std::env::var(OPENAI_API_KEY).is_err() {
127-
return Err("OpenAI API key not found".into());
128-
}
126+
let openai_models = self
127+
.model_config
128+
.get_models_for_provider(ModelProvider::OpenAI);
129+
self.openai_config
130+
.check(openai_models.into_iter().map(|m| m.to_string()).collect())
131+
.await?;
129132
}
130133

131134
Ok(())

src/config/ollama.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl OllamaConfig {
5151

5252
let auto_pull = std::env::var("OLLAMA_AUTO_PULL").unwrap_or_default() == "true";
5353

54-
OllamaConfig {
54+
Self {
5555
host,
5656
port,
5757
hardcoded_models,
@@ -109,6 +109,7 @@ impl OllamaConfig {
109109
}
110110
}
111111

112+
log::info!("Ollama setup is all good.",);
112113
Ok(())
113114
}
114115
}

0 commit comments

Comments
 (0)