Skip to content

Commit 8a2ea28

Browse files
committed
Remove GPT specific penalties from ollamaChat
1 parent cd9bbe2 commit 8a2ea28

File tree

9 files changed

+36
-62
lines changed

9 files changed

+36
-62
lines changed

+llms/+internal/callAzureChatAPI.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function [text, message, response] = callAzureChatAPI(endpoint, deploymentID, messages, functions, nvp)
2+
% This function is undocumented and will change in a future release
3+
24
%callAzureChatAPI Calls the openAI chat completions API on Azure.
35
%
46
% MESSAGES and FUNCTIONS should be structs matching the json format

+llms/+internal/callOllamaChatAPI.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function [text, message, response] = callOllamaChatAPI(model, messages, nvp)
2+
% This function is undocumented and will change in a future release
3+
24
%callOllamaChatAPI Calls the ollama chat completions API.
35
%
46
% MESSAGES and FUNCTIONS should be structs matching the json format

+llms/+internal/callOpenAIChatAPI.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
function [text, message, response] = callOpenAIChatAPI(messages, functions, nvp)
2+
% This function is undocumented and will change in a future release
3+
24
%callOpenAIChatAPI Calls the openAI chat completions API.
35
%
46
% MESSAGES and FUNCTIONS should be structs matching the json format

+llms/+internal/gptPenalties.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
classdef (Abstract) gptPenalties
2+
% This class is undocumented and will change in a future release
3+
4+
% Copyright 2024 The MathWorks, Inc.
5+
properties
6+
%PRESENCEPENALTY Penalty for using a token in the response that has already been used.
7+
PresencePenalty {llms.utils.mustBeValidPenalty} = 0
8+
9+
%FREQUENCYPENALTY Penalty for using a token that is frequent in the training data.
10+
FrequencyPenalty {llms.utils.mustBeValidPenalty} = 0
11+
end
12+
end

+llms/+internal/sendRequest.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
function [response, streamedText] = sendRequest(parameters, token, endpoint, timeout, streamFun)
2+
% This function is undocumented and will change in a future release
3+
24
%sendRequest Sends a request to an ENDPOINT using PARAMETERS and
35
% api key TOKEN. TIMEOUT is the number of seconds to wait for initial
46
% server connection. STREAMFUN is an optional callback function.
57

6-
% Copyright 2023 The MathWorks, Inc.
8+
% Copyright 2023-2024 The MathWorks, Inc.
79

810
arguments
911
parameters

+llms/+internal/textGenerator.m

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
classdef (Abstract) textGenerator
2-
%
2+
% This class is undocumented and will change in a future release
33

44
% Copyright 2023-2024 The MathWorks, Inc.
55

@@ -12,12 +12,6 @@
1212

1313
%STOPSEQUENCES Sequences to stop the generation of tokens.
1414
StopSequences {llms.utils.mustBeValidStop} = {}
15-
16-
%PRESENCEPENALTY Penalty for using a token in the response that has already been used.
17-
PresencePenalty {llms.utils.mustBeValidPenalty} = 0
18-
19-
%FREQUENCYPENALTY Penalty for using a token that is frequent in the training data.
20-
FrequencyPenalty {llms.utils.mustBeValidPenalty} = 0
2115
end
2216

2317
properties (SetAccess=protected)

azureChat.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
classdef(Sealed) azureChat < llms.internal.textGenerator
1+
classdef(Sealed) azureChat < llms.internal.textGenerator & llms.internal.gptPenalties
22
%azureChat Chat completion API from Azure.
33
%
44
% CHAT = azureChat(endpoint, deploymentID) creates an azureChat object with the

