Skip to content

Commit

Permalink
Obsolete code removed
Browse files Browse the repository at this point in the history
  • Loading branch information
qikram committed Jul 17, 2024
1 parent 5fa097a commit 450a4e7
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,15 @@ codeunit 7763 "AOAI Chat Messages"
exit(AOAIChatMessagesImpl.GetHistoryTokenCount());
end;

#if not CLEAN25
/// <summary>
/// Appends a Tool to the payload.
/// </summary>
/// <param name="NewTool">The Tool to be added to the payload.</param>
/// <remarks>See more details here: https://go.microsoft.com/fwlink/?linkid=2254538</remarks>
[NonDebuggable]
[Obsolete('Use AddTool that takes in an AOAI Function interface.', '25.0')]
procedure AddTool(NewTool: JsonObject)
begin
#pragma warning disable AL0432
AOAIToolsImpl.AddTool(NewTool);
#pragma warning restore AL0432
end;

/// <summary>
Expand All @@ -221,27 +217,20 @@ codeunit 7763 "AOAI Chat Messages"
/// <param name="NewTool">The new Tool.</param>
/// <error>Message id does not exist.</error>
[NonDebuggable]
[Obsolete('Deprecated with no replacement. Use DeleteFunctionTool and AddTool.', '25.0')]
procedure ModifyTool(Id: Integer; NewTool: JsonObject)
begin
#pragma warning disable AL0432
AOAIToolsImpl.ModifyTool(Id, NewTool);
#pragma warning restore AL0432
end;

/// <summary>
/// Deletes a Tool from the list of Tool.
/// </summary>
/// <param name="Id">Id of the Tool.</param>
/// <error>Message id does not exist.</error>
[Obsolete('Use DeleteFunctionTool that takes in a function name instead.', '25.0')]
procedure DeleteTool(Id: Integer)
begin
#pragma warning disable AL0432
AOAIToolsImpl.DeleteTool(Id);
#pragma warning restore AL0432
end;
#endif

/// <summary>
/// Adds a function to the payload.
Expand Down Expand Up @@ -290,20 +279,15 @@ codeunit 7763 "AOAI Chat Messages"
exit(AOAIToolsImpl.GetFunctionTools());
end;

#if not CLEAN25
/// <summary>
/// Gets the list of Tools.
/// </summary>
/// <returns>List of Tools.</returns>
[NonDebuggable]
[Obsolete('Use GetFunctionTool() that takes in a function name and returns the interface.', '25.0')]
procedure GetTools(): List of [JsonObject]
begin
#pragma warning disable AL0432
exit(AOAIToolsImpl.GetTools());
#pragma warning restore AL0432
end;
#endif

/// <summary>
/// Checks if at least one Tools exists in the list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ codeunit 7778 "AOAI Tools Impl"
AddToolToPayload: Boolean;
[NonDebuggable]
ToolChoice: Text;
#if not CLEAN25
[NonDebuggable]
Tools: List of [JsonObject];
ToolIdDoesNotExistErr: Label 'Tool id does not exist.';
#endif
ToolObjectInvalidErr: Label '%1 object does not contain %2 property.', Comment = '%1 is the object name and %2 is the property that is missing.';
ToolTypeErr: Label 'Tool type must be of function type.';
TooManyFunctionsAddedErr: Label 'Too many functions have been added. Maximum number of functions is %1', Comment = '%1 is the maximum number of tools that can be added.';
Expand Down Expand Up @@ -61,9 +59,7 @@ codeunit 7778 "AOAI Tools Impl"
exit(FunctionNames.Keys());
end;

#if not CLEAN25
[NonDebuggable]
[Obsolete('Use AddTool that takes in an AOAI Function interface instead.', '25.0')]
procedure AddTool(NewTool: JsonObject)
begin
Initialize();
Expand All @@ -72,7 +68,6 @@ codeunit 7778 "AOAI Tools Impl"
end;

[NonDebuggable]
[Obsolete('Use ModifyTool that takes in an AOAI Function interface instead.', '25.0')]
procedure ModifyTool(Id: Integer; NewTool: JsonObject)
begin
if (Id < 1) or (Id > Tools.Count) then
Expand All @@ -81,7 +76,6 @@ codeunit 7778 "AOAI Tools Impl"
Tools.Set(Id, NewTool);
end;

[Obsolete('Use DeleteTool that takes in a function name instead.', '25.0')]
procedure DeleteTool(Id: Integer)
begin
if (Id < 1) or (Id > Tools.Count) then
Expand All @@ -91,12 +85,10 @@ codeunit 7778 "AOAI Tools Impl"
end;

[NonDebuggable]
[Obsolete('Use GetTool() that takes in a function name and var for AOAI Function interface.', '25.0')]
procedure GetTools(): List of [JsonObject]
begin
exit(Tools);
end;
#endif

procedure DeleteTool(Name: Text): Boolean
var
Expand All @@ -118,9 +110,7 @@ codeunit 7778 "AOAI Tools Impl"

