@@ -11,29 +11,50 @@ async fn main() -> Result<()> {
1111 println ! ( "Hello Foundry Local!" ) ;
1212 println ! ( "===================" ) ;
1313
14+ // For this example, we will use the "phi-3-mini-4k" model which is 2.181 GB in size.
15+ let model_to_use: & str = "phi-3-mini-4k" ;
16+
1417 // Create a FoundryLocalManager instance using the builder pattern
1518 println ! ( "\n Initializing Foundry Local manager..." ) ;
1619 let mut manager = FoundryLocalManager :: builder ( )
20+ // Alternatively to the checks below, you can specify the model to use directly during bootstrapping
21+ // .alias_or_model_id(model_to_use)
1722 . bootstrap ( true ) // Start the service if not running
1823 . build ( )
1924 . await ?;
2025
2126 // List all the models in the catalog
2227 println ! ( "\n Available models in catalog:" ) ;
2328 let models = manager. list_catalog_models ( ) . await ?;
29+ let model_in_catalog = models. iter ( ) . any ( |m| m. alias == model_to_use) ;
2430 for model in models {
2531 println ! ( "- {model}" ) ;
2632 }
33+ // Check if the model is in the catalog
34+ if !model_in_catalog {
35+ println ! ( "Model '{model_to_use}' not found in catalog. Exiting." ) ;
36+ return Ok ( ( ) ) ;
37+ }
2738
2839 // List available models in the local cache
2940 println ! ( "\n Available models in local cache:" ) ;
3041 let models = manager. list_cached_models ( ) . await ?;
42+ let model_in_cache = models. iter ( ) . any ( |m| m. alias == model_to_use) ;
3143 for model in models {
3244 println ! ( "- {model}" ) ;
3345 }
3446
47+ // Check if the model is already cached and download if not
48+ if !model_in_cache {
49+ println ! ( "Model '{model_to_use}' not found in local cache. Downloading..." ) ;
50+ // Download the model if not in cache
51+ // NOTE if you've bootstrapped with `alias_or_model_id`, you can use that directly and skip this check
52+ manager. download_model ( model_to_use, None , false ) . await ?;
53+ println ! ( "Model '{model_to_use}' downloaded successfully." ) ;
54+ }
55+
3556 // Get the model information
36- let model_info = manager. get_model_info ( "phi-4-mini" , true ) . await ?;
57+ let model_info = manager. get_model_info ( model_to_use , true ) . await ?;
3758 println ! ( "\n Using model: {model_info}" ) ;
3859
3960 // Build the prompt
0 commit comments