Skip to content

Commit 27aa59e

Browse files
committed
Update topenAIMessages.m
Resolved unit tests in topenAIMessages
1 parent 3bf8430 commit 27aa59e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

tests/topenAIMessages.m

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,12 @@ function assistantToolCallMessageIsAdded(testCase)
8484
funCall = struct("name", functionName, "arguments", args);
8585
toolCall = struct("id", "123", "type", "function", "function", funCall);
8686
toolCallPrompt = struct("role", "assistant", "content", "", "tool_calls", []);
87-
toolCallPrompt.tool_calls = {toolCall};
87+
% tool_calls is an array of struct in API response
88+
toolCallPrompt.tool_calls = toolCall;
8889
msgs = addResponseMessage(msgs, toolCallPrompt);
89-
testCase.verifyEqual(msgs.Messages{1}, toolCallPrompt);
90+
% to include in msgs, tool_calls must be a cell
91+
testCase.verifyEqual(fieldnames(msgs.Messages{1}), fieldnames(toolCallPrompt));
92+
testCase.verifyEqual(msgs.Messages{1}.tool_calls{1}, toolCallPrompt.tool_calls);
9093
end
9194

9295
function assistantToolCallMessageWithoutArgsIsAdded(testCase)
@@ -95,9 +98,12 @@ function assistantToolCallMessageWithoutArgsIsAdded(testCase)
9598
funCall = struct("name", functionName, "arguments", "{}");
9699
toolCall = struct("id", "123", "type", "function", "function", funCall);
97100
toolCallPrompt = struct("role", "assistant", "content", "","tool_calls", []);
98-
toolCallPrompt.tool_calls = {toolCall};
101+
% tool_calls is an array of struct in API response
102+
toolCallPrompt.tool_calls = toolCall;
99103
msgs = addResponseMessage(msgs, toolCallPrompt);
100-
testCase.verifyEqual(msgs.Messages{1}, toolCallPrompt);
104+
% to include in msgs, tool_calls must be a cell
105+
testCase.verifyEqual(fieldnames(msgs.Messages{1}), fieldnames(toolCallPrompt));
106+
testCase.verifyEqual(msgs.Messages{1}.tool_calls{1}, toolCallPrompt.tool_calls);
101107
end
102108

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

0 commit comments

Comments
 (0)