Skip to content

Conversation

@aaronpowell
Copy link
Member

Moving away from our current ways of registering an IChatClient/IEmbeddingGenerator to leverage the builder pattern from MEAI. This allows the consumer to add middleware to the AI pipeline.

Existing methods have been marked as Obsolete.

Set some default middleware with logging and OTEL.

Fixes #461

Moving away from our current ways of registering an IChatClient/IEmbeddingGenerator to leverage the builder pattern from MEAI. This allows the consumer to add middleware to the AI pipeline.

Existing methods have been marked as Obsolete.

Set some default middleware with logging and OTEL.

Fixes #461
@aaronpowell
Copy link
Member Author

@davidfowl

@github-actions
Copy link
Contributor

Code Coverage

Package Line Rate Branch Rate Complexity Health
CommunityToolkit.Aspire.EventStore 100% 100% 46
CommunityToolkit.Aspire.GoFeatureFlag 100% 97% 74
CommunityToolkit.Aspire.Hosting.ActiveMQ 70% 27% 144
CommunityToolkit.Aspire.Hosting.ActiveMQ.MassTransit 1% 0% 14
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.Dapr 60% 51% 560
CommunityToolkit.Aspire.Hosting.Dapr.AzureRedis 93% 71% 54
CommunityToolkit.Aspire.Hosting.DbGate 63% 11% 62
CommunityToolkit.Aspire.Hosting.Deno 84% 75% 72
CommunityToolkit.Aspire.Hosting.EventStore 90% 71% 62
CommunityToolkit.Aspire.Hosting.GoFeatureFlag 59% 11% 62
CommunityToolkit.Aspire.Hosting.Golang 94% 50% 16
CommunityToolkit.Aspire.Hosting.Java 69% 72% 120
CommunityToolkit.Aspire.Hosting.Meilisearch 61% 27% 94
CommunityToolkit.Aspire.Hosting.MongoDB.Extensions 65% 38% 80
CommunityToolkit.Aspire.Hosting.Ngrok 52% 35% 82
CommunityToolkit.Aspire.Hosting.NodeJS.Extensions 90% 68% 92
CommunityToolkit.Aspire.Hosting.Ollama 65% 64% 198
CommunityToolkit.Aspire.Hosting.PapercutSmtp 92% 50% 10
CommunityToolkit.Aspire.Hosting.PostgreSQL.Extensions 70% 45% 88
CommunityToolkit.Aspire.Hosting.Python.Extensions 69% 50% 86
CommunityToolkit.Aspire.Hosting.RavenDB 64% 49% 176
CommunityToolkit.Aspire.Hosting.Rust 94% 83% 16
CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects 74% 61% 114
CommunityToolkit.Aspire.Hosting.Sqlite 96% 96% 38
CommunityToolkit.Aspire.MassTransit.RabbitMQ 100% 100% 30
CommunityToolkit.Aspire.Meilisearch 97% 92% 68
CommunityToolkit.Aspire.Microsoft.Data.Sqlite 89% 85% 52
CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite 50% 50% 88
CommunityToolkit.Aspire.OllamaSharp 72% 69% 98
CommunityToolkit.Aspire.RavenDB.Client 60% 53% 237
Summary 71% (4713 / 6599) 55% (1418 / 2558) 3037

Minimum allowed line rate is 60%

/// <param name="hostBuilder">The <see cref="IHostApplicationBuilder"/> with which services are being registered.</param>
/// <param name="serviceKey">The service key used to register the <see cref="OllamaApiClient"/> service, if any.</param>
/// <param name="disableTracing">A flag to indicate whether tracing should be disabled.</param>
public class AspireOllamaApiClientBuilder(IHostApplicationBuilder hostBuilder, string serviceKey, bool disableTracing)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe remove this constructor and just use required properties? Feels like we're going to add more properties over time.

Copy link
Member Author

Choose a reason for hiding this comment

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

/// <param name="configureSettings">An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.</param>
/// <exception cref="UriFormatException">Thrown when no Ollama endpoint is provided.</exception>
public static void AddOllamaApiClient(this IHostApplicationBuilder builder, string connectionName, Action<OllamaSharpSettings>? configureSettings = null)
public static AspireOllamaApiClientBuilder AddOllamaApiClient(this IHostApplicationBuilder builder, string connectionName, Action<OllamaSharpSettings>? configureSettings = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a breaking change. Are you OK with that?

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, it is a breaking change, but in terms of breaking changes it's a pretty unobtrusive one. Having it as a void method previously means that you weren't capturing anything to now having a returned value, but since C# doesn't require return assignment it shouldn't result in a compilation error.

It would be a problem if anyone is using reflection to find the method and invoking it based off an expected signature, and maybe a problem in F# as the return needs to be handled (or piped to ignore), but both are pretty obscure edge cases.

@davidfowl
Copy link
Contributor

APIs look much nicer! It's a breaking change though. What's the policy on that?

@aaronpowell
Copy link
Member Author

APIs look much nicer! It's a breaking change though. What's the policy on that?

"Aaron does what he wants" 😂.

As I mentioned on the specific comment, I consider this a minor breaking change and acceptable at that. We could introduce a new method and deprecate all the current ones, but the naming of that would deviate from the generally used Aspire method naming structure of Add<Type To Add>.

Behaviourally, the code is the same though, with the exception that we now add the middleware for logging and OTEL to IChatClient and IEmbeddingGenerator, but those middleware stages are unobtrusive and (arguably) not impactful to the consumer.

@aaronpowell aaronpowell merged commit 559ccd4 into main Feb 12, 2025
10 checks passed
@aaronpowell aaronpowell deleted the aaronpowell/issue461 branch February 12, 2025 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improving integration with the ChatClientBuilder and middleware of MEAI

3 participants