Skip to content

Commit 9ce8f94

Browse files
authored
Merge pull request #79 from matlab-deep-learning/remove-from-empty-history
Special error message for removing from empty history
2 parents d127953 + fd9bf75 commit 9ce8f94

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

+llms/+utils/errorMessageCatalog.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
catalog("llms:mustBeAssistantWithNameAndArguments") = "Field 'function' must be a struct with fields 'name' and 'arguments'.";
4343
catalog("llms:assistantMustHaveTextNameAndArguments") = "Fields 'name' and 'arguments' must be text with one or more characters.";
4444
catalog("llms:mustBeValidIndex") = "Index exceeds the number of array elements. Index must be less than or equal to {1}.";
45+
catalog("llms:removeFromEmptyHistory") = "Unable to remove message from empty message history.";
4546
catalog("llms:stopSequencesMustHaveMax4Elements") = "Number of stop sequences must be less than or equal to 4.";
4647
catalog("llms:endpointMustBeSpecified") = "Unable to find endpoint. Either set environment variable AZURE_OPENAI_ENDPOINT or specify name-value argument ""Endpoint"".";
4748
catalog("llms:deploymentMustBeSpecified") = "Unable to find deployment name. Either set environment variable AZURE_OPENAI_DEPLOYMENT or specify name-value argument ""Deployment"".";

messageHistory.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@
213213
this (1,1) messageHistory
214214
idx (1,1) {mustBeInteger, mustBePositive}
215215
end
216+
if isempty(this.Messages)
217+
error("llms:removeFromEmptyHistory",llms.utils.errorMessageCatalog.getMessage("llms:removeFromEmptyHistory"));
218+
end
216219
if idx>numel(this.Messages)
217220
error("llms:mustBeValidIndex",llms.utils.errorMessageCatalog.getMessage("llms:mustBeValidIndex", string(numel(this.Messages))));
218221
end

tests/tmessageHistory.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ function invalidInputsResponsePrompt(testCase, InvalidInputsResponseMessage)
319319
struct("Input", {{0}}, ...
320320
"Error", "MATLAB:validators:mustBePositive"), ...
321321
...
322+
"FromEmpty", ...
323+
struct("Input", {{1}}, ...
324+
"Error", "llms:removeFromEmptyHistory"), ...
325+
...
322326
"NonScalarInput", ...
323327
struct("Input", {{[1 2]}}, ...
324328
"Error", "MATLAB:validation:IncompatibleSize"));

0 commit comments

Comments
 (0)