Skip to content
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
9 changes: 9 additions & 0 deletions src/Tools/AI Test Toolkit/src/AITTestContext.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ codeunit 149044 "AIT Test Context"
AITTestContextImpl.GetAITTestSuite(AITTestSuite);
end;

/// <summary>
/// Sets the token consumption for the method line run. Useful if external calls are made outside of AI toolkit.
/// </summary>
/// <param name="TokensUsed">Number of tokens used externally.</param>
procedure SetTokenConsumption(TokensUsed: Integer)
begin
AITTestContextImpl.SetTokenConsumption(TokensUsed);
end;

/// <summary>
/// Integration event that is raised after a test run is completed.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/Tools/AI Test Toolkit/src/AITTestContextImpl.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,15 @@ codeunit 149043 "AIT Test Context Impl."

CurrentTestOutputJson.Add(ElementName, TestInput.GetTestInput(ElementName).ValueAsText());
end;

/// <summary>
/// Sets the token consumption for the method line run. Useful if external calls are made outside of AI toolkit.
/// </summary>
/// <param name="TokensUsed">Number of tokens used externally.</param>
internal procedure SetTokenConsumption(TokensUsed: Integer)
var
AITTestRunIteration: Codeunit "AIT Test Run Iteration";
begin
AITTestRunIteration.SetExternalAITokenUsedByLastTestMethodLine(TokensUsed);
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ codeunit 149042 "AIT Test Run Iteration"
UpdateTestSuite: Boolean;
RunAllTests: Boolean;
GlobalAITokenUsedByLastTestMethodLine: Integer;
GlobalExternalAITokenUsedByLastTestMethodLine: Integer;
GlobalNumberOfTurnsForLastTestMethodLine: Integer;
GlobalNumberOfTurnsPassedForLastTestMethodLine: Integer;
GlobalTestAccuracy: Decimal;
Expand All @@ -36,6 +37,7 @@ codeunit 149042 "AIT Test Run Iteration"

NoOfInsertedLogEntries := 0;
GlobalAITokenUsedByLastTestMethodLine := 0;
GlobalExternalAITokenUsedByLastTestMethodLine := 0;
UpdateTestSuite := true;
RunAllTests := true;

Expand Down Expand Up @@ -155,6 +157,11 @@ codeunit 149042 "AIT Test Run Iteration"
exit(GlobalTestAccuracy);
end;

procedure SetExternalAITokenUsedByLastTestMethodLine(TokensUsed: Integer)
begin
GlobalExternalAITokenUsedByLastTestMethodLine += TokensUsed;
end;

[InternalEvent(false)]
procedure OnBeforeRunIteration(var AITTestSuite: Record "AIT Test Suite"; var AITTestMethodLine: Record "AIT Test Method Line"; var RunAllTests: Boolean; var UpdateTestSuite: Boolean)
begin
Expand All @@ -180,6 +187,7 @@ codeunit 149042 "AIT Test Run Iteration"

// Update AI Token Consumption
GlobalAITokenUsedByLastTestMethodLine := 0;
GlobalExternalAITokenUsedByLastTestMethodLine := 0;

// Update Turns
GlobalNumberOfTurnsPassedForLastTestMethodLine := 0;
Expand Down Expand Up @@ -209,7 +217,7 @@ codeunit 149042 "AIT Test Run Iteration"
GlobalTestMethodLine := CurrentTestMethodLine;

// Update AI Token Consumption
GlobalAITokenUsedByLastTestMethodLine := AOAIToken.GetTotalServerSessionTokensConsumed() - GlobalSessionAITokenUsed;
GlobalAITokenUsedByLastTestMethodLine := AOAIToken.GetTotalServerSessionTokensConsumed() - GlobalSessionAITokenUsed + GlobalExternalAITokenUsedByLastTestMethodLine;

// Update Turns
GlobalNumberOfTurnsForLastTestMethodLine := AITContextCU.GetNumberOfTurns();
Expand Down
Loading