Code: Select all
public interface ISearchService
{
Task GetCustomerAsync(string surname);
}
< /code>
Dies ist die Schnittstelle. Die Implementierung ist unkompliziert. Ich habe dann eine Plugin -Klasse erstellt: < /p>
[Description("Representats customer data")]
public class SearchPlugin(ISearchService searchService)
{
[KernelFunction("GetCustomer"), Description("Get customer details by their surname")]
[return: Description("Customer details")]
public async Task GetCustomer([Description("Customer surname")] string surname)
=> await searchService.GetCustomerAsync(surname);
}
Code: Select all
services.AddScoped();
< /code>
und registrieren Sie den Kernel: < /p>
services.AddSemanticKernel(configuration)
.Plugins.AddFromType();
public static IKernelBuilder AddSemanticKernel(this IServiceCollection services, IConfiguration configuration)
{
var modelId = "llama3.2:3b";
var endpoint = new Uri("http://localhost:11424");
services.AddOllamaChatCompletion(modelId, endpoint);
return services.AddKernel();
}
< /code>
Wenn ich jedoch die App starte, erhalte ich die folgende Ausnahme: < /p>
system.invalidoperationException: Ich kann den Scoped Service 'MyApp.Services nicht beheben.>