forked from SciSharp/BotSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAiResponseHelper.cs
More file actions
34 lines (28 loc) · 1.43 KB
/
AiResponseHelper.cs
File metadata and controls
34 lines (28 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using BotSharp.Abstraction.Models;
namespace BotSharp.Plugin.ImageHandler.Helpers;
internal static class AiResponseHelper
{
internal static async Task<string> GetImageGenerationResponse(IServiceProvider services, Agent agent, string description, IEnumerable<string>? files = null)
{
var text = $"Please generate a user-friendly response from the following description to " +
$"inform user that you have completed the required image: {description}";
var settingService = services.GetRequiredService<ISettingService>();
var provider = agent?.LlmConfig?.Provider ?? "openai";
var model = agent?.LlmConfig?.Model ?? settingService.GetUpgradeModel(Gpt4xModelConstants.GPT_4o_Mini);
var completion = CompletionProvider.GetChatCompletion(services, provider: provider, model: model);
var response = await completion.GetChatCompletions(agent, [new RoleDialogModel(AgentRole.User, text)]);
return response.Content.IfNullOrEmptyAs(GetDefaultResponse(files)) ?? string.Empty;
}
internal static string GetDefaultResponse(IEnumerable<string>? files)
{
if (files.IsNullOrEmpty())
{
return $"No image is generated.";
}
if (files.Count() > 1)
{
return $"Here are the images you asked for: {string.Join(", ", files)}";
}
return $"Here is the image you asked for: {string.Join(", ", files)}";
}
}