Skip to content

Commit b270c1a

Browse files
committed
Fixing text, m-help and README.
1 parent 3c99406 commit b270c1a

File tree

6 files changed

+49
-53
lines changed

6 files changed

+49
-53
lines changed

README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ This repository contains example code to demonstrate how to connect MATLAB to th
44

55
The functionality shown here serves as an interface to the ChatGPT API. To start using the ChatGPT API, you first need to obtain the OpenAI API keys. You are responsible for any fees OpenAI may charge for the use of their API. You should be familiar with the limitations and risks associated with using this technology, and you agree that you shall be solely responsible for full compliance with any terms that may apply to your use of the OpenAI Chat Completions API.
66

7-
The current LLMs supported are:
7+
Some of the current LLMs supported are:
88
- gpt-3.5-turbo
9-
- gpt-3.5-turbo-0613
10-
- gpt-3.5-turbo-16k
11-
- gpt-3.5-turbo-16k-0613
129
- gpt-4
13-
- gpt-4-0613
14-
- gpt-4-32k
15-
- gpt-4-32k-0613
1610

1711
For details on the specification of each model, check the official [OpenAI documentation](https://platform.openai.com/docs/models).
1812

1913
## Setup
14+
15+
If you would like to use this repository with MATLAB Online, simply click [![Open in MATLAB Online](https://www.mathworks.com/images/responsive/global/open-in-matlab-online.svg)](https://matlab.mathworks.com/open/github/v1?repo=matlab-deep-learning/llms-with-matlab)
16+
17+
If you would like to use it with MATLAB Desktop, proceed with the following steps:
18+
2019
1. Clone the repository to your local machine.
2120

2221
```bash
@@ -42,7 +41,6 @@ For details on the specification of each model, check the official [OpenAI docum
4241
loadenv(filename)
4342
```
4443

45-
4644
### MathWorks Products (https://www.mathworks.com)
4745

4846
- Requires MATLAB release R2023a or newer.

examples/ExampleBasicUsage.mlx

-2.75 KB
Binary file not shown.

examples/ExampleSummarization.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
% piece of text extracted from a webpage hosted by MathWorks.
77

88
% Initiating a ChatGPT session with the role defined as a professional summarizer
9-
chat = openAIChat("You are a professional summarizer, create a summary of the provided text, be it an article, post, conversation, or passage.");
10-
9+
chat = openAIChat("You are a professional summarizer, create a summary of the provided text, be it an article," + ...
10+
" post, conversation, or passage.");
1111

1212
url = "https://www.mathworks.com/help/textanalytics";
1313
code = webread(url);
@@ -19,11 +19,11 @@
1919
%% Summarizing large documents
2020
% This section of the script demonstrates how to incrementally summarize a large text
2121
% by breaking it into smaller chunks and summarizing each chunk step by
22-
% step. It uses as input text Romeo and Juliet, by William Shakespeare,
23-
% from The Project Gutenberg.
22+
% step. It uses as input text Alice's Adventures in Wonderland by
23+
% Lewis Carroll from Project Gutenberg.
2424

2525
options = weboptions(Timeout=30);
26-
code = webread("https://www.gutenberg.org/files/1513/1513-h/1513-h.htm", options);
26+
code = webread("https://www.gutenberg.org/files/11/11-h/11-h.htm", options);
2727
longText = extractHTMLText(string(code));
2828

2929
incrementalSummary = longText;

openAIChat.m

+19-20
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@
44
% CHAT = openAIChat(systemPrompt) creates an openAIChat object with the
55
% specified system prompt.
66
%
7-
% CHAT = openAIChat(systemPrompt, Name=Value) specifies additional options
7+
% CHAT = openAIChat(systemPrompt,ApiKey=key) uses the specified API key
8+
%
9+
% CHAT = openAIChat(systemPrompt,Name=Value) specifies additional options
810
% using one or more name-value arguments:
911
%
10-
% 'Functions' - An array of openAIFunction objects representing
12+
% Functions - Array of openAIFunction objects representing
1113
% custom functions to be used during chat completions.
1214
%
13-
% 'ModelName' - The name of the model to use for chat completions.
15+
% ModelName - Name of the model to use for chat completions.
1416
% The default value is "gpt-3.5-turbo".
1517
%
16-
% 'Temperature' - The temperature value for controlling the randomness
17-
% of the output. The default value is 1.
18+
% Temperature - Temperature value for controlling the randomness
19+
% of the output. Default value is 1.
1820
%
19-
% 'TopProbabilityMass' - The top probability mass value for controlling the
20-
% diversity of the output. The default value is 1.
21+
% TopProbabilityMass - Top probability mass value for controlling the
22+
% diversity of the output. Default value is 1.
2123
%
22-
% 'StopSequences' - Vector of strings that when encountered, will
23-
% stop the generation of tokens. The default
24+
% StopSequences - Vector of strings that when encountered, will
25+
% stop the generation of tokens. Default
2426
% value is empty.
2527
%
26-
% 'ApiKey' - The API key for accessing the OpenAI Chat API.
27-
%
28-
% 'PresencePenalty' - The penalty value for using a token in the response
29-
% that has already been used. The default value is 0.
28+
% PresencePenalty - Penalty value for using a token in the response
29+
% that has already been used. Default value is 0.
3030
%
31-
% 'FrequencyPenalty' - The penalty value for using a token that is frequent
32-
% in the training data. The default value is 0.
31+
% FrequencyPenalty - Penalty value for using a token that is frequent
32+
% in the training data. Default value is 0.
3333
%
3434
% openAIChat Functions:
3535
% openAIChat - Chat completion API from OpenAI.
@@ -145,20 +145,19 @@
145145
%generate Generate a response using the openAIChat instance.
146146
%
147147
% [TEXT, MESSAGE, RESPONSE] = generate(CHAT, MESSAGES) generates a response
148-
% with the specified MESSAGES and optional
149-
% name-value pair arguments.
148+
% with the specified MESSAGES.
150149
%
151150
% [TEXT, MESSAGE, RESPONSE] = generate(__, Name=Value) specifies additional options
152151
% using one or more name-value arguments:
153152
%
154153
% NumCompletions - Number of completions to generate.
155-
% The default value is 1.
154+
% Default value is 1.
156155
%
157156
% MaxNumTokens - Maximum number of tokens in the generated response.
158-
% The default value is inf.
157+
% Default value is inf.
159158
%
160159
% FunctionCall - Function call to execute before generating the
161-
% response. The default value is empty.
160+
% response, specified as a string array. Default value is empty.
162161

163162
arguments
164163
this (1,1) openAIChat

openAIFunction.m

+15-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
%openAIFunction Define a function
33
%
44
% FUNC = openAIFunction(NAME, DESCRIPTION) creates an open AI function
5-
% object with the specified NAME and DESCRIPTION.
5+
% object with the specified name and description.
66
%
77
% openAIFunction Functions:
88
% openAIFunction - Define a function.
@@ -48,28 +48,27 @@
4848
function this = addParameter(this, parameterName, propertyName, propertyValue, nvp)
4949
%addParameter Add parameter to the function
5050
%
51-
% FUNC = addParameter(FUNC, parameterName, propertyName, propertyValue)
52-
% adds a parameter to the function signature with name parameterName and
53-
% property propertyName with value propertyValue. Inputs propertyName and
54-
% propertyValue can be specified repeatedly. The values
55-
% accepted for propertyNames are "type", "description" and
56-
% "enum". Each propertyName will accept different values
57-
% for propertyValue:
58-
% - type: accepts "string", "number", "integer", "object", "boolean",
59-
% "null" and any combination of those values.
60-
% - description: accepts text scalar.
61-
% - enum: accepts string vectors of text.
51+
% FCN = addParameter(FCN,paramName,propName1,value1, ..., propNameN,valueN)
52+
% adds the specified parameter and corresponding property names and values to the
53+
% function signature. The property names must be
54+
% "type", "description", or "enum".
55+
% The values depend on the property name:
56+
% - Values corresponding to "type" must be any combination of "string",
57+
% "number", "integer", "object", "boolean", "null".
58+
% - Values corresponding to "description" must be a string scalar.
59+
% - Value corresponging to "enum" must be string vectors.
6260
%
63-
% FUNC = addParameter(__, RequiredParameter=TF), specifies
64-
% if the parameter is required.
61+
% FCN = addParameter(__,RequiredParameter=TF), specifies
62+
% if the parameter is a required parameter.
6563
%
6664
% Example:
6765
% % Create an OpenAI function object
6866
% f = openAIFunction("editDistance", "Find edit distance between two strings or documents");
6967
%
7068
% % Add two parameters with type and description
71-
% f = addParameter(f, "str1", type="string", description="Source string.");
72-
% f = addParameter(f, "str2", type="string", description="Target string.");
69+
% f = addParameter(f,"str1","type","string","description","Source string.");
70+
% f = addParameter(f,"str2","type","string" ,"description","Target string.");
71+
7372

7473
arguments
7574
this (1,1) openAIFunction

openAIMessages.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
%addSystemMessage Add system message.
2525
%
2626
% MESSAGES = addSystemMessage(MESSAGES, NAME, CONTENT) adds a system
27-
% message with the specified NAME and CONTENT. NAME and CONTENT
27+
% message with the specified name and content. NAME and CONTENT
2828
% must be text scalars.
2929
%
3030
% Example:
@@ -51,7 +51,7 @@
5151
%addUserMessage Add user message.
5252
%
5353
% MESSAGES = addUserMessage(MESSAGES, CONTENT) adds a user message
54-
% with the specified CONTENT to MESSAGES. CONTENT must be a text scalar.
54+
% with the specified content to MESSAGES. CONTENT must be a text scalar.
5555
%
5656
% Example:
5757
% % Create messages object
@@ -73,7 +73,7 @@
7373
%addFunctionMessage Add function message.
7474
%
7575
% MESSAGES = addFunctionMessage(MESSES, NAME, CONTENT) adds a function
76-
% message with the specified NAME and CONTENT. NAME and
76+
% message with the specified name and content. NAME and
7777
% CONTENT must be text scalars.
7878
%
7979
% Example:
@@ -145,7 +145,7 @@
145145
%removeMessage Remove message.
146146
%
147147
% MESSAGES = removeMessage(MESSAGES, IDX) removes a message at the specified
148-
% IDX from MESSAGES. IDX must be a positive integer.
148+
% index from MESSAGES. IDX must be a positive integer.
149149
%
150150
% Example:
151151
%

0 commit comments

Comments
 (0)