Skip to content

Commit

Permalink
Add getAnswerFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
mehrandvd committed Dec 24, 2023
1 parent f015402 commit d6e0d31
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/skUnit/Asserts/SemanticKernelAssert_Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ namespace skUnit;

public partial class SemanticKernelAssert
{
public static async Task ScenarioChatSuccessAsync(Kernel kernel, ChatScenario scenario)
public static async Task ScenarioChatSuccessAsync(Kernel kernel, ChatScenario scenario, Func<ChatHistory, Task<string>> getAnswerFunc)
{
var chatService = kernel.GetRequiredService<IChatCompletionService>();
var chatHistory = new ChatHistory();

Log($"# TEST {scenario.Description}");
Expand Down Expand Up @@ -38,13 +37,7 @@ public static async Task ScenarioChatSuccessAsync(Kernel kernel, ChatScenario sc
""");
}

OpenAIPromptExecutionSettings settings = new()
{
ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions,
};

var result = await chatService.GetChatMessageContentsAsync(chatHistory, settings);
var answer = result.First().Content ?? "";
var answer = await getAnswerFunc(chatHistory);
Log($"## [## ACTUAL ANSWER");
Log(answer);
Log();
Expand Down Expand Up @@ -90,6 +83,19 @@ public static async Task ScenarioChatSuccessAsync(Kernel kernel, ChatScenario sc
}
}

public static async Task ScenarioChatSuccessAsync(Kernel kernel, ChatScenario scenario)
{
Func<ChatHistory, Task<string>> getAnswerFunc = async (history) =>
{
var chatService = kernel.GetRequiredService<IChatCompletionService>();
var result = await chatService.GetChatMessageContentsAsync(history);

return result.First().Content ?? "";
};

await ScenarioChatSuccessAsync(kernel, scenario, getAnswerFunc);
}

public static async Task ScenarioChatSuccessAsync(Kernel kernel, List<ChatScenario> scenarios)
{
foreach (var scenario in scenarios)
Expand Down

0 comments on commit d6e0d31

Please sign in to comment.