Skip to content

Commit b6b65c7

Browse files
authored
SDK: Update model alias resolution (#249)
* don't hardcode ep list * update best model logic * clean * put device in front * update versions to 0.5.0, js sdk * update c# * python integ test * open ai dev req * skip service stops, fix cs download publisher * add js integration test * update c# version to 0.3.0
1 parent c855ff8 commit b6b65c7

File tree

24 files changed

+1535
-1772
lines changed

24 files changed

+1535
-1772
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
test.ipynb
2+
13
# Visual Studio and Visual Studio Code
24
bin/
35
obj/

sdk/cs/samples/TestApp/Program.cs

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,41 @@ public static async Task Main(string[] args)
1717
{
1818
var app = new TestApp(); // Create an instance of TestApp
1919

20-
Console.WriteLine(new string('=', 80)); // Separator for clarity
20+
Console.WriteLine(new string('=', 80));
2121
Console.WriteLine("Testing catalog integration...");
2222
await app.TestCatalog(); // Call the instance method
2323

24-
Console.WriteLine(new string('=', 80)); // Separator for clarity
24+
Console.WriteLine(new string('=', 80));
2525
Console.WriteLine("Testing cache operations...");
2626
await app.TestCacheOperations(); // Call the instance method
2727

28-
Console.WriteLine(new string('=', 80)); // Separator for clarity
29-
Console.WriteLine("Testing OpenAI integration (from stopped service)...");
30-
using var manager = new FoundryLocalManager();
31-
if (manager != null)
28+
string[] aliasesOrModelIds = new[] { "qwen2.5-0.5b", "qwen2.5-0.5b-instruct-generic-cpu:3" };
29+
30+
foreach (var aliasOrModelId in aliasesOrModelIds)
3231
{
33-
await manager.StopServiceAsync();
32+
Console.WriteLine(new string('=', 80));
33+
// don't stop for now. the catalog api doesn't return register EP models afer stop, start and model list
34+
// Console.WriteLine($"Testing OpenAI integration (from stopped service) with {aliasOrModelId}...");
35+
// using var manager = new FoundryLocalManager();
36+
// await manager.StopServiceAsync();
37+
// await app.TestOpenAIIntegration(aliasOrModelId);
38+
39+
Console.WriteLine(new string('=', 80));
40+
Console.WriteLine($"Testing OpenAI integration (service running) with {aliasOrModelId}...");
41+
await app.TestOpenAIIntegration(aliasOrModelId);
42+
43+
Console.WriteLine(new string('=', 80));
44+
Console.WriteLine($"Testing service operations with {aliasOrModelId}...");
45+
await app.TestService();
46+
47+
Console.WriteLine(new string('=', 80));
48+
Console.WriteLine($"Testing model (un)loading with {aliasOrModelId}...");
49+
await app.TestModelLoadUnload(aliasOrModelId);
50+
51+
// Console.WriteLine(new string('=', 80));
52+
// Console.WriteLine($"Testing force downloading with {aliasOrModelId}...");
53+
// await app.TestDownload(aliasOrModelId);
3454
}
35-
await app.TestOpenAIIntegration("qwen2.5-0.5b");
36-
37-
Console.WriteLine(new string('=', 80)); // Separator for clarity
38-
Console.WriteLine("Testing OpenAI integration (test again service is started)...");
39-
await app.TestOpenAIIntegration("qwen2.5-0.5b");
40-
41-
Console.WriteLine(new string('=', 80)); // Separator for clarity
42-
Console.WriteLine("Testing service operations");
43-
await app.TestService(); // Call the instance method
44-
45-
Console.WriteLine(new string('=', 80)); // Separator for clarity
46-
Console.WriteLine("Testing model (un)loading");
47-
await app.TestModelLoadUnload("qwen2.5-0.5b"); // Call the instance method
48-
49-
Console.WriteLine(new string('=', 80)); // Separator for clarity
50-
Console.WriteLine("Testing downloading");
51-
await app.TestDownload("qwen2.5-0.5b"); // Call the instance method
52-
53-
Console.WriteLine("Press any key to exit...");
54-
Console.ReadKey(true);
5555
}
5656

5757
private async Task TestCacheOperations()
@@ -77,10 +77,11 @@ private async Task TestService()
7777
Console.WriteLine($"Service Uri: {manager.ServiceUri}");
7878
Console.WriteLine($"Endpoint {manager.Endpoint}");
7979
Console.WriteLine($"ApiKey: {manager.ApiKey}");
80-
// stop the service
81-
await manager.StopServiceAsync();
82-
Console.WriteLine($"Service stopped");
83-
Console.WriteLine($"Service running (should be false): {manager.IsServiceRunning}");
80+
// don't stop for now. the catalog api doesn't return register EP models afer stop, start and model list
81+
// // stop the service
82+
// await manager.StopServiceAsync();
83+
// Console.WriteLine($"Service stopped");
84+
// Console.WriteLine($"Service running (should be false): {manager.IsServiceRunning}");
8485
}
8586

8687
private async Task TestCatalog()
@@ -106,7 +107,7 @@ private async Task TestOpenAIIntegration(string aliasOrModelId)
106107

107108
var chatClient = client.GetChatClient(model?.ModelId);
108109

109-
CollectionResult<StreamingChatCompletionUpdate> completionUpdates = chatClient.CompleteChatStreaming("Why is the sky blue'");
110+
CollectionResult<StreamingChatCompletionUpdate> completionUpdates = chatClient.CompleteChatStreaming("Why is the sky blue?");
110111

111112
Console.Write($"[ASSISTANT]: ");
112113
foreach (StreamingChatCompletionUpdate completionUpdate in completionUpdates)
@@ -121,14 +122,25 @@ private async Task TestOpenAIIntegration(string aliasOrModelId)
121122
private async Task TestModelLoadUnload(string aliasOrModelId)
122123
{
123124
using var manager = new FoundryLocalManager();
124-
// Load a model
125+
126+
// Load the model
125127
var model = await manager.LoadModelAsync(aliasOrModelId);
126128
Console.WriteLine($"Loaded model: {model.Alias} ({model.ModelId})");
127-
// Unload the model
129+
130+
// Attempt to unload without forcing
128131
await manager.UnloadModelAsync(aliasOrModelId);
129-
Console.WriteLine($"Unloaded model: {model.Alias} ({model.ModelId})");
132+
var stillLoaded = (await manager.ListLoadedModelsAsync())
133+
.Any(m => m.ModelId == model.ModelId);
134+
Console.WriteLine($"Model still loaded (expected: True): {stillLoaded}");
135+
136+
// Force unload
137+
await manager.UnloadModelAsync(aliasOrModelId, force: true);
138+
var unloaded = (await manager.ListLoadedModelsAsync())
139+
.Any(m => m.ModelId == model.ModelId);
140+
Console.WriteLine($"Model unloaded (expected: True): {!unloaded}");
130141
}
131142

143+
132144
private async Task TestDownload(string aliasOrModelId)
133145
{
134146
using var manager = new FoundryLocalManager();

0 commit comments

Comments
 (0)