Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

little bit of code reformatting #36

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 16 additions & 60 deletions openAIChat.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@

properties
%TEMPERATURE Temperature of generation.
Temperature
Temperature {mustBeValidTemperature} = 1

%TOPPROBABILITYMASS Top probability mass to consider for generation.
TopProbabilityMass
TopProbabilityMass {mustBeValidTopP} = 1

%STOPSEQUENCES Sequences to stop the generation of tokens.
StopSequences
StopSequences {mustBeValidStop} = {}

%PRESENCEPENALTY Penalty for using a token in the response that has already been used.
PresencePenalty
PresencePenalty {mustBeValidPenalty} = 0

%FREQUENCYPENALTY Penalty for using a token that is frequent in the training data.
FrequencyPenalty
FrequencyPenalty {mustBeValidPenalty} = 0
end

properties(SetAccess=private)
Expand Down Expand Up @@ -114,11 +114,13 @@
arguments
systemPrompt {llms.utils.mustBeTextOrEmpty} = []
nvp.Tools (1,:) {mustBeA(nvp.Tools, "openAIFunction")} = openAIFunction.empty
nvp.ModelName (1,1) {mustBeMember(nvp.ModelName,["gpt-4o", ...
"gpt-4o-2024-05-13","gpt-4-turbo", ...
"gpt-4-turbo-2024-04-09","gpt-4","gpt-4-0613", ...
"gpt-3.5-turbo","gpt-3.5-turbo-0125", ...
"gpt-3.5-turbo-1106"])} = "gpt-3.5-turbo"
nvp.ModelName (1,1) string {mustBeMember(nvp.ModelName,[...
"gpt-4o","gpt-4o-2024-05-13",...
"gpt-4-turbo","gpt-4-turbo-2024-04-09",...
"gpt-4","gpt-4-0613", ...
"gpt-3.5-turbo","gpt-3.5-turbo-0125", ...
"gpt-3.5-turbo-1106",...
])} = "gpt-3.5-turbo"
nvp.Temperature {mustBeValidTemperature} = 1
nvp.TopProbabilityMass {mustBeValidTopP} = 1
nvp.StopSequences {mustBeValidStop} = {}
Expand Down Expand Up @@ -147,7 +149,7 @@

if ~isempty(systemPrompt)
systemPrompt = string(systemPrompt);
if ~(strlength(systemPrompt)==0)
if systemPrompt ~= ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or if ~isempty(systemPrompt )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeps being tempting, but it's not the same thing. Strings are “proper” matrices, and a scalar can't be empty.

>> isempty("")

ans =

  logical

   0

this.SystemPrompt = {struct("role", "system", "content", systemPrompt)};
end
end
Expand All @@ -158,7 +160,7 @@
this.StopSequences = nvp.StopSequences;

% ResponseFormat is only supported in the latest models only
if (nvp.ResponseFormat == "json")
if nvp.ResponseFormat == "json"
if ismember(this.ModelName,["gpt-4","gpt-4-0613"])
error("llms:invalidOptionAndValueForModel", ...
llms.utils.errorMessageCatalog.getMessage("llms:invalidOptionAndValueForModel", "ResponseFormat", "json", this.ModelName));
Expand Down Expand Up @@ -243,52 +245,6 @@
end

end

function this = set.Temperature(this, temperature)
arguments
this openAIChat
temperature
end
mustBeValidTemperature(temperature);

this.Temperature = temperature;
end

function this = set.TopProbabilityMass(this,topP)
arguments
this openAIChat
topP
end
mustBeValidTopP(topP);
this.TopProbabilityMass = topP;
end

function this = set.StopSequences(this,stop)
arguments
this openAIChat
stop
end
mustBeValidStop(stop);
this.StopSequences = stop;
end

function this = set.PresencePenalty(this,penalty)
arguments
this openAIChat
penalty
end
mustBeValidPenalty(penalty)
this.PresencePenalty = penalty;
end

function this = set.FrequencyPenalty(this,penalty)
arguments
this openAIChat
penalty
end
mustBeValidPenalty(penalty)
this.FrequencyPenalty = penalty;
end
end

methods(Hidden)
Expand Down Expand Up @@ -331,7 +287,7 @@ function mustBeNonzeroLengthTextScalar(content)

for i = 1:numFunctions
functionsStruct{i} = struct('type','function', ...
'function',encodeStruct(functions(i))) ;
'function',encodeStruct(functions(i)));
functionNames(i) = functions(i).FunctionName;
end
end
Expand Down Expand Up @@ -377,4 +333,4 @@ function mustBeIntegerOrEmpty(value)
if ~isempty(value)
mustBeInteger(value)
end
end
end