Skip to content

Commit 238e11a

Browse files
committed
Rename openAIMessages to messageHistory
1 parent 0973f11 commit 238e11a

14 files changed

+71
-72
lines changed

+llms/+utils/errorMessageCatalog.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
catalog("llms:keyMustBeSpecified") = "Unable to find API key. Either set environment variable {1} or specify name-value argument ""APIKey"".";
4747
catalog("llms:mustHaveMessages") = "Value must contain at least one message in Messages.";
4848
catalog("llms:mustSetFunctionsForCall") = "When no functions are defined, ToolChoice must not be specified.";
49-
catalog("llms:mustBeMessagesOrTxt") = "Messages must be text with one or more characters or an openAIMessages objects.";
49+
catalog("llms:mustBeMessagesOrTxt") = "Messages must be text with one or more characters or a messageHistory object.";
5050
catalog("llms:invalidOptionAndValueForModel") = "'{1}' with value '{2}' is not supported for ModelName '{3}'";
5151
catalog("llms:invalidOptionForModel") = "{1} is not supported for ModelName '{2}'";
5252
catalog("llms:invalidContentTypeForModel") = "{1} is not supported for ModelName '{2}'";

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ txt = generate(chat,"The team is feeling very motivated")
134134

135135
If you want to create a chat system, you will have to create a history of the conversation and pass that to the `generate` function.
136136

137-
To start a conversation history, create a `openAIMessages` object:
137+
To start a conversation history, create a `messageHistory` object:
138138

139139
```matlab
140-
history = openAIMessages;
140+
history = messageHistory;
141141
```
142142

143143
Then create the chat assistant:
@@ -146,7 +146,7 @@ Then create the chat assistant:
146146
chat = openAIChat("You are a helpful AI assistant.");
147147
```
148148

149-
(Side note: `azureChat` and `ollamaChat` work with `openAIMessages`, too.)
149+
(Side note: `azureChat` and `ollamaChat` work with `messageHistory`, too.)
150150

151151
Add a user message to the history and pass it to `generate`:
152152

@@ -197,7 +197,7 @@ chat = openAIChat("You are a helpful assistant.",Tools=f);
197197
When the model identifies that it could use the defined functions to answer a query, it will return a `tool_calls` request, instead of directly generating the response:
198198

199199
```matlab
200-
messages = openAIMessages;
200+
messages = messageHistory;
201201
messages = addUserMessage(messages, "What is the sine of 30?");
202202
[txt, response] = generate(chat, messages);
203203
messages = addResponseMessage(messages, response);
@@ -287,7 +287,7 @@ Note that this function does not need to exist, since it will only be used to ex
287287
```matlab
288288
chat = openAIChat("You are helpful assistant that reads patient records and extracts information", ...
289289
Tools=f);
290-
messages = openAIMessages;
290+
messages = messageHistory;
291291
messages = addUserMessage(messages,"Extract the information from the report:" + newline + patientReport);
292292
[txt, response] = generate(chat, messages);
293293
```
@@ -332,7 +332,7 @@ You can use gpt-4-turbo to experiment with image understanding.
332332
```matlab
333333
chat = openAIChat("You are an AI assistant.", ModelName="gpt-4-turbo");
334334
image_path = "peppers.png";
335-
messages = openAIMessages;
335+
messages = messageHistory;
336336
messages = addUserMessageWithImages(messages,"What is in the image?",image_path);
337337
[txt,response] = generate(chat,messages,MaxNumTokens=4096);
338338
% Should output the description of the image
@@ -357,8 +357,8 @@ After establishing your connection with Azure, you can continue using the `gener
357357
% Initialize the Azure Chat object, passing a system prompt and specifying the API version
358358
chat = azureChat(YOUR_RESOURCE_NAME, YOUR_DEPLOYMENT_NAME, "You are a helpful AI assistant", APIVersion="2023-12-01-preview");
359359
360-
% Create an openAIMessages object to start the conversation history
361-
history = openAIMessages;
360+
% Create a messageHistory object to start the conversation history
361+
history = messageHistory;
362362
363363
% Ask your question and store it in the history, create the response using the generate method, and store the response in the history
364364
history = addUserMessage(history,"What is an eigenvalue?");
@@ -382,8 +382,8 @@ In many workflows, `ollamaChat` is drop-in compatible with `openAIChat`:
382382
% Initialize the chat object
383383
chat = ollamaChat("phi3");
384384
385-
% Create an openAIMessages object to start the conversation history
386-
history = openAIMessages;
385+
% Create a messageHistory object to start the conversation history
386+
history = messageHistory;
387387
388388
% Ask your question and store it in the history, create the response using the generate method, and store the response in the history
389389
history = addUserMessage(history,"What is an eigenvalue?");

