Код: Выделить всё
public interface ISearchService
{
Task GetCustomerAsync(string surname);
}
< /code>
Это интерфейс. Реализация проста. Затем я создал класс плагинов: < /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);
}
Код: Выделить всё
services.AddScoped();
< /code>
и зарегистрировать ядро: < /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>
Однако, когда я запускаю приложение, я получаю следующее исключение: < /p>
system.invalidoperationException: не может разрешить Scoped Service 'myApp.services.Interfaces.isearchServ' из root provider.>
Подробнее здесь: https://stackoverflow.com/questions/797 ... el-plugins
Мобильная версия