-
Notifications
You must be signed in to change notification settings - Fork 152
Support running native Ollama #978
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
examples/ollama/CommunityToolkit.Aspire.Hosting.Ollama.AppHost/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/CommunityToolkit.Aspire.Hosting.Ollama/IOllamaResource.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| namespace Aspire.Hosting.ApplicationModel; | ||
|
|
||
| /// <summary> | ||
| /// Represents an Ollama resource. | ||
| /// </summary> | ||
| public interface IOllamaResource : IResourceWithConnectionString, IResourceWithEndpoints | ||
| { | ||
| /// <summary> | ||
| /// Gets the list of models to download on initial startup. | ||
| /// </summary> | ||
| IReadOnlyList<string> Models { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the endpoint for the Ollama server. | ||
| /// </summary> | ||
| EndpointReference PrimaryEndpoint { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the host endpoint reference for this resource. | ||
| /// </summary> | ||
| EndpointReferenceExpression Host { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the port endpoint reference for this resource. | ||
| /// </summary> | ||
| EndpointReferenceExpression Port { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the connection URI expression for the Ollama server. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Format: <c>http://{host}:{port}</c>. | ||
| /// </remarks> | ||
| ReferenceExpression UriExpression { get; } | ||
|
|
||
| /// <summary> | ||
| /// Adds a model to the list of models to download on initial startup. | ||
| /// </summary> | ||
| /// <param name="modelName">The name of the model</param> | ||
| void AddModel(string modelName); | ||
| } |
58 changes: 58 additions & 0 deletions
58
src/CommunityToolkit.Aspire.Hosting.Ollama/OllamaExecutableResource.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| namespace Aspire.Hosting.ApplicationModel; | ||
|
|
||
| /// <summary> | ||
| /// A resource that represents an Ollama executable resource. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Constructs an <see cref="OllamaExecutableResource"/>. | ||
| /// </remarks> | ||
| /// <param name="name">The name of the resource.</param> | ||
| public class OllamaExecutableResource(string name) : ExecutableResource(name, "ollama", string.Empty), IOllamaResource | ||
| { | ||
| internal const string OllamaEndpointName = "http"; | ||
| internal const int DefaultHttpPort = 11434; | ||
|
|
||
| private readonly List<string> _models = []; | ||
|
|
||
| private EndpointReference? _primaryEndpointReference; | ||
|
|
||
| /// <inheritdoc/> | ||
| public IReadOnlyList<string> Models => _models; | ||
|
|
||
| /// <inheritdoc/> | ||
| public EndpointReference PrimaryEndpoint => _primaryEndpointReference ??= new(this, OllamaEndpointName); | ||
|
|
||
| /// <inheritdoc/> | ||
| public EndpointReferenceExpression Host => PrimaryEndpoint.Property(EndpointProperty.Host); | ||
|
|
||
| /// <inheritdoc/> | ||
| public EndpointReferenceExpression Port => PrimaryEndpoint.Property(EndpointProperty.Port); | ||
|
|
||
| /// <summary> | ||
| /// Gets the connection string expression for the Ollama server. | ||
| /// </summary> | ||
| public ReferenceExpression ConnectionStringExpression => | ||
| ReferenceExpression.Create( | ||
| $"Endpoint={PrimaryEndpoint.Property(EndpointProperty.Scheme)}://{PrimaryEndpoint.Property(EndpointProperty.Host)}:{PrimaryEndpoint.Property(EndpointProperty.Port)}" | ||
| ); | ||
|
|
||
| /// <inheritdoc/> | ||
| public ReferenceExpression UriExpression => ReferenceExpression.Create($"{PrimaryEndpoint.Property(EndpointProperty.Scheme)}://{Host}:{Port}"); | ||
|
|
||
| /// <inheritdoc/> | ||
| public void AddModel(string modelName) | ||
| { | ||
| ArgumentException.ThrowIfNullOrEmpty(modelName, nameof(modelName)); | ||
| if (!_models.Contains(modelName)) | ||
| { | ||
| _models.Add(modelName); | ||
| } | ||
| } | ||
|
|
||
| IEnumerable<KeyValuePair<string, ReferenceExpression>> IResourceWithConnectionString.GetConnectionProperties() | ||
| { | ||
| yield return new("Host", ReferenceExpression.Create($"{Host}")); | ||
| yield return new("Port", ReferenceExpression.Create($"{Port}")); | ||
| yield return new("Uri", UriExpression); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's best that we set it up on all Ollama tests runs, as we should do CI on both the container and non-container versions of Ollama
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, to avoid any extra workflow/actions setup on non-ollama tests I felt like this was as specific as I could get. The
AppHostTeststhat test both container/non-container versions live in a single test project (CommunityToolkit.Aspire.Hosting.Ollama.Tests)