@ai-sdk/openai-compatible 3.0.0-beta.33 → 3.0.0-beta.34
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 +12 -0
- package/dist/index.js +74 -56
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +73 -55
- package/dist/internal/index.js.map +1 -1
- package/package.json +4 -4
- package/src/chat/convert-openai-compatible-chat-usage.ts +1 -1
- package/src/chat/convert-to-openai-compatible-chat-messages.ts +92 -78
- package/src/chat/map-openai-compatible-finish-reason.ts +1 -1
- package/src/chat/openai-compatible-api-types.ts +1 -1
- package/src/chat/openai-compatible-chat-language-model.ts +8 -8
- package/src/chat/openai-compatible-metadata-extractor.ts +1 -1
- package/src/chat/openai-compatible-prepare-tools.ts +2 -3
- package/src/completion/convert-openai-compatible-completion-usage.ts +1 -1
- package/src/completion/convert-to-openai-compatible-completion-prompt.ts +1 -2
- package/src/completion/map-openai-compatible-finish-reason.ts +1 -1
- package/src/completion/openai-compatible-completion-language-model.ts +6 -7
- package/src/embedding/openai-compatible-embedding-model.ts +5 -5
- package/src/image/openai-compatible-image-model.ts +4 -4
- package/src/openai-compatible-error.ts +1 -2
- package/src/openai-compatible-provider.ts +4 -4
- package/src/utils/to-camel-case.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/openai-compatible
|
|
2
2
|
|
|
3
|
+
## 3.0.0-beta.34
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
|
|
8
|
+
- 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
|
|
9
|
+
- Updated dependencies [9bd6512]
|
|
10
|
+
- Updated dependencies [258c093]
|
|
11
|
+
- Updated dependencies [b6783da]
|
|
12
|
+
- @ai-sdk/provider-utils@5.0.0-beta.29
|
|
13
|
+
- @ai-sdk/provider@4.0.0-beta.14
|
|
14
|
+
|
|
3
15
|
## 3.0.0-beta.33
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -105,7 +105,8 @@ import {
|
|
|
105
105
|
import {
|
|
106
106
|
convertBase64ToUint8Array,
|
|
107
107
|
convertToBase64,
|
|
108
|
-
|
|
108
|
+
getTopLevelMediaType,
|
|
109
|
+
resolveFullMediaType
|
|
109
110
|
} from "@ai-sdk/provider-utils";
|
|
110
111
|
function getOpenAIMetadata(message) {
|
|
111
112
|
var _a, _b;
|
|
@@ -151,70 +152,87 @@ function convertToOpenAICompatibleChatMessages(prompt) {
|
|
|
151
152
|
return { type: "text", text: part.text, ...partMetadata };
|
|
152
153
|
}
|
|
153
154
|
case "file": {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
functionality: "file parts with provider references"
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
if (part.mediaType.startsWith("image/")) {
|
|
160
|
-
const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
|
|
161
|
-
return {
|
|
162
|
-
type: "image_url",
|
|
163
|
-
image_url: {
|
|
164
|
-
url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
|
|
165
|
-
},
|
|
166
|
-
...partMetadata
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
if (part.mediaType.startsWith("audio/")) {
|
|
170
|
-
if (part.data instanceof URL) {
|
|
155
|
+
switch (part.data.type) {
|
|
156
|
+
case "reference": {
|
|
171
157
|
throw new UnsupportedFunctionalityError({
|
|
172
|
-
functionality: "
|
|
158
|
+
functionality: "file parts with provider references"
|
|
173
159
|
});
|
|
174
160
|
}
|
|
175
|
-
|
|
176
|
-
if (format === null) {
|
|
161
|
+
case "text": {
|
|
177
162
|
throw new UnsupportedFunctionalityError({
|
|
178
|
-
functionality:
|
|
163
|
+
functionality: "text file parts"
|
|
179
164
|
});
|
|
180
165
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
166
|
+
case "url":
|
|
167
|
+
case "data": {
|
|
168
|
+
const topLevel = getTopLevelMediaType(part.mediaType);
|
|
169
|
+
if (topLevel === "image") {
|
|
170
|
+
return {
|
|
171
|
+
type: "image_url",
|
|
172
|
+
image_url: {
|
|
173
|
+
url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`
|
|
174
|
+
},
|
|
175
|
+
...partMetadata
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (topLevel === "audio") {
|
|
179
|
+
if (part.data.type === "url") {
|
|
180
|
+
throw new UnsupportedFunctionalityError({
|
|
181
|
+
functionality: "audio file parts with URLs"
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
185
|
+
const format = getAudioFormat(fullMediaType);
|
|
186
|
+
if (format === null) {
|
|
187
|
+
throw new UnsupportedFunctionalityError({
|
|
188
|
+
functionality: `audio media type ${fullMediaType}`
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
type: "input_audio",
|
|
193
|
+
input_audio: {
|
|
194
|
+
data: convertToBase64(part.data.data),
|
|
195
|
+
format
|
|
196
|
+
},
|
|
197
|
+
...partMetadata
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (topLevel === "application") {
|
|
201
|
+
if (part.data.type === "url") {
|
|
202
|
+
throw new UnsupportedFunctionalityError({
|
|
203
|
+
functionality: "PDF file parts with URLs"
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
const fullMediaType = resolveFullMediaType({ part });
|
|
207
|
+
if (fullMediaType !== "application/pdf") {
|
|
208
|
+
throw new UnsupportedFunctionalityError({
|
|
209
|
+
functionality: `file part media type ${fullMediaType}`
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return {
|
|
213
|
+
type: "file",
|
|
214
|
+
file: {
|
|
215
|
+
filename: (_a2 = part.filename) != null ? _a2 : "document.pdf",
|
|
216
|
+
file_data: `data:application/pdf;base64,${convertToBase64(part.data.data)}`
|
|
217
|
+
},
|
|
218
|
+
...partMetadata
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (topLevel === "text") {
|
|
222
|
+
const textContent = part.data.type === "url" ? part.data.url.toString() : typeof part.data.data === "string" ? new TextDecoder().decode(
|
|
223
|
+
convertBase64ToUint8Array(part.data.data)
|
|
224
|
+
) : new TextDecoder().decode(part.data.data);
|
|
225
|
+
return {
|
|
226
|
+
type: "text",
|
|
227
|
+
text: textContent,
|
|
228
|
+
...partMetadata
|
|
229
|
+
};
|
|
230
|
+
}
|
|
192
231
|
throw new UnsupportedFunctionalityError({
|
|
193
|
-
functionality:
|
|
232
|
+
functionality: `file part media type ${part.mediaType}`
|
|
194
233
|
});
|
|
195
234
|
}
|
|
196
|
-
return {
|
|
197
|
-
type: "file",
|
|
198
|
-
file: {
|
|
199
|
-
filename: (_a2 = part.filename) != null ? _a2 : "document.pdf",
|
|
200
|
-
file_data: `data:application/pdf;base64,${convertToBase64(part.data)}`
|
|
201
|
-
},
|
|
202
|
-
...partMetadata
|
|
203
|
-
};
|
|
204
235
|
}
|
|
205
|
-
if (part.mediaType.startsWith("text/")) {
|
|
206
|
-
const textContent = part.data instanceof URL ? part.data.toString() : typeof part.data === "string" ? new TextDecoder().decode(
|
|
207
|
-
convertBase64ToUint8Array(part.data)
|
|
208
|
-
) : new TextDecoder().decode(part.data);
|
|
209
|
-
return {
|
|
210
|
-
type: "text",
|
|
211
|
-
text: textContent,
|
|
212
|
-
...partMetadata
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
throw new UnsupportedFunctionalityError({
|
|
216
|
-
functionality: `file part media type ${part.mediaType}`
|
|
217
|
-
});
|
|
218
236
|
}
|
|
219
237
|
}
|
|
220
238
|
}),
|
|
@@ -1761,7 +1779,7 @@ import {
|
|
|
1761
1779
|
} from "@ai-sdk/provider-utils";
|
|
1762
1780
|
|
|
1763
1781
|
// src/version.ts
|
|
1764
|
-
var VERSION = true ? "3.0.0-beta.
|
|
1782
|
+
var VERSION = true ? "3.0.0-beta.34" : "0.0.0-test";
|
|
1765
1783
|
|
|
1766
1784
|
// src/openai-compatible-provider.ts
|
|
1767
1785
|
function createOpenAICompatible(options) {
|