@ai-sdk/openai 4.0.88 → 4.0.89
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.
- package/CHANGELOG.md +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/openai-decision-model.ts +50 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.89",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.25",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.57"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.4",
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InvalidResponseDataError,
|
|
3
|
+
UnsupportedFunctionalityError,
|
|
3
4
|
type Experimental_DecisionModelV4 as DecisionModelV4,
|
|
4
5
|
type Experimental_DecisionModelV4Answer as DecisionModelV4Answer,
|
|
5
6
|
type Experimental_DecisionModelV4Input as DecisionModelV4Input,
|
|
6
7
|
} from '@ai-sdk/provider';
|
|
7
8
|
import {
|
|
8
9
|
combineHeaders,
|
|
10
|
+
convertUint8ArrayToBase64,
|
|
11
|
+
detectMediaType,
|
|
12
|
+
isFullMediaType,
|
|
9
13
|
createJsonResponseHandler,
|
|
10
14
|
postJsonToApi,
|
|
11
15
|
parseProviderOptions,
|
|
@@ -72,10 +76,6 @@ const responseSchema = z.object({
|
|
|
72
76
|
),
|
|
73
77
|
});
|
|
74
78
|
|
|
75
|
-
function toText(input: DecisionModelV4Input): string {
|
|
76
|
-
return typeof input === 'string' ? input : JSON.stringify(input);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
79
|
export class DecisionOpenAIModel implements DecisionModelV4 {
|
|
80
80
|
readonly specificationVersion = 'v4';
|
|
81
81
|
readonly supportedQuestionTypes = ['choice', 'score', 'boolean'] as const;
|
|
@@ -135,7 +135,48 @@ export class DecisionOpenAIModel implements DecisionModelV4 {
|
|
|
135
135
|
body: {
|
|
136
136
|
model: this.modelId,
|
|
137
137
|
safety_identifier: openaiOptions?.safetyIdentifier,
|
|
138
|
-
input:
|
|
138
|
+
input: [
|
|
139
|
+
{
|
|
140
|
+
role: 'user',
|
|
141
|
+
content: state.map(part => {
|
|
142
|
+
if (part.type === 'text')
|
|
143
|
+
return { type: 'input_text', text: part.text };
|
|
144
|
+
if (part.type === 'json')
|
|
145
|
+
return {
|
|
146
|
+
type: 'input_text',
|
|
147
|
+
text: JSON.stringify(part.value),
|
|
148
|
+
};
|
|
149
|
+
if (part.data.type !== 'data') {
|
|
150
|
+
throw new UnsupportedFunctionalityError({
|
|
151
|
+
functionality: `OpenAI decision file input: ${part.mediaType} (${part.data.type})`,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
// Direct doDecide calls can bypass Core's media type detection.
|
|
155
|
+
const mediaType = isFullMediaType(part.mediaType)
|
|
156
|
+
? part.mediaType
|
|
157
|
+
: detectMediaType({
|
|
158
|
+
data: part.data.data,
|
|
159
|
+
topLevelType: 'image',
|
|
160
|
+
});
|
|
161
|
+
if (
|
|
162
|
+
![
|
|
163
|
+
'image/png',
|
|
164
|
+
'image/jpeg',
|
|
165
|
+
'image/webp',
|
|
166
|
+
'image/gif',
|
|
167
|
+
].includes(mediaType ?? '')
|
|
168
|
+
) {
|
|
169
|
+
throw new UnsupportedFunctionalityError({
|
|
170
|
+
functionality: `OpenAI decision image media type: ${part.mediaType}`,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
type: 'input_image',
|
|
175
|
+
image_url: `data:${mediaType};base64,${typeof part.data.data === 'string' ? part.data.data : convertUint8ArrayToBase64(part.data.data)}`,
|
|
176
|
+
};
|
|
177
|
+
}),
|
|
178
|
+
},
|
|
179
|
+
],
|
|
139
180
|
questions: Object.entries(questions).map(([name, question]) => {
|
|
140
181
|
const instructions = toText(question.instructions);
|
|
141
182
|
switch (question.type) {
|
|
@@ -283,3 +324,7 @@ export class DecisionOpenAIModel implements DecisionModelV4 {
|
|
|
283
324
|
};
|
|
284
325
|
}
|
|
285
326
|
}
|
|
327
|
+
|
|
328
|
+
function toText(input: DecisionModelV4Input): string {
|
|
329
|
+
return typeof input === 'string' ? input : JSON.stringify(input);
|
|
330
|
+
}
|