ollamaChat.m

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@
1313
% of the output. Default value depends on the model;
1414
% if not specified in the model, defaults to 0.8.
1515
%
16-
% TODO: TopK and TopP, how do they relate to this?
1716
% TopProbabilityMass - Top probability mass value for controlling the
18-
% diversity of the output. Default value is 1.
17+
% diversity of the output. Default value is 1; with
18+
% smaller value TopProbabilityMass=p, only the most
19+
% probable tokens up to a cumulative probability p
20+
% are used.
21+
%
22+
% TopProbabilityNum - Maximum number of most likely tokens that are
23+
% considered for output. Default is Inf, allowing
24+
% all tokens. Smaller values reduce diversity in
25+
% the output.
1926
%
2027
% StopSequences - Vector of strings that when encountered, will
2128
% stop the generation of tokens. Default
@@ -24,8 +31,6 @@
2431
% ResponseFormat - The format of response the model returns.
2532
% "text" (default) | "json"
2633
%
27-
% Seed - TODO: Seems to have no effect whatsoever (tested via curl) - cf. https://github.com/ollama/ollama/issues/4660
28-
%
2934
% Mirostat - 0/1/2, eta, tau
3035
%
3136
% RepeatLastN - find a better name! “Sets how far back for the model to look back to prevent repetition. (Default: 64, 0 = disabled, -1 = num_ctx)”
@@ -34,8 +39,6 @@
3439
%
3540
% TailFreeSamplingZ
3641
%
37-
% MaxNumTokens
38-
%
3942
% StreamFun - Function to callback when streaming the
4043
% result
4144
%
@@ -48,18 +51,14 @@
4851
% generate - Generate a response using the ollamaChat instance.
4952
%
5053
% ollamaChat Properties: TODO TODO
54+
% Model - Model name (as expected by ollama server)
55+
%
5156
% Temperature - Temperature of generation.
5257
%
5358
% TopProbabilityMass - Top probability mass to consider for generation.
5459
%
5560
% StopSequences - Sequences to stop the generation of tokens.
5661
%
57-
% PresencePenalty - Penalty for using a token in the
58-
% response that has already been used.
59-
%
60-
% FrequencyPenalty - Penalty for using a token that is
61-
% frequent in the training data.
62-
%
6362
% SystemPrompt - System prompt.
6463
%
6564
% ResponseFormat - Specifies the response format, text or json
@@ -159,52 +158,13 @@
159158
TimeOut=this.TimeOut, StreamFun=this.StreamFun);
160159
end
161160
end
162-
163-
methods(Hidden)
164-
function mustBeValidFunctionCall(this, functionCall)
165-
if ~isempty(functionCall)
166-
mustBeTextScalar(functionCall);
167-
if isempty(this.FunctionNames)
168-
error("llms:mustSetFunctionsForCall", llms.utils.errorMessageCatalog.getMessage("llms:mustSetFunctionsForCall"));
169-
end
170-
mustBeMember(functionCall, ["none","auto", this.FunctionNames]);
171-
end
172-
end
173-
174-
function toolChoice = convertToolChoice(this, toolChoice)
175-
% if toolChoice is empty
176-
if isempty(toolChoice)
177-
% if Tools is not empty, the default is 'auto'.
178-
if ~isempty(this.Tools)
179-
toolChoice = "auto";
180-
end
181-
elseif ToolChoice ~= "auto"
182-
% if toolChoice is not empty, then it must be in the format
183-
% {"type": "function", "function": {"name": "my_function"}}
184-
toolChoice = struct("type","function","function",struct("name",toolChoice));
185-
end
186-
187-
end
188-
end
189161
end
190162

191163
function mustBeNonzeroLengthTextScalar(content)
192164
mustBeNonzeroLengthText(content)
193165
mustBeTextScalar(content)
194166
end
195167

196-
function [functionsStruct, functionNames] = functionAsStruct(functions)
197-
numFunctions = numel(functions);
198-
functionsStruct = cell(1, numFunctions);
199-
functionNames = strings(1, numFunctions);
200-
201-
for i = 1:numFunctions
202-
functionsStruct{i} = struct('type','function', ...
203-
'function',encodeStruct(functions(i))) ;
204-
functionNames(i) = functions(i).FunctionName;
205-
end
206-
end
207-
208168
function mustBeValidMsgs(value)
209169
if isa(value, "openAIMessages")
210170
if numel(value.Messages) == 0
@@ -223,4 +183,4 @@ function mustBeIntegerOrEmpty(value)
223183
if ~isempty(value)
224184
mustBeInteger(value)
225185
end
226-
end
186+
end

openAIChat.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
classdef(Sealed) openAIChat < llms.internal.textGenerator
1+
classdef(Sealed) openAIChat < llms.internal.textGenerator & llms.internal.gptPenalties
22
%openAIChat Chat completion API from OpenAI.
33
%
44
% CHAT = openAIChat(systemPrompt) creates an openAIChat object with the

0 commit comments

Comments
 (0)