Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AI Test Tool] Add support for multi-turn in test data view #2745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions src/Tools/AI Test Toolkit/src/Logs/AITTestData.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ codeunit 149035 "AIT Test Data"
{
Access = Internal;

var
TurnsLbl: Label '<b>%1:</b> %2 <br>', Comment = '%1 = The turn number as an integer, %2 = The data from that turn', Locked = true;

procedure UpdateTestInput(TestInput: Text; TestInputView: Enum "AIT Test Input - View"): Text
var
TestData: Codeunit "Test Input Json";
Expand All @@ -21,15 +24,15 @@ codeunit 149035 "AIT Test Data"
TestInputView::"Full Input":
exit(TestInput);
TestInputView::Question:
exit(GetTestDataElement('question', TestData));
exit(FilterToElement('question', TestData));
TestInputView::Context:
exit(GetTestDataElement('context', TestData));
exit(FilterToElement('context', TestData));
TestInputView::"Test Setup":
exit(GetTestDataElement('test_setup', TestData));
exit(FilterToElement('test_setup', TestData));
TestInputView::"Ground Truth":
exit(GetTestDataElement('ground_truth', TestData));
exit(FilterToElement('ground_truth', TestData));
TestInputView::"Expected Data":
exit(GetTestDataElement('expected_data', TestData));
exit(FilterToElement('expected_data', TestData));
else
exit('');
end;
Expand All @@ -45,13 +48,13 @@ codeunit 149035 "AIT Test Data"
TestOutputView::"Full Output":
exit(TestOutput);
TestOutputView::Answer:
exit(GetTestDataElement('answer', TestData));
exit(FilterToElement('answer', TestData));
TestOutputView::Question:
exit(GetTestDataElement('question', TestData));
exit(FilterToElement('question', TestData));
TestOutputView::Context:
exit(GetTestDataElement('context', TestData));
exit(FilterToElement('context', TestData));
TestOutputView::"Ground Truth":
exit(GetTestDataElement('ground_truth', TestData));
exit(FilterToElement('ground_truth', TestData));
else
exit('');
end;
Expand All @@ -65,20 +68,38 @@ codeunit 149035 "AIT Test Data"
TestData.Initialize(TestDataText);
end;

local procedure GetTestDataElement(ElementName: Text; TestData: Codeunit "Test Input Json"): Text
local procedure FilterToElement(ElementName: Text; TestData: Codeunit "Test Input Json"): Text
var
ElementTestDataJson: Codeunit "Test Input Json";
ElementExists: Boolean;
TurnsDataJson: Codeunit "Test Input Json";
ElementJson: Codeunit "Test Input Json";
TextBuilder: TextBuilder;
IsMultiTurn: Boolean;
NumberOfTurns: Integer;
I: Integer;
begin
ElementTestDataJson := TestData.ElementExists('turns', ElementExists);
TurnsDataJson := TestData.ElementExists('turns', IsMultiTurn);

if not IsMultiTurn then
exit(GetTestDataElement(ElementName, TestData));

NumberOfTurns := TurnsDataJson.GetElementCount();
for I := 0 to NumberOfTurns - 1 do begin
ElementJson := TurnsDataJson.ElementAt(I);
TextBuilder.AppendLine(StrSubstNo(TurnsLbl, I, GetTestDataElement(ElementName, ElementJson)));
end;

if ElementExists then
TestData := ElementTestDataJson;
exit(TextBuilder.ToText());
end;

ElementTestDataJson := TestData.ElementExists(ElementName, ElementExists);
local procedure GetTestDataElement(ElementName: Text; var TestData: Codeunit "Test Input Json"): Text
var
ElementJson: Codeunit "Test Input Json";
ElementExists: Boolean;
begin
ElementJson := TestData.ElementExists(ElementName, ElementExists);

if ElementExists and (ElementTestDataJson.ToText() <> '{}') then
exit(ElementTestDataJson.ToText())
if ElementExists and (ElementJson.ToText() <> '{}') then
exit(ElementJson.ToText())
else
exit('');
end;
Expand Down
Loading