Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing WaitFor support with Ollama model downloads #260

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

aaronpowell
Copy link
Member

Closes #256

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • New integration
    • Docs are written
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Other information

The lifecycle hook would get blocked if you used WaitFor on the model resource, as it wouldn't fire until the model was healthy, which it couldn't achieve. Refactored to use an event instead that relies on the server resource ready event.

Had to turn the event into a non-blocking with Task.Run otherwise models couldn't be downloaded concurrently, as the events would run one at a time, waiting for model download completion before continuing on.

Also took this time to refactor the AddModel method to have a few extension methods, making it a bit clearer as to what happens when.

The lifecycle hook would get blocked if you used WaitFor on the model resource, as it wouldn't fire until the model was healthy, which it couldn't achieve. Refactored to use an event instead that relies on the server resource ready event.

Had to turn the event into a non-blocking with Task.Run otherwise models couldn't be downloaded concurrently, as the events would run one at a time, waiting for model download completion before continuing on.

Also took this time to refactor the AddModel method to have a few extension methods, making it a bit clearer as to what happens when.

Fixes #256
Copy link

Code Coverage

Package Line Rate Branch Rate Complexity Health
CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder 100% 100% 22
CommunityToolkit.Aspire.Hosting.Azure.StaticWebApps 100% 100% 28
CommunityToolkit.Aspire.Hosting.Bun 81% 71% 54
CommunityToolkit.Aspire.Hosting.Deno 84% 75% 72
CommunityToolkit.Aspire.Hosting.Golang 94% 50% 16
CommunityToolkit.Aspire.Hosting.Java 98% 71% 58
CommunityToolkit.Aspire.Hosting.Meilisearch 61% 27% 94
CommunityToolkit.Aspire.Hosting.NodeJS.Extensions 90% 68% 92
CommunityToolkit.Aspire.Hosting.Ollama 65% 63% 190
CommunityToolkit.Aspire.Hosting.Python.Extensions 67% 46% 56
CommunityToolkit.Aspire.Hosting.Rust 94% 83% 16
CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects 69% 60% 50
CommunityToolkit.Aspire.Meilisearch 97% 92% 68
CommunityToolkit.Aspire.OllamaSharp 84% 77% 76
Summary 77% (1893 / 2444) 65% (452 / 700) 892

Minimum allowed line rate is 60%

@aaronpowell aaronpowell requested a review from Alirexaa November 19, 2024 05:04
@aaronpowell aaronpowell added the bug Something isn't working label Nov 19, 2024
ResourceCommandState.Enabled :
ResourceCommandState.Disabled,
executeCommand: async context =>
builder.ApplicationBuilder.Eventing.Subscribe<ResourceReadyEvent>(builder.Resource.Parent, (@event, cancellationToken) =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we subscribe to the ResourceReadyEvent for a resource multiple times?
What happens when we have various models?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can, they will fire in sequence though, which is why I use Task.Run to execute the download, spawning a background job to download the model so that the event handler becomes non-blocking (originally I didn't do that and it would be blocking, which is not ideal).

@aaronpowell aaronpowell requested a review from Alirexaa November 21, 2024 00:12
@aaronpowell aaronpowell merged commit 3e7d41b into main Nov 21, 2024
10 checks passed
@aaronpowell aaronpowell deleted the aaronpowell/issue256 branch November 21, 2024 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Waiting on Ollama model resources blocks download
2 participants