Skip to content

Commit

Permalink
Update topenAIMessages.m
Browse files Browse the repository at this point in the history
Resolved unit tests in topenAIMessages
  • Loading branch information
toshiakit committed Jan 23, 2024
1 parent 3bf8430 commit 27aa59e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tests/topenAIMessages.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,12 @@ function assistantToolCallMessageIsAdded(testCase)
funCall = struct("name", functionName, "arguments", args);
toolCall = struct("id", "123", "type", "function", "function", funCall);
toolCallPrompt = struct("role", "assistant", "content", "", "tool_calls", []);
toolCallPrompt.tool_calls = {toolCall};
% tool_calls is an array of struct in API response
toolCallPrompt.tool_calls = toolCall;
msgs = addResponseMessage(msgs, toolCallPrompt);
testCase.verifyEqual(msgs.Messages{1}, toolCallPrompt);
% to include in msgs, tool_calls must be a cell
testCase.verifyEqual(fieldnames(msgs.Messages{1}), fieldnames(toolCallPrompt));
testCase.verifyEqual(msgs.Messages{1}.tool_calls{1}, toolCallPrompt.tool_calls);
end

function assistantToolCallMessageWithoutArgsIsAdded(testCase)
Expand All @@ -95,9 +98,12 @@ function assistantToolCallMessageWithoutArgsIsAdded(testCase)
funCall = struct("name", functionName, "arguments", "{}");
toolCall = struct("id", "123", "type", "function", "function", funCall);
toolCallPrompt = struct("role", "assistant", "content", "","tool_calls", []);
toolCallPrompt.tool_calls = {toolCall};
% tool_calls is an array of struct in API response
toolCallPrompt.tool_calls = toolCall;
msgs = addResponseMessage(msgs, toolCallPrompt);
testCase.verifyEqual(msgs.Messages{1}, toolCallPrompt);
% to include in msgs, tool_calls must be a cell
testCase.verifyEqual(fieldnames(msgs.Messages{1}), fieldnames(toolCallPrompt));
testCase.verifyEqual(msgs.Messages{1}.tool_calls{1}, toolCallPrompt.tool_calls);
end

function assistantParallelToolCallMessageIsAdded(testCase)
Expand All @@ -107,6 +113,7 @@ function assistantParallelToolCallMessageIsAdded(testCase)
funCall = struct("name", functionName, "arguments", args);
toolCall = struct("id", "123", "type", "function", "function", funCall);
toolCallPrompt = struct("role", "assistant", "content", "", "tool_calls", []);
% tool_calls is an array of struct in API response
toolCallPrompt.tool_calls = [toolCall,toolCall,toolCall];
msgs = addResponseMessage(msgs, toolCallPrompt);
testCase.verifyEqual(msgs.Messages{1}, toolCallPrompt);
Expand Down

0 comments on commit 27aa59e

Please sign in to comment.