|
8 | 8 | % Ref: https://platform.openai.com/docs/guides/gpt/chat-completions-api |
9 | 9 | % |
10 | 10 | % Currently, the supported NVP are, including the equivalent name in the API: |
11 | | -% - FunctionCall (function_call) |
| 11 | +% - ToolChoice (tool_choice) |
12 | 12 | % - ModelName (model) |
13 | 13 | % - Temperature (temperature) |
14 | 14 | % - TopProbabilityMass (top_p) |
|
17 | 17 | % - MaxNumTokens (max_tokens) |
18 | 18 | % - PresencePenalty (presence_penalty) |
19 | 19 | % - FrequencyPenalty (frequence_penalty) |
| 20 | +% - ResponseFormat (response_format) |
| 21 | +% - Seed (seed) |
20 | 22 | % - ApiKey |
21 | 23 | % - TimeOut |
22 | 24 | % - StreamFun |
|
55 | 57 | arguments |
56 | 58 | messages |
57 | 59 | functions |
58 | | - nvp.FunctionCall = [] |
| 60 | + nvp.ToolChoice = [] |
59 | 61 | nvp.ModelName = "gpt-3.5-turbo" |
60 | 62 | nvp.Temperature = 1 |
61 | 63 | nvp.TopProbabilityMass = 1 |
|
64 | 66 | nvp.MaxNumTokens = inf |
65 | 67 | nvp.PresencePenalty = 0 |
66 | 68 | nvp.FrequencyPenalty = 0 |
| 69 | + nvp.ResponseFormat = "text" |
| 70 | + nvp.Seed = [] |
67 | 71 | nvp.ApiKey = "" |
68 | 72 | nvp.TimeOut = 10 |
69 | 73 | nvp.StreamFun = [] |
|
85 | 89 | message = struct("role", "assistant", ... |
86 | 90 | "content", streamedText); |
87 | 91 | end |
88 | | - if isfield(message, "function_call") |
| 92 | + if isfield(message, "tool_choice") |
89 | 93 | text = ""; |
90 | 94 | else |
91 | 95 | text = string(message.content); |
|
105 | 109 |
|
106 | 110 | parameters.stream = ~isempty(nvp.StreamFun); |
107 | 111 |
|
108 | | -if ~isempty(functions) |
109 | | - parameters.functions = functions; |
| 112 | +if ~isempty(functions) && ~strcmp(nvp.ModelName,'gpt-4-vision-preview') |
| 113 | + parameters.tools = functions; |
110 | 114 | end |
111 | 115 |
|
112 | | -if ~isempty(nvp.FunctionCall) |
113 | | - parameters.function_call = nvp.FunctionCall; |
| 116 | +if ~isempty(nvp.ToolChoice) && ~strcmp(nvp.ModelName,'gpt-4-vision-preview') |
| 117 | + parameters.tool_choice = nvp.ToolChoice; |
| 118 | +end |
| 119 | + |
| 120 | +if ismember(nvp.ModelName,["gpt-3.5-turbo-1106","gpt-4-1106-preview"]) |
| 121 | + if strcmp(nvp.ResponseFormat,"json") |
| 122 | + parameters.response_format = struct('type','json_object'); |
| 123 | + end |
| 124 | +end |
| 125 | + |
| 126 | +if ~isempty(nvp.Seed) |
| 127 | + parameters.seed = nvp.Seed; |
114 | 128 | end |
115 | 129 |
|
116 | 130 | parameters.model = nvp.ModelName; |
117 | 131 |
|
118 | 132 | dict = mapNVPToParameters; |
119 | 133 |
|
120 | 134 | nvpOptions = keys(dict); |
| 135 | +if strcmp(nvp.ModelName,'gpt-4-vision-preview') |
| 136 | + nvpOptions(ismember(nvpOptions,["MaxNumTokens","StopSequences"])) = []; |
| 137 | +end |
| 138 | + |
121 | 139 | for i=1:length(nvpOptions) |
122 | 140 | if isfield(nvp, nvpOptions(i)) |
123 | 141 | parameters.(dict(nvpOptions(i))) = nvp.(nvpOptions(i)); |
|
0 commit comments