@ai-sdk/openai 4.0.2 → 4.0.4
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 +14 -0
- package/dist/index.js +34 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +33 -1
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +6 -0
- package/package.json +3 -3
- package/src/responses/openai-responses-language-model.ts +55 -1
package/dist/internal/index.js
CHANGED
|
@@ -6317,8 +6317,15 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
6317
6317
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
6318
6318
|
}
|
|
6319
6319
|
if (!chunk.success) {
|
|
6320
|
+
const error = isOpenAIChatCompletionChunk(chunk.rawValue) ? createOpenAIResponsesChatCompletionsMismatchError({
|
|
6321
|
+
value: chunk.rawValue,
|
|
6322
|
+
cause: chunk.error,
|
|
6323
|
+
url,
|
|
6324
|
+
requestBodyValues: body,
|
|
6325
|
+
responseHeaders
|
|
6326
|
+
}) : chunk.error;
|
|
6320
6327
|
finishReason = { unified: "error", raw: void 0 };
|
|
6321
|
-
controller.enqueue({ type: "error", error
|
|
6328
|
+
controller.enqueue({ type: "error", error });
|
|
6322
6329
|
return;
|
|
6323
6330
|
}
|
|
6324
6331
|
const value = chunk.value;
|
|
@@ -7175,6 +7182,31 @@ var OpenAIResponsesLanguageModel = class _OpenAIResponsesLanguageModel {
|
|
|
7175
7182
|
function isTextDeltaChunk(chunk) {
|
|
7176
7183
|
return chunk.type === "response.output_text.delta";
|
|
7177
7184
|
}
|
|
7185
|
+
function isOpenAIChatCompletionChunk(value) {
|
|
7186
|
+
const chunk = asRecord2(value);
|
|
7187
|
+
return chunk != null && Array.isArray(chunk.choices) && typeof chunk.type !== "string";
|
|
7188
|
+
}
|
|
7189
|
+
function createOpenAIResponsesChatCompletionsMismatchError({
|
|
7190
|
+
value,
|
|
7191
|
+
cause,
|
|
7192
|
+
url,
|
|
7193
|
+
requestBodyValues,
|
|
7194
|
+
responseHeaders
|
|
7195
|
+
}) {
|
|
7196
|
+
return new APICallError2({
|
|
7197
|
+
message: "Received a Chat Completions stream while using the OpenAI Responses API. The default OpenAI provider model uses the Responses API. If your custom baseURL targets a Chat Completions-compatible endpoint, use openai.chat('model-id') or createOpenAI(...).chat('model-id') instead. You can also use @ai-sdk/openai-compatible for OpenAI-compatible providers.",
|
|
7198
|
+
url,
|
|
7199
|
+
requestBodyValues,
|
|
7200
|
+
responseHeaders,
|
|
7201
|
+
responseBody: JSON.stringify(value),
|
|
7202
|
+
cause,
|
|
7203
|
+
data: value,
|
|
7204
|
+
isRetryable: false
|
|
7205
|
+
});
|
|
7206
|
+
}
|
|
7207
|
+
function asRecord2(value) {
|
|
7208
|
+
return typeof value === "object" && value != null ? value : void 0;
|
|
7209
|
+
}
|
|
7178
7210
|
function isResponseOutputItemDoneChunk(chunk) {
|
|
7179
7211
|
return chunk.type === "response.output_item.done";
|
|
7180
7212
|
}
|