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

Marketing Text AI Tests Added #1504

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions src/System Application/Test/DisabledTests/EntityTextTests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"bug": "",
"codeunitId": 134640,
"codeunitName": "Mkt Text Accuracy AIT",
"method": "*"
},
{
"bug": "",
"codeunitId": 134641,
"codeunitName": "Mkt Text RedTeam AIT",
"method": "*"
}
]
29 changes: 29 additions & 0 deletions src/System Application/Test/EntityText/app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"id": "fb54748b-71f1-4a4a-9dc8-8f1d32a60c8d",
"name": "Entity Text Test",
"publisher": "Microsoft",
"brief": "",
"description": "Tests for Entity Text",
"version": "25.0.0.0",
"privacyStatement": "https://go.microsoft.com/fwlink/?LinkId=724011",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the links corect?

"EULA": "https://go.microsoft.com/fwlink/?LinkId=724011",
"help": "https://go.microsoft.com/fwlink/?LinkId=724011",
"url": "https://go.microsoft.com/fwlink/?LinkId=724011",
"logo": "",
"dependencies": [
{
"id": "2156302a-872f-4568-be0b-60968696f0d5",
"name": "AI Test Toolkit",
"publisher": "Microsoft",
"version": "25.0.0.0"
}
],
"platform": "25.0.0.0",
"target": "OnPrem",
"idRanges": [
{
"from": 134640,
"to": 134641
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------

namespace System.Test.EntityText;

using System.TestTools.AITestToolkit;
using System.Text;

codeunit 134640 "Mkt Text Accuracy AIT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the tests to a folder for the time being to distinguish between AIT Tests vs regular tests?
In the near future, we maybe introduce a separate codeunit number range.

The test app is also missing the Suite Configuration (.xml) file.

{
Subtype = Test;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if TestPermissions needs to be set to disabled.


[Test]
procedure TaglineParagraphInspiring()
var
AITestContext: Codeunit "AIT Test Context";
EntityTextCod: Codeunit "Entity Text";
Facts: Dictionary of [Text, Text];
Format: Enum "Entity Text Format";
Category: Text;
InputPrompt: Text;
Response: Text;
begin
InputPrompt := AITestContext.GetInput().ValueAsText();
Facts := LineInputToDictionary(InputPrompt);
Format := Enum::"Entity Text Format"::TaglineParagraph;
Response := EntityTextCod.GenerateText(Facts, Enum::"Entity Text Tone"::Inspiring, Format, Enum::"Entity Text Emphasis"::None);

AITestContext.SetTestOutput(PrepareOutput(BuildFactsText(Facts, Category), Category, Response, Enum::"Entity Text Tone"::Inspiring, Format));
end;

[Test]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are missing comments:
[Scenario]
[Given]
[When]
[Then]

Did we stop using these?

procedure TaglineParagraphFormal()
var
AITestContext: Codeunit "AIT Test Context";
EntityTextCod: Codeunit "Entity Text";
Facts: Dictionary of [Text, Text];
Format: Enum "Entity Text Format";
Category: Text;
InputPrompt: Text;
Response: Text;
begin
InputPrompt := AITestContext.GetInput().ValueAsText();
Facts := LineInputToDictionary(InputPrompt);
Format := Enum::"Entity Text Format"::TaglineParagraph;
Response := EntityTextCod.GenerateText(Facts, Enum::"Entity Text Tone"::Formal, Format, Enum::"Entity Text Emphasis"::None);

AITestContext.SetTestOutput(PrepareOutput(BuildFactsText(Facts, Category), Category, Response, Enum::"Entity Text Tone"::Formal, Format));
end;

[Test]
procedure TaglineParagraphCreative()
var
AITestContext: Codeunit "AIT Test Context";
EntityTextCod: Codeunit "Entity Text";
Facts: Dictionary of [Text, Text];
Format: Enum "Entity Text Format";
Category: Text;
InputPrompt: Text;
Response: Text;
begin
InputPrompt := AITestContext.GetInput().ValueAsText();
Facts := LineInputToDictionary(InputPrompt);
Format := Enum::"Entity Text Format"::TaglineParagraph;
Response := EntityTextCod.GenerateText(Facts, Enum::"Entity Text Tone"::Creative, Format, Enum::"Entity Text Emphasis"::None);
AITestContext.SetTestOutput(PrepareOutput(BuildFactsText(Facts, Category), Category, Response, Enum::"Entity Text Tone"::Creative, Format));
end;

[Test]
procedure TaglineInspiring()
var
AITestContext: Codeunit "AIT Test Context";
EntityTextCod: Codeunit "Entity Text";
Facts: Dictionary of [Text, Text];
Format: Enum "Entity Text Format";
Category: Text;
InputPrompt: Text;
Response: Text;
begin
InputPrompt := AITestContext.GetInput().ValueAsText();
Facts := LineInputToDictionary(InputPrompt);
Format := Enum::"Entity Text Format"::Tagline;
Response := EntityTextCod.GenerateText(Facts, Enum::"Entity Text Tone"::Inspiring, Format, Enum::"Entity Text Emphasis"::None);
AITestContext.SetTestOutput(PrepareOutput(BuildFactsText(Facts, Category), Category, Response, Enum::"Entity Text Tone"::Inspiring, Format));
end;

[Test]
procedure TaglineFormal()
var
AITestContext: Codeunit "AIT Test Context";
EntityTextCod: Codeunit "Entity Text";
Facts: Dictionary of [Text, Text];
Format: Enum "Entity Text Format";
Category: Text;
InputPrompt: Text;
Response: Text;
begin
InputPrompt := AITestContext.GetInput().ValueAsText();
Facts := LineInputToDictionary(InputPrompt);
Format := Enum::"Entity Text Format"::Tagline;
Response := EntityTextCod.GenerateText(Facts, Enum::"Entity Text Tone"::Formal, Format, Enum::"Entity Text Emphasis"::None);
AITestContext.SetTestOutput(PrepareOutput(BuildFactsText(Facts, Category), Category, Response, Enum::"Entity Text Tone"::Formal, Format));
end;

[Test]
procedure TaglineCreative()
var
AITestContext: Codeunit "AIT Test Context";
EntityTextCod: Codeunit "Entity Text";
Facts: Dictionary of [Text, Text];
Format: Enum "Entity Text Format";
Category: Text;
InputPrompt: Text;
Response: Text;
begin
InputPrompt := AITestContext.GetInput().ValueAsText();
Facts := LineInputToDictionary(InputPrompt);
Format := Enum::"Entity Text Format"::Tagline;
Response := EntityTextCod.GenerateText(Facts, Enum::"Entity Text Tone"::Creative, Format, Enum::"Entity Text Emphasis"::None);
AITestContext.SetTestOutput(PrepareOutput(BuildFactsText(Facts, Category), Category, Response, Enum::"Entity Text Tone"::Creative, Format));
end;

[Test]
procedure BriefInspiring()
var
AITestContext: Codeunit "AIT Test Context";
EntityTextCod: Codeunit "Entity Text";
Facts: Dictionary of [Text, Text];
Format: Enum "Entity Text Format";
Category: Text;
InputPrompt: Text;
Response: Text;
begin
InputPrompt := AITestContext.GetInput().ValueAsText();
Facts := LineInputToDictionary(InputPrompt);
Format := Enum::"Entity Text Format"::Brief;
Response := EntityTextCod.GenerateText(Facts, Enum::"Entity Text Tone"::Inspiring, Format, Enum::"Entity Text Emphasis"::None);
AITestContext.SetTestOutput(PrepareOutput(BuildFactsText(Facts, Category), Category, Response, Enum::"Entity Text Tone"::Inspiring, Format));
end;

[Test]
procedure BriefFormal()
var
AITestContext: Codeunit "AIT Test Context";
EntityTextCod: Codeunit "Entity Text";
Facts: Dictionary of [Text, Text];
Format: Enum "Entity Text Format";
Category: Text;
InputPrompt: Text;
Response: Text;
begin
InputPrompt := AITestContext.GetInput().ValueAsText();
Facts := LineInputToDictionary(InputPrompt);
Format := Enum::"Entity Text Format"::Brief;
Response := EntityTextCod.GenerateText(Facts, Enum::"Entity Text Tone"::Formal, Format, Enum::"Entity Text Emphasis"::None);
AITestContext.SetTestOutput(PrepareOutput(BuildFactsText(Facts, Category), Category, Response, Enum::"Entity Text Tone"::Formal, Format));
Comment on lines +154 to +158
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is repeated in all procedures, and its difference is minimal:
image

Can you just make one local procedure with parameter for Enum::"Entity Text Format" and parameter for Enum::"Entity Text Tone"

Than you won't have 5 times declaration of 7 variables and use only one liners

end;

[Test]
procedure BriefCreative()
var
AITestContext: Codeunit "AIT Test Context";
EntityTextCod: Codeunit "Entity Text";
Facts: Dictionary of [Text, Text];
Format: Enum "Entity Text Format";
Category: Text;
InputPrompt: Text;
Response: Text;
begin
InputPrompt := AITestContext.GetInput().ValueAsText();
Facts := LineInputToDictionary(InputPrompt);
Format := Enum::"Entity Text Format"::Brief;
Response := EntityTextCod.GenerateText(Facts, Enum::"Entity Text Tone"::Creative, Format, Enum::"Entity Text Emphasis"::None);
AITestContext.SetTestOutput(PrepareOutput(BuildFactsText(Facts, Category), Category, Response, Enum::"Entity Text Tone"::Creative, Format));
end;

local procedure BuildFactsText(var Facts: Dictionary of [Text, Text]; var Category: Text): Text
var
FactTemplateTxt: Label '- %1: %2%3', Locked = true;
FactKey: Text;
FactValue: Text;
FactsList: Text;
NewLineChar: Char;
MaxFacts: Integer;
TotalFacts: Integer;
MaxFactLength: Integer;
begin
NewLineChar := 10;
TotalFacts := Facts.Count();

MaxFacts := 20;
MaxFactLength := 250;

TotalFacts := 0;
foreach FactKey in Facts.Keys() do begin
if TotalFacts < MaxFacts then begin
Facts.Get(FactKey, FactValue);
FactKey := FactKey.Replace(NewLineChar, '').Trim();
FactValue := FactValue.Replace(NewLineChar, '').Trim();
if (Category = '') and FactKey.Contains('Category') then
Category := FactValue
else
FactsList += StrSubstNo(FactTemplateTxt, CopyStr(FactKey, 1, MaxFactLength), CopyStr(FactValue, 1, MaxFactLength), NewLineChar);
end;
TotalFacts += 1;
end;
exit(FactsList);
end;

local procedure LineInputToDictionary(Input: Text): Dictionary of [Text, Text];
var
Attributes: Dictionary of [Text, Text];
InputJson: JsonObject;
AttributeValueToken: JsonToken;
AttributeKey: Text;
begin
InputJson.ReadFrom(Input);

foreach AttributeKey in InputJson.Keys() do begin
InputJson.Get(AttributeKey, AttributeValueToken);
Attributes.Add(AttributeKey, AttributeValueToken.AsValue().AsText());
end;
exit(Attributes);
end;

local procedure PrepareOutput(Facts: Text; Category: Text; Response: Text; Tone: Enum "Entity Text Tone"; Format: Enum "Entity Text Format"): Text;
var
Context: Text;
FormatLbl: Label '{"question": "METAPROMPT: %1", "answer": "%2", "context": "%3", "ground_truth": "%4", "tone": "%5", "format" : "%6"}', Comment = '%1= Input Prompt, %2= Response Prompt, %3= Context, %4= Ground Truth, %5= Tone, %6= Format';
EncodedNewlineTok: Label '<br />', Locked = true;
NewLineChar: Char;
begin
NewLineChar := 10;
Context := 'Here are some facts about the item:<br /><br />' + Facts.Replace(NewLineChar, EncodedNewlineTok) + '<br /> This is in the category of: ' + Category.Replace(NewLineChar, EncodedNewlineTok);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Labels? If this shouldn't be translated, shouldn't than FormatLbl be locked?

exit(StrSubstNo(FormatLbl, Facts.Replace(NewLineChar, EncodedNewlineTok), Response.Replace(NewLineChar, EncodedNewlineTok), Context, '', Tone.Names.Get(Tone.Ordinals.IndexOf(Tone.AsInteger())), Format.Names.Get(Format.Ordinals.IndexOf(Format.AsInteger()))));
end;

}
Loading
Loading