1
- mod models;
2
- mod ollama;
3
- mod openai;
4
-
5
1
use crate :: utils:: { address_in_use, crypto:: to_address} ;
6
2
use dkn_p2p:: libp2p:: Multiaddr ;
3
+ use dkn_workflows:: ModelConfig ;
7
4
use eyre:: { eyre, Result } ;
8
5
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 ) ;
18
6
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 } ;
21
8
22
9
#[ derive( Debug , Clone ) ]
23
10
pub struct DriaComputeNodeConfig {
@@ -33,11 +20,6 @@ pub struct DriaComputeNodeConfig {
33
20
pub p2p_listen_addr : Multiaddr ,
34
21
/// Available LLM models & providers for the node.
35
22
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 ,
41
23
}
42
24
43
25
/// The default P2P network listen address.
@@ -97,7 +79,7 @@ impl DriaComputeNodeConfig {
97
79
let address = to_address ( & public_key) ;
98
80
log:: info!( "Node Address: 0x{}" , hex:: encode( address) ) ;
99
81
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 ( ) ) ;
101
83
#[ cfg( not( test) ) ]
102
84
if model_config. models . is_empty ( ) {
103
85
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 {
118
100
address,
119
101
model_config,
120
102
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 ( ( ) )
182
103
}
183
104
}
184
105
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 < ( ) > {
187
108
if address_in_use ( & self . p2p_listen_addr ) {
188
109
return Err ( eyre ! (
189
110
"Listen address {} is already in use." ,
0 commit comments