diff --git a/tests/tmessageHistory.m b/tests/tmessageHistory.m index da00d93..28836df 100644 --- a/tests/tmessageHistory.m +++ b/tests/tmessageHistory.m @@ -319,6 +319,10 @@ function invalidInputsResponsePrompt(testCase, InvalidInputsResponseMessage) struct("Input", {{0}}, ... "Error", "MATLAB:validators:mustBePositive"), ... ... + "FromEmpty", ... + struct("Input", {{1}}, ... + "Error", "llms:removeFromEmptyHistory"), ... + ... "NonScalarInput", ... struct("Input", {{[1 2]}}, ... "Error", "MATLAB:validation:IncompatibleSize")); diff --git a/toolbox/+llms/+utils/errorMessageCatalog.m b/toolbox/+llms/+utils/errorMessageCatalog.m index 5a9be78..1eaed29 100644 --- a/toolbox/+llms/+utils/errorMessageCatalog.m +++ b/toolbox/+llms/+utils/errorMessageCatalog.m @@ -42,6 +42,7 @@ catalog("llms:mustBeAssistantWithNameAndArguments") = "Field 'function' must be a struct with fields 'name' and 'arguments'."; catalog("llms:assistantMustHaveTextNameAndArguments") = "Fields 'name' and 'arguments' must be text with one or more characters."; catalog("llms:mustBeValidIndex") = "Index exceeds the number of array elements. Index must be less than or equal to {1}."; +catalog("llms:removeFromEmptyHistory") = "Unable to remove message from empty message history."; catalog("llms:stopSequencesMustHaveMax4Elements") = "Number of stop sequences must be less than or equal to 4."; catalog("llms:endpointMustBeSpecified") = "Unable to find endpoint. Either set environment variable AZURE_OPENAI_ENDPOINT or specify name-value argument ""Endpoint""."; catalog("llms:deploymentMustBeSpecified") = "Unable to find deployment name. Either set environment variable AZURE_OPENAI_DEPLOYMENT or specify name-value argument ""Deployment""."; diff --git a/toolbox/messageHistory.m b/toolbox/messageHistory.m index e2e0e60..adac787 100644 --- a/toolbox/messageHistory.m +++ b/toolbox/messageHistory.m @@ -213,6 +213,9 @@ this (1,1) messageHistory idx (1,1) {mustBeInteger, mustBePositive} end + if isempty(this.Messages) + error("llms:removeFromEmptyHistory",llms.utils.errorMessageCatalog.getMessage("llms:removeFromEmptyHistory")); + end if idx>numel(this.Messages) error("llms:mustBeValidIndex",llms.utils.errorMessageCatalog.getMessage("llms:mustBeValidIndex", string(numel(this.Messages)))); end