@@ -19,12 +19,16 @@ public static async Task RunAsync()
1919
2020 // Step 1: Start the Foundry Local service
2121 Console . WriteLine ( "Starting Foundry Local service..." ) ;
22- var manager = await FoundryLocalManager . StartServiceAsync ( ) ;
22+ await FoundryLocalManager . CreateAsync ( new Configuration { AppName = "FoundryLocalSamples" } , null , default ) ;
23+ var manager = FoundryLocalManager . Instance ;
24+ await manager . StartWebServiceAsync ( default ) ;
2325
24- // Step 2: Check if the model is already downloaded
25- var cachedModels = await manager . ListCachedModelsAsync ( ) ;
26- var catalogInfo = await manager . GetModelInfoAsync ( aliasOrModelId : alias ) ;
27- var isCached = cachedModels . Any ( m => m . ModelId == catalogInfo ? . ModelId ) ;
26+ // Step 2: Get the model from the catalog
27+ var catalog = await manager . GetCatalogAsync ( default ) ;
28+ var model = await catalog . GetModelAsync ( alias , default ) ;
29+
30+ // Step 3: Check if the model is already downloaded
31+ var isCached = await model . IsCachedAsync ( default ) ;
2832
2933 if ( isCached )
3034 {
@@ -33,25 +37,25 @@ public static async Task RunAsync()
3337 else
3438 {
3539 Console . WriteLine ( $ "Downloading model: { alias } (this may take several minutes)...") ;
36- await manager . DownloadModelAsync ( aliasOrModelId : alias ) ;
40+ await model . DownloadAsync ( null , default ) ;
3741 Console . WriteLine ( $ "Download complete: { alias } ") ;
3842 }
3943
40- // Step 3 : Load the model into memory
44+ // Step 4 : Load the model into memory
4145 Console . WriteLine ( $ "Loading model: { alias } ...") ;
42- var model = await manager . LoadModelAsync ( aliasOrModelId : alias ) ;
43- Console . WriteLine ( $ "Loaded model: { model ? . ModelId } ") ;
44- Console . WriteLine ( $ "Endpoint: { manager . Endpoint } \n ") ;
46+ await model . LoadAsync ( default ) ;
47+ Console . WriteLine ( $ "Loaded model: { model . Id } ") ;
48+ Console . WriteLine ( $ "Endpoint: { manager . Urls [ 0 ] } \n ") ;
4549
46- var key = new ApiKeyCredential ( manager . ApiKey ) ;
50+ var key = new ApiKeyCredential ( "foundry-local" ) ;
4751 var client = new OpenAIClient ( key , new OpenAIClientOptions
4852 {
49- Endpoint = manager . Endpoint
53+ Endpoint = new Uri ( manager . Urls [ 0 ] )
5054 } ) ;
5155
5256 // Create an AIAgent using the Agent Framework extension method
5357 AIAgent joker = client
54- . GetChatClient ( model ? . ModelId )
58+ . GetChatClient ( model . Id )
5559 . AsAIAgent (
5660 instructions : "You are good at telling jokes. Keep your jokes short and family-friendly." ,
5761 name : "Joker"
0 commit comments