1
1
use crate :: utils:: split_comma_separated;
2
+ use eyre:: { eyre, Result } ;
2
3
use ollama_workflows:: { Model , ModelProvider } ;
3
4
use rand:: seq:: IteratorRandom ; // provides Vec<_>.choose
4
5
@@ -58,27 +59,27 @@ impl ModelConfig {
58
59
/// If this is a provider, the first matching model in the node config is returned.
59
60
///
60
61
/// If there are no matching models with this logic, an error is returned.
61
- pub fn get_matching_model (
62
- & self ,
63
- model_or_provider : String ,
64
- ) -> Result < ( ModelProvider , Model ) , String > {
62
+ pub fn get_matching_model ( & self , model_or_provider : String ) -> Result < ( ModelProvider , Model ) > {
65
63
if let Ok ( provider) = ModelProvider :: try_from ( model_or_provider. clone ( ) ) {
66
64
// this is a valid provider, return the first matching model in the config
67
65
self . models
68
66
. iter ( )
69
67
. find ( |( p, _) | * p == provider)
70
- . ok_or_else ( || format ! ( "Provider {} is not supported by this node." , provider) )
68
+ . ok_or ( eyre ! (
69
+ "Provider {} is not supported by this node." ,
70
+ provider
71
+ ) )
71
72
. cloned ( )
72
73
} else if let Ok ( model) = Model :: try_from ( model_or_provider. clone ( ) ) {
73
74
// this is a valid model, return it if it is supported by the node
74
75
self . models
75
76
. iter ( )
76
77
. find ( |( _, m) | * m == model)
77
- . ok_or_else ( || format ! ( "Model {} is not supported by this node." , model) )
78
+ . ok_or ( eyre ! ( "Model {} is not supported by this node." , model) )
78
79
. cloned ( )
79
80
} else {
80
81
// this is neither a valid provider or model for this node
81
- Err ( format ! (
82
+ Err ( eyre ! (
82
83
"Given string '{}' is neither a model nor provider." ,
83
84
model_or_provider
84
85
) )
@@ -89,7 +90,7 @@ impl ModelConfig {
89
90
pub fn get_any_matching_model (
90
91
& self ,
91
92
list_model_or_provider : Vec < String > ,
92
- ) -> Result < ( ModelProvider , Model ) , String > {
93
+ ) -> Result < ( ModelProvider , Model ) > {
93
94
// filter models w.r.t supported ones
94
95
let matching_models = list_model_or_provider
95
96
. into_iter ( )
@@ -109,7 +110,7 @@ impl ModelConfig {
109
110
matching_models
110
111
. into_iter ( )
111
112
. choose ( & mut rand:: thread_rng ( ) )
112
- . ok_or_else ( || "No matching models found." . to_string ( ) )
113
+ . ok_or ( eyre ! ( "No matching models found." ) )
113
114
}
114
115
115
116
/// Returns the list of unique providers in the config.
0 commit comments