Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/ExampleBlazorApp/ExampleBlazorApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

<ItemGroup>
<ProjectReference Include="..\..\src\SmartComponents.AspNetCore\SmartComponents.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\SmartComponents.Inference.OpenAI\SmartComponents.Inference.OpenAI.csproj" />
<ProjectReference Include="..\..\src\SmartComponents.LocalEmbeddings\SmartComponents.LocalEmbeddings.csproj" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions samples/ExampleBlazorApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using ExampleBlazorApp.Components;
using SmartComponents.Inference.OpenAI;
using Microsoft.Extensions.AI.Abstractions;
using SmartComponents.LocalEmbeddings;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -12,7 +12,6 @@
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddSmartComponents()
.WithInferenceBackend<OpenAIInferenceBackend>()
.WithAntiforgeryValidation();

builder.Services.AddSingleton<LocalEmbedder>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<ItemGroup>
<ProjectReference Include="..\..\src\SmartComponents.AspNetCore\SmartComponents.AspNetCore.csproj" />
<ProjectReference Include="..\..\src\SmartComponents.Inference.OpenAI\SmartComponents.Inference.OpenAI.csproj" />
<ProjectReference Include="..\..\src\SmartComponents.LocalEmbeddings\SmartComponents.LocalEmbeddings.csproj" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="1.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 2 additions & 3 deletions samples/ExampleMvcRazorPagesApp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using SmartComponents.Inference.OpenAI;
using Microsoft.Extensions.AI.Abstractions;
using SmartComponents.LocalEmbeddings;

var builder = WebApplication.CreateBuilder(args);
Expand All @@ -11,7 +11,6 @@
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddSmartComponents()
.WithInferenceBackend<OpenAIInferenceBackend>()
.WithAntiforgeryValidation();

builder.Services.AddSingleton<LocalEmbedder>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Extensions.DependencyInjection;
using SmartComponents.StaticAssets.Inference;
using Microsoft.Extensions.AI.Abstractions;

namespace Microsoft.AspNetCore.Builder;

internal sealed class DefaultSmartComponentsBuilder(IServiceCollection services) : ISmartComponentsBuilder
{
public ISmartComponentsBuilder WithInferenceBackend<T>(string? name) where T : class, IInferenceBackend
public ISmartComponentsBuilder WithInferenceBackend<T>(string? name) where T : class, IChatClient
{
if (string.IsNullOrEmpty(name))
{
services.AddSingleton<IInferenceBackend, T>();
services.AddSingleton<IChatClient, T>();
}
else
{
services.AddKeyedSingleton<IInferenceBackend, T>(name);
services.AddKeyedSingleton<IChatClient, T>(name);
}

return this;
Expand Down
6 changes: 3 additions & 3 deletions src/SmartComponents.AspNetCore/ISmartComponentsBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using SmartComponents.StaticAssets.Inference;
using Microsoft.Extensions.AI.Abstractions;

namespace Microsoft.AspNetCore.Builder;

public interface ISmartComponentsBuilder
{
public ISmartComponentsBuilder WithInferenceBackend<T>(string? name = null) where T : class, IInferenceBackend;
public ISmartComponentsBuilder WithInferenceBackend<T>(string? name = null) where T : class, IChatClient;

public ISmartComponentsBuilder WithAntiforgeryValidation();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.Json;
Expand All @@ -9,10 +9,10 @@
using Microsoft.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.AI.Abstractions;
using SmartComponents.AspNetCore;
using SmartComponents.Inference;
using SmartComponents.Infrastructure;
using SmartComponents.StaticAssets.Inference;

namespace Microsoft.AspNetCore.Builder;

Expand Down Expand Up @@ -40,7 +40,7 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) =

builder.UseEndpoints(app =>
{
var smartPasteEndpoint = app.MapPost("/_smartcomponents/smartpaste", async ([FromServices] IInferenceBackend inference, HttpContext httpContext, [FromServices] IAntiforgery antiforgery, [FromServices] SmartPasteInference smartPasteInference) =>
var smartPasteEndpoint = app.MapPost("/_smartcomponents/smartpaste", async ([FromServices] IChatClient inference, HttpContext httpContext, [FromServices] IAntiforgery antiforgery, [FromServices] SmartPasteInference smartPasteInference) =>
{
// The rules about whether antiforgery are enabled by default vary across different
// ASP.NET Core versions. To make it consistent, we disable the default enablement on
Expand All @@ -62,7 +62,7 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) =
return result.BadRequest ? Results.BadRequest() : Results.Content(result.Response!);
});

var smartTextAreaEndpoint = app.MapPost("/_smartcomponents/smarttextarea", async ([FromServices] IInferenceBackend inference, HttpContext httpContext, [FromServices] IAntiforgery antiforgery, [FromServices] SmartTextAreaInference smartTextAreaInference) =>
var smartTextAreaEndpoint = app.MapPost("/_smartcomponents/smarttextarea", async ([FromServices] IChatClient inference, HttpContext httpContext, [FromServices] IAntiforgery antiforgery, [FromServices] SmartTextAreaInference smartTextAreaInference) =>
{
if (validateAntiforgery)
{
Expand Down
46 changes: 0 additions & 46 deletions src/SmartComponents.Inference.OpenAI/ApiConfig.cs

This file was deleted.

89 changes: 0 additions & 89 deletions src/SmartComponents.Inference.OpenAI/OpenAIInferenceBackend.cs

This file was deleted.

Loading
Loading