Я предоставил 3 встроенные функции (EmailPlugin.cs):
- Получить электронную почту
- Упорядочить их по дате по убыванию
- Получить первые «x» писем из списка
code> я ожидаю такой план:
- -Шаг 1 -> Шаг 2 -> Шаг 3
- Шаг 1 -> Шаг 3
Мне кажется, я что-то здесь не понял... Я создал EmailsPlanner чтобы ядро могло получить информацию о необходимых шагах для этой конкретной задачи (latest 3 E-Mails), но метод в EmailsPlanner даже не задействован.
Из документации просто не могу определить необходимые шаги, которые мне нужно сделать, чтобы сообщить об этом планировщику. правильный план достижения этой цели...
Вот мой код:
Program.cs
// add appsettings.json
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build();
// Create the kernel
var kernelBuilder = Kernel.CreateBuilder();
kernelBuilder.Services.AddOpenAIChatCompletion(
config["OPEN_AI_MODEL_ID"],
config["OPEN_AI_API_KEY"]
);
kernelBuilder.Plugins.AddFromType();
kernelBuilder.Plugins.AddFromType();
kernelBuilder.Services.AddSingleton(config);
var kernel = kernelBuilder.Build();
var planner = new HandlebarsPlanner(new HandlebarsPlannerOptions() { AllowLoops = true });
// Start the conversation
while (true)
{
// Get user input
Console.Write("User > ");
var goal = Console.ReadLine();
// Enable auto function calling
OpenAIPromptExecutionSettings openAIPromptExecutionSettings = new()
{
ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions
};
var plan = await planner.CreatePlanAsync(kernel, goal);
Console.WriteLine($"Plan > {plan}");
var result = await plan.InvokeAsync(kernel, new KernelArguments(openAIPromptExecutionSettings));
Console.Write($"Assistant > {result}");
Console.WriteLine();
}
EmailPlugin.cs
[KernelFunction]
[Description("Gets a list of all E-Mails")]
public async Task GetEmailsAsync()
{
// Fetch emails (cached and new)
var messages = await FetchEmailsFromServerAsync();
// Save updated list to cache
var updatedJson = JsonSerializer.Serialize(messages);
await File.WriteAllTextAsync(_cacheFilePath, updatedJson);
return messages;
}
[KernelFunction]
[Description("Sort E-Mails by date descending")]
public async Task SortEmailsDescendingAsync(
[Description("The list of E-Mails that should be sorted")] List emails
)
{
return await Task.Run(() =>
{
var sortedEmails = emails.OrderBy(email =>
{
DateTime.TryParseExact(email.Date, "dd.MM.yyyy - HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out var date);
return date;
}).ToList();
return sortedEmails;
});
}
[KernelFunction]
[Description("Gets the first 'x' E-Mails of the given list, where 'x' is a specified amount")]
public Task GetFirstEmails(
[Description("The list of E-Mails")] List emails,
[Description("amount of E-Mail that should be fetched from the list")] int amount
)
{
return Task.FromResult(emails.Take(amount).ToList());
}
EmailsPlanner.cs
[KernelFunction]
[Description("Returns back the required steps to get the latest 'x' E-Mails, where 'x' is a fix input")]
[return: Description("The required steps to get the latest 'x' E-Mails")]
public Task RequiredStepsForFetchingMailsAsync(
[Description("An Integer value representing how many mails should be fetched")] int amount
)
{
var result = $"""
I want to get the latest {amount} E-Mails. Here are the necessary steps to achieve the goal:
1. Get the E-Mails
2. Order them descending by date
3. Get the first {amount} E-Mails from the ordered list.
""";
// Return the plan back to the agent
return Task.FromResult(result);
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... -correctly
Мобильная версия