From 1c3de4bc13b04c8c0727b5242fbb82b85862e5e9 Mon Sep 17 00:00:00 2001 From: Christopher Creutzig <89011131+ccreutzi@users.noreply.github.com> Date: Fri, 23 Aug 2024 09:13:27 +0200 Subject: [PATCH 1/2] Special error message for removing from empty history --- +llms/+utils/errorMessageCatalog.m | 1 + messageHistory.m | 3 +++ tests/tmessageHistory.m | 4 ++++ 3 files changed, 8 insertions(+) diff --git a/+llms/+utils/errorMessageCatalog.m b/+llms/+utils/errorMessageCatalog.m index 5a9be78..f043f95 100644 --- a/+llms/+utils/errorMessageCatalog.m +++ b/+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") = "Cannot 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/messageHistory.m b/messageHistory.m index e2e0e60..adac787 100644 --- a/messageHistory.m +++ b/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 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")); From fd9bf75d0a6581fbad91224348553af7b52559a0 Mon Sep 17 00:00:00 2001 From: Christopher Creutzig <89011131+ccreutzi@users.noreply.github.com> Date: Fri, 23 Aug 2024 10:52:32 +0200 Subject: [PATCH 2/2] Update +llms/+utils/errorMessageCatalog.m Co-authored-by: MiriamScharnke --- +llms/+utils/errorMessageCatalog.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/+llms/+utils/errorMessageCatalog.m b/+llms/+utils/errorMessageCatalog.m index f043f95..1eaed29 100644 --- a/+llms/+utils/errorMessageCatalog.m +++ b/+llms/+utils/errorMessageCatalog.m @@ -42,7 +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") = "Cannot remove message from empty message history."; +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"".";