procedure ClearTools()
begin
#if not CLEAN25
Clear(Tools);
#endif
Clear(Functions);
Clear(FunctionNames);
end;
Expand All @@ -129,9 +119,7 @@ codeunit 7778 "AOAI Tools Impl"
procedure PrepareTools() ToolsResult: JsonArray
var
Counter: Integer;
#if not CLEAN25
Tool: JsonObject;
#endif
begin
Initialize();
Counter := 1;
Expand All @@ -142,7 +130,6 @@ codeunit 7778 "AOAI Tools Impl"
Counter += 1;
until Counter > FunctionNames.Count();

#if not CLEAN25
Counter := 1;
if Tools.Count <> 0 then
repeat
Expand All @@ -151,19 +138,14 @@ codeunit 7778 "AOAI Tools Impl"
ToolsResult.Add(Tool);
Counter += 1;
until Counter > Tools.Count;
#endif
end;

procedure ToolsExists(): Boolean
begin
if not AddToolToPayload then
exit(false);

#if not CLEAN25
if (FunctionNames.Count() = 0) and (Tools.Count = 0) then
#else
if (FunctionNames.Count() = 0) then
#endif
exit(false);

exit(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ codeunit 132686 "Azure OpenAI Tools Test"
var
LibraryAssert: Codeunit "Library Assert";
ToolObjectInvalidErr: Label '%1 object does not contain %2 property.', Comment = '%1 is the object name and %2 is the property that is missing.';
#if not CLEAN25

[Test]
procedure TestAddingToolsInChatMessages()
var
AOAIChatMessages: Codeunit "AOAI Chat Messages";
begin
LibraryAssert.IsFalse(AOAIChatMessages.ToolsExists(), 'Tool should not exist');
#pragma warning disable AL0432
AOAIChatMessages.AddTool(GetTestFunction1Tool());
#pragma warning restore AL0432
LibraryAssert.IsTrue(AOAIChatMessages.ToolsExists(), 'Tool via JsonObject should exist');
end;
#endif

[Test]
procedure TestAddingFunctionsInChatMessages()
Expand All @@ -36,7 +33,6 @@ codeunit 132686 "Azure OpenAI Tools Test"
LibraryAssert.IsTrue(AOAIChatMessages.ToolsExists(), 'Tool via interface should exist');
end;

#if not CLEAN25
[Test]
procedure TestModifyToolsInChatMessages()
var
Expand All @@ -47,21 +43,15 @@ codeunit 132686 "Azure OpenAI Tools Test"
begin
Function1Tool := GetTestFunction1Tool();
Function2Tool := GetTestFunction2Tool();
#pragma warning disable AL0432
AOAIChatMessages.AddTool(Function1Tool);

Tools := AOAIChatMessages.GetTools();
#pragma warning restore AL0432

LibraryAssert.AreEqual(1, Tools.Count, 'Tool should exist');
LibraryAssert.AreEqual(Format(Function1Tool), Format(Tools.Get(1)), 'Tool should have same value.');
#pragma warning disable AL0432
AOAIChatMessages.ModifyTool(1, Function2Tool);
#pragma warning restore AL0432
LibraryAssert.AreEqual(Format(Function2Tool), Format(Tools.Get(1)), 'Tool should have same value.');
#pragma warning disable AL0432
AOAIChatMessages.DeleteTool(1);
#pragma warning restore AL0432
LibraryAssert.IsFalse(AOAIChatMessages.ToolsExists(), 'Tool should not exist');
end;

Expand All @@ -74,23 +64,16 @@ codeunit 132686 "Azure OpenAI Tools Test"
Payload: Text;
begin
LibraryAssert.IsFalse(AOAIChatMessages.ToolsExists(), 'Tool should not exist');
#pragma warning disable AL0432
AOAIChatMessages.AddTool(GetTestFunction1Tool());
AOAIChatMessages.AddTool(GetTestFunction2Tool());
#pragma warning restore AL0432
LibraryAssert.IsTrue(AOAIChatMessages.ToolsExists(), 'Tool should exist');
#pragma warning disable AL0432
AOAIChatMessages.DeleteTool(1);
#pragma warning restore AL0432
LibraryAssert.IsTrue(AOAIChatMessages.ToolsExists(), 'Tool should exist');
#pragma warning disable AL0432
Tools := AOAIChatMessages.GetTools();
#pragma warning restore AL0432
Tools.Get(1, ToolObject);
ToolObject.WriteTo(Payload);
LibraryAssert.AreEqual(Format(GetTestFunction2Tool()), Payload, 'Tool should have same value.');
end;
#endif

[Test]
procedure TestDeleteFunctionToolInChatMessages()
Expand All @@ -115,22 +98,18 @@ codeunit 132686 "Azure OpenAI Tools Test"
LibraryAssert.AreEqual(Format(TestFunction2.GetPrompt()), Payload, 'Tool should have same value.');
end;

#if not CLEAN25
[Test]
procedure TestClearToolsInChatMessagesObsoleted()
var
AOAIChatMessages: Codeunit "AOAI Chat Messages";
begin
LibraryAssert.IsFalse(AOAIChatMessages.ToolsExists(), 'Tool should not exist');
#pragma warning disable AL0432
AOAIChatMessages.AddTool(GetTestFunction1Tool());
AOAIChatMessages.AddTool(GetTestFunction2Tool());
#pragma warning restore AL0432
LibraryAssert.IsTrue(AOAIChatMessages.ToolsExists(), 'Tool should exist');
AOAIChatMessages.ClearTools();
LibraryAssert.IsFalse(AOAIChatMessages.ToolsExists(), 'No tool should exist');
end;
#endif

[Test]
procedure TestClearToolsInChatMessages()
Expand All @@ -147,20 +126,16 @@ codeunit 132686 "Azure OpenAI Tools Test"
LibraryAssert.IsFalse(AOAIChatMessages.ToolsExists(), 'No tool should exist');
end;

#if not CLEAN25
[Test]
procedure TestSetAddToolsToChatMessages()
var
AOAIChatMessages: Codeunit "AOAI Chat Messages";
begin
#pragma warning disable AL0432
AOAIChatMessages.AddTool(GetTestFunction1Tool());
#pragma warning restore AL0432
LibraryAssert.IsTrue(AOAIChatMessages.ToolsExists(), 'Tool should exist');
AOAIChatMessages.SetAddToolsToPayload(false);
LibraryAssert.IsFalse(AOAIChatMessages.ToolsExists(), 'Tool should not exist');
end;
#endif

[Test]
procedure TestSetAddFunctionToolsToChatMessages()
Expand All @@ -173,7 +148,7 @@ codeunit 132686 "Azure OpenAI Tools Test"
AOAIChatMessages.SetAddToolsToPayload(false);
LibraryAssert.IsFalse(AOAIChatMessages.ToolsExists(), 'Tool should not exist');
end;
#if not CLEAN25

[Test]
procedure TestToolFormatInChatMessages()
var
Expand All @@ -182,19 +157,14 @@ codeunit 132686 "Azure OpenAI Tools Test"
begin
Function1Tool := GetTestFunction1Tool();
Function1Tool.Remove('type');
#pragma warning disable AL0432
asserterror AOAIChatMessages.AddTool(Function1Tool);
#pragma warning restore AL0432
LibraryAssert.ExpectedError(StrSubstNo(ToolObjectInvalidErr, 'Tool', 'type'));

Function1Tool := GetTestFunction1Tool();
Function1Tool.Remove('function');
#pragma warning disable AL0432
asserterror AOAIChatMessages.AddTool(Function1Tool);
#pragma warning restore AL0432
LibraryAssert.ExpectedError(StrSubstNo(ToolObjectInvalidErr, 'Tool', 'function'));
end;
#endif

[Test]
procedure TestFunctionToolFormatInChatMessages()
Expand All @@ -210,7 +180,6 @@ codeunit 132686 "Azure OpenAI Tools Test"
LibraryAssert.ExpectedError(StrSubstNo(ToolObjectInvalidErr, 'Tool', 'function'));
end;

#if not CLEAN25
[Test]
procedure TestToolCoiceInChatMessages()
var
Expand All @@ -219,16 +188,13 @@ codeunit 132686 "Azure OpenAI Tools Test"
ToolChoice: Text;
begin
Function1Tool := GetTestFunction1Tool();
#pragma warning disable AL0432
AOAIChatMessages.AddTool(GetTestFunction1Tool());
#pragma warning restore AL0432
LibraryAssert.AreEqual('auto', AOAIChatMessages.GetToolChoice(), 'Tool choice should be auto by default.');

ToolChoice := GetToolChoice();
AOAIChatMessages.SetToolChoice(ToolChoice);
LibraryAssert.AreEqual(ToolChoice, AOAIChatMessages.GetToolChoice(), 'Tool choice should be equal to what was set.');
end;
#endif

[Test]
procedure TestToolChoiceInChatMessages()
Expand Down Expand Up @@ -271,7 +237,6 @@ codeunit 132686 "Azure OpenAI Tools Test"
LibraryAssert.AreEqual(Format(TestFunction2.GetPrompt()), Format(Tool2), 'Tool should have same value.');
end;

#if not CLEAN25
[Test]
procedure TestAssembleToolsInChatMessages()
var
Expand All @@ -284,14 +249,10 @@ codeunit 132686 "Azure OpenAI Tools Test"
Tools: JsonArray;
begin
Function1Tool := GetTestFunction1Tool();
#pragma warning disable AL0432
AOAIChatMessages.AddTool(GetTestFunction1Tool());
#pragma warning restore AL0432

Function2Tool := GetTestFunction2Tool();
#pragma warning disable AL0432
AOAIChatMessages.AddTool(GetTestFunction2Tool());
#pragma warning restore AL0432

Tools := AzureOpenAITestLibrary.GetAOAIAssembleTools(AOAIChatMessages);

Expand Down Expand Up @@ -578,7 +539,6 @@ codeunit 132686 "Azure OpenAI Tools Test"
ToolJsonObject.ReadFrom(TestTool);
exit(ToolJsonObject);
end;
#endif

local procedure GetToolChoice(): Text
begin
Expand Down

0 comments on commit 450a4e7

Please sign in to comment.