@ai-sdk/openai 4.0.105 → 4.0.106

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,196 +0,0 @@
1
- import type {
2
- LanguageModelV4CallOptions,
3
- SharedV4Warning,
4
- } from '@ai-sdk/provider';
5
- import { mapReasoningToProviderEffort } from '@ai-sdk/provider-utils';
6
-
7
- type OpenAIReasoningEffort = Exclude<
8
- LanguageModelV4CallOptions['reasoning'],
9
- 'provider-default' | undefined
10
- >;
11
-
12
- // Unknown model families send the reasoning value directly.
13
- const ALL_OPENAI_REASONING_EFFORTS: readonly OpenAIReasoningEffort[] = [
14
- 'none',
15
- 'minimal',
16
- 'low',
17
- 'medium',
18
- 'high',
19
- 'xhigh',
20
- 'max',
21
- ];
22
-
23
- export type OpenAILanguageModelCapabilities = {
24
- isReasoningModel: boolean;
25
- systemMessageMode: 'remove' | 'system' | 'developer';
26
- supportsFlexProcessing: boolean;
27
- supportsPriorityProcessing: boolean;
28
- supportsConfigurationUpdate: boolean;
29
- supportsAsyncToolCalling: boolean;
30
- /**
31
- * Reasoning efforts supported by the model family, or `undefined` when they
32
- * are not known.
33
- */
34
- supportedReasoningEfforts: readonly OpenAIReasoningEffort[] | undefined;
35
-
36
- /**
37
- * Whether function tools can be combined with a reasoning effort other than
38
- * `none` in the Chat Completions API.
39
- */
40
- supportsChatFunctionToolsWithReasoning: boolean;
41
-
42
- /**
43
- * Allow temperature, topP, logProbs when reasoningEffort is none.
44
- */
45
- supportsNonReasoningParameters: boolean;
46
- };
47
-
48
- export function getOpenAILanguageModelCapabilities(
49
- modelId: string,
50
- ): OpenAILanguageModelCapabilities {
51
- const oSeriesVersion = getOSeriesVersion(modelId);
52
- const gptVersion = getGptVersion(modelId);
53
- const isGptChatModel =
54
- gptVersion?.minor == null &&
55
- (gptVersion?.variant?.startsWith('chat') ?? false);
56
- const isGptNanoModel = gptVersion?.variant?.startsWith('nano') ?? false;
57
- const isGpt6OrLaterModel = gptVersion != null && gptVersion.major >= 6;
58
-
59
- // Pro, codex, and chat variants are excluded because their supported
60
- // efforts are not known.
61
- const isStandardGpt5Model =
62
- gptVersion?.major === 5 &&
63
- (gptVersion.variant == null ||
64
- /^(?:(?:mini|nano|sol|luna|terra)(?:-\d{4}-\d{2}-\d{2})?|\d{4}-\d{2}-\d{2})$/.test(
65
- gptVersion.variant,
66
- ));
67
-
68
- const isGpt6OrLaterModelWithNoneEffort =
69
- modelId === 'gpt-6-sol' ||
70
- modelId === 'gpt-6-luna' ||
71
- modelId === 'gpt-6.1-terra';
72
-
73
- const supportsFlexProcessing =
74
- (oSeriesVersion != null && oSeriesVersion >= 3) ||
75
- (gptVersion != null && gptVersion.major >= 5 && !isGptChatModel);
76
-
77
- const supportsPriorityProcessing =
78
- modelId.startsWith('gpt-4') ||
79
- (gptVersion != null &&
80
- gptVersion.major >= 5 &&
81
- !isGptNanoModel &&
82
- !isGptChatModel) ||
83
- (oSeriesVersion != null && oSeriesVersion >= 3);
84
-
85
- // Only recognizable OpenAI model families should use the developer role.
86
- // Fine-tuned, third-party, and custom model IDs keep conservative defaults.
87
- const isReasoningModel =
88
- oSeriesVersion != null ||
89
- (gptVersion != null && gptVersion.major >= 5 && !isGptChatModel);
90
-
91
- // https://platform.openai.com/docs/guides/latest-model#gpt-5-1-parameter-compatibility
92
- // GPT-5.1 through GPT-5.x, GPT-6 Sol/Luna, and GPT-6.1 Terra support
93
- // temperature, topP, and logProbs when reasoningEffort is none.
94
- const supportsNonReasoningParameters =
95
- isGpt6OrLaterModelWithNoneEffort ||
96
- (!isGpt6OrLaterModel &&
97
- gptVersion != null &&
98
- (gptVersion.major > 5 ||
99
- (gptVersion.major === 5 && (gptVersion.minor ?? 0) >= 1)));
100
-
101
- const systemMessageMode = isReasoningModel ? 'developer' : 'system';
102
-
103
- return {
104
- supportsFlexProcessing,
105
- supportsPriorityProcessing,
106
- supportsConfigurationUpdate: isGpt6OrLaterModel,
107
- supportsAsyncToolCalling: isGpt6OrLaterModel,
108
- supportedReasoningEfforts: isGpt6OrLaterModelWithNoneEffort
109
- ? ['none', 'low', 'medium', 'high', 'xhigh', 'max']
110
- : isGpt6OrLaterModel
111
- ? ['low', 'medium', 'high', 'xhigh', 'max']
112
- : isStandardGpt5Model
113
- ? getGpt5ReasoningEfforts(gptVersion.minor ?? 0)
114
- : undefined,
115
- // GPT-5.6 rejects function tools with reasoning in the Chat Completions API.
116
- supportsChatFunctionToolsWithReasoning: !(
117
- gptVersion?.major === 5 && (gptVersion.minor ?? 0) >= 6
118
- ),
119
- isReasoningModel,
120
- systemMessageMode,
121
- supportsNonReasoningParameters,
122
- };
123
- }
124
-
125
- function getGpt5ReasoningEfforts(
126
- minor: number,
127
- ): readonly OpenAIReasoningEffort[] {
128
- if (minor === 0) {
129
- return ['minimal', 'low', 'medium', 'high'];
130
- }
131
-
132
- if (minor === 1) {
133
- return ['none', 'low', 'medium', 'high'];
134
- }
135
-
136
- if (minor < 6) {
137
- return ['none', 'low', 'medium', 'high', 'xhigh'];
138
- }
139
-
140
- return ['none', 'low', 'medium', 'high', 'xhigh', 'max'];
141
- }
142
-
143
- function getOSeriesVersion(modelId: string): number | undefined {
144
- const match = /^o(\d+)(?:-|$)/.exec(modelId);
145
- return match == null ? undefined : Number(match[1]);
146
- }
147
-
148
- function getGptVersion(modelId: string):
149
- | {
150
- major: number;
151
- minor: number | undefined;
152
- variant: string | undefined;
153
- }
154
- | undefined {
155
- const match = /^gpt-(\d+)(?:\.(\d+))?(?:-(.+))?$/.exec(modelId);
156
-
157
- if (match == null) {
158
- return undefined;
159
- }
160
-
161
- return {
162
- major: Number(match[1]),
163
- minor: match[2] == null ? undefined : Number(match[2]),
164
- variant: match[3],
165
- };
166
- }
167
-
168
- /**
169
- * Resolves the reasoning effort to send to OpenAI.
170
- *
171
- * A reasoning effort from provider options is sent unchanged. Otherwise the
172
- * top-level reasoning value is mapped to the closest effort that the model
173
- * family supports, or sent directly when the supported efforts are not known.
174
- */
175
- export function resolveOpenAIReasoningEffort({
176
- providerReasoningEffort,
177
- reasoning,
178
- supportedReasoningEfforts,
179
- warnings,
180
- }: {
181
- providerReasoningEffort: string | null | undefined;
182
- reasoning: LanguageModelV4CallOptions['reasoning'];
183
- supportedReasoningEfforts: readonly OpenAIReasoningEffort[] | undefined;
184
- warnings: SharedV4Warning[];
185
- }): string | undefined {
186
- return mapReasoningToProviderEffort({
187
- reasoning,
188
- providerOptionsEffort: providerReasoningEffort,
189
- effortMap: Object.fromEntries(
190
- (supportedReasoningEfforts ?? ALL_OPENAI_REASONING_EFFORTS).map(
191
- effort => [effort, effort],
192
- ),
193
- ),
194
- warnings,
195
- });
196
- }