azureChat.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ function mustBeNonzeroLengthTextScalar(content)
261261
end
262262

263263
function mustBeValidMsgs(value)
264-
if isa(value, "openAIMessages")
264+
if isa(value, "messageHistory")
265265
if numel(value.Messages) == 0
266266
error("llms:mustHaveMessages", llms.utils.errorMessageCatalog.getMessage("llms:mustHaveMessages"));
267267
end
Binary file not shown.

examples/CreateSimpleChatBot.mlx

10 Bytes
Binary file not shown.
2 Bytes
Binary file not shown.

functionSignatures.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"inputs":
2828
[
2929
{"name":"this","kind":"required","type":["openAIChat","scalar"]},
30-
{"name":"messages","kind":"required","type":[["openAIMessages","row"],["string","scalar"]]},
30+
{"name":"messages","kind":"required","type":[["messageHistory","row"],["string","scalar"]]},
3131
{"name":"NumCompletions","kind":"namevalue","type":["numeric","scalar","integer","positive"]},
3232
{"name":"MaxNumTokens","kind":"namevalue","type":["numeric","scalar","positive"]},
3333
{"name":"ToolChoice","kind":"namevalue","type":"choices=[\"none\",\"auto\",this.FunctionNames]"},
@@ -69,7 +69,7 @@
6969
"inputs":
7070
[
7171
{"name":"this","kind":"required","type":["azureChat","scalar"]},
72-
{"name":"messages","kind":"required","type":[["openAIMessages","row"],["string","scalar"]]},
72+
{"name":"messages","kind":"required","type":[["messageHistory","row"],["string","scalar"]]},
7373
{"name":"NumCompletions","kind":"namevalue","type":["numeric","scalar","integer","positive"]},
7474
{"name":"MaxNumTokens","kind":"namevalue","type":["numeric","scalar","positive"]},
7575
{"name":"ToolChoice","kind":"namevalue","type":"choices=[\"none\",\"auto\",this.FunctionNames]"},
@@ -107,7 +107,7 @@
107107
"inputs":
108108
[
109109
{"name":"this","kind":"required","type":["ollamaChat","scalar"]},
110-
{"name":"messages","kind":"required","type":[["openAIMessages","row"],["string","scalar"]]},
110+
{"name":"messages","kind":"required","type":[["messageHistory","row"],["string","scalar"]]},
111111
{"name":"NumCompletions","kind":"namevalue","type":["numeric","scalar","integer","positive"]},
112112
{"name":"MaxNumTokens","kind":"namevalue","type":["numeric","scalar","positive"]},
113113
{"name":"Seed","kind":"namevalue","type":["numeric","integer","scalar"]}

openAIMessages.m renamed to messageHistory.m

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
classdef (Sealed) openAIMessages
2-
%openAIMessages - Create an object to manage and store messages in a conversation.
3-
% messages = openAIMessages creates an openAIMessages object.
1+
classdef (Sealed) messageHistory
2+
%messageHistory - Create an object to manage and store messages in a conversation.
3+
% messages = messageHistory creates a messageHistory object.
44
%
5-
% openAIMessages functions:
5+
% messageHistory functions:
66
% addSystemMessage - Add system message.
77
% addUserMessage - Add user message.
88
% addUserMessageWithImages - Add user message with images for
@@ -11,7 +11,7 @@
1111
% addResponseMessage - Add a response message.
1212
% removeMessage - Remove message from history.
1313
%
14-
% openAIMessages properties:
14+
% messageHistory properties:
1515
% Messages - Messages in the conversation history.
1616

1717
% Copyright 2023-2024 The MathWorks, Inc.
@@ -31,7 +31,7 @@
3131
%
3232
% Example:
3333
% % Create messages object
34-
% messages = openAIMessages;
34+
% messages = messageHistory;
3535
%
3636
% % Add system messages to provide examples of the conversation
3737
% messages = addSystemMessage(messages, "example_user", "Hello, how are you?");
@@ -40,7 +40,7 @@
4040
% messages = addSystemMessage(messages, "example_assistant", "O céu está lindo hoje.");
4141

4242
arguments
43-
this (1,1) openAIMessages
43+
this (1,1) messageHistory
4444
name {mustBeNonzeroLengthTextScalar}
4545
content {mustBeNonzeroLengthTextScalar}
4646
end
@@ -57,13 +57,13 @@
5757
%
5858
% Example:
5959
% % Create messages object
60-
% messages = openAIMessages;
60+
% messages = messageHistory;
6161
%
6262
% % Add user message
6363
% messages = addUserMessage(messages, "Where is Natick located?");
6464

6565
arguments
66-
this (1,1) openAIMessages
66+
this (1,1) messageHistory
6767
content {mustBeNonzeroLengthTextScalar}
6868
end
6969

@@ -94,7 +94,7 @@
9494
% chat = openAIChat("You are an AI assistant.", ModelName="gpt-4-vision-preview");
9595
%
9696
% % Create messages object
97-
% messages = openAIMessages;
97+
% messages = messageHistory;
9898
%
9999
% % Add user message with an image
100100
% content = "What is in this picture?"
@@ -105,7 +105,7 @@
105105
% [text, response] = generate(chat, messages, MaxNumTokens=300);
106106

107107
arguments
108-
this (1,1) openAIMessages
108+
this (1,1) messageHistory
109109
content {mustBeNonzeroLengthTextScalar}
110110
images (1,:) {mustBeNonzeroLengthText}
111111
nvp.Detail string {mustBeMember(nvp.Detail,["low","high","auto"])} = "auto"
@@ -148,14 +148,14 @@
148148
%
149149
% Example:
150150
% % Create messages object
151-
% messages = openAIMessages;
151+
% messages = messageHistory;
152152
%
153153
% % Add function message, containing the result of
154154
% % calling strcat("Hello", " World")
155155
% messages = addToolMessage(messages, "call_123", "strcat", "Hello World");
156156

157157
arguments
158-
this (1,1) openAIMessages
158+
this (1,1) messageHistory
159159
id {mustBeNonzeroLengthTextScalar}
160160
name {mustBeNonzeroLengthTextScalar}
161161
content {mustBeNonzeroLengthTextScalar}
@@ -182,7 +182,7 @@
182182
% chat = openAIChat("You are a helpful AI Assistant.");
183183
%
184184
% % Create messages object
185-
% messages = openAIMessages;
185+
% messages = messageHistory;
186186
%
187187
% % Add user message
188188
% messages = addUserMessage(messages, "What is the capital of England?");
@@ -194,7 +194,7 @@
194194
% messages = addResponseMessage(messages, response);
195195

196196
arguments
197-
this (1,1) openAIMessages
197+
this (1,1) messageHistory
198198
messageStruct (1,1) struct
199199
end
200200

@@ -223,7 +223,7 @@
223223
% Example:
224224
%
225225
% % Create messages object
226-
% messages = openAIMessages;
226+
% messages = messageHistory;
227227
%
228228
% % Add user messages
229229
% messages = addUserMessage(messages, "What is the capital of England?");
@@ -233,7 +233,7 @@
233233
% messages = removeMessage(messages,1);
234234

235235
arguments
236-
this (1,1) openAIMessages
236+
this (1,1) messageHistory
237237
idx (1,1) {mustBeInteger, mustBePositive}
238238
end
239239
if idx>numel(this.Messages)
@@ -247,7 +247,7 @@
247247

248248
function this = addAssistantMessage(this, content, toolCalls)
249249
arguments
250-
this (1,1) openAIMessages
250+
this (1,1) messageHistory
251251
content string
252252
toolCalls struct = []
253253
end

ollamaChat.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
end
188188

189189
function mustBeValidMsgs(value)
190-
if isa(value, "openAIMessages")
190+
if isa(value, "messageHistory")
191191
if numel(value.Messages) == 0
192192
error("llms:mustHaveMessages", llms.utils.errorMessageCatalog.getMessage("llms:mustHaveMessages"));
193193
end

openAIChat.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function mustBeNonzeroLengthTextScalar(content)
249249
end
250250

251251
function mustBeValidMsgs(value)
252-
if isa(value, "openAIMessages")
252+
if isa(value, "messageHistory")
253253
if numel(value.Messages) == 0
254254
error("llms:mustHaveMessages", llms.utils.errorMessageCatalog.getMessage("llms:mustHaveMessages"));
255255
end

0 commit comments

Comments
 (0)