-
Notifications
You must be signed in to change notification settings - Fork 164
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
base: main
Are you sure you want to change the base?
Changes from all commits
c19b91f
b9c8b78
f4ae6f7
2b1ed5f
9f1a6a7
7bc9f6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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": "*" | ||
} | ||
] |
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", | ||
"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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? The test app is also missing the Suite Configuration (.xml) file. |
||
{ | ||
Subtype = Test; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests are missing comments: 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the links corect?