@ai-sdk/openai
Advanced tools
Comparing version 0.0.51 to 0.0.52
@@ -354,3 +354,3 @@ "use strict"; | ||
async doGenerate(options) { | ||
var _a, _b; | ||
var _a, _b, _c, _d, _e, _f; | ||
const { args, warnings } = this.getArgs(options); | ||
@@ -393,4 +393,4 @@ const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({ | ||
usage: { | ||
promptTokens: response.usage.prompt_tokens, | ||
completionTokens: response.usage.completion_tokens | ||
promptTokens: (_d = (_c = response.usage) == null ? void 0 : _c.prompt_tokens) != null ? _d : NaN, | ||
completionTokens: (_f = (_e = response.usage) == null ? void 0 : _e.completion_tokens) != null ? _f : NaN | ||
}, | ||
@@ -428,4 +428,4 @@ rawCall: { rawPrompt, rawSettings }, | ||
let usage = { | ||
promptTokens: Number.NaN, | ||
completionTokens: Number.NaN | ||
promptTokens: void 0, | ||
completionTokens: void 0 | ||
}; | ||
@@ -438,3 +438,3 @@ let logprobs; | ||
transform(chunk, controller) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n; | ||
if (!chunk.success) { | ||
@@ -453,4 +453,4 @@ finishReason = "error"; | ||
usage = { | ||
promptTokens: value.usage.prompt_tokens, | ||
completionTokens: value.usage.completion_tokens | ||
promptTokens: (_a = value.usage.prompt_tokens) != null ? _a : void 0, | ||
completionTokens: (_b = value.usage.completion_tokens) != null ? _b : void 0 | ||
}; | ||
@@ -503,3 +503,3 @@ } | ||
} | ||
if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) { | ||
if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) { | ||
throw new import_provider2.InvalidResponseDataError({ | ||
@@ -515,7 +515,7 @@ data: toolCallDelta, | ||
name: toolCallDelta.function.name, | ||
arguments: (_b = toolCallDelta.function.arguments) != null ? _b : "" | ||
arguments: (_d = toolCallDelta.function.arguments) != null ? _d : "" | ||
} | ||
}; | ||
const toolCall2 = toolCalls[index]; | ||
if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) { | ||
if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) { | ||
controller.enqueue({ | ||
@@ -531,3 +531,3 @@ type: "tool-call-delta", | ||
toolCallType: "function", | ||
toolCallId: (_e = toolCall2.id) != null ? _e : (0, import_provider_utils3.generateId)(), | ||
toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils3.generateId)(), | ||
toolName: toolCall2.function.name, | ||
@@ -540,4 +540,4 @@ args: toolCall2.function.arguments | ||
const toolCall = toolCalls[index]; | ||
if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) { | ||
toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : ""; | ||
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) { | ||
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : ""; | ||
} | ||
@@ -549,9 +549,9 @@ controller.enqueue({ | ||
toolName: toolCall.function.name, | ||
argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : "" | ||
argsTextDelta: (_k = toolCallDelta.function.arguments) != null ? _k : "" | ||
}); | ||
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) { | ||
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) { | ||
controller.enqueue({ | ||
type: "tool-call", | ||
toolCallType: "function", | ||
toolCallId: (_l = toolCall.id) != null ? _l : (0, import_provider_utils3.generateId)(), | ||
toolCallId: (_n = toolCall.id) != null ? _n : (0, import_provider_utils3.generateId)(), | ||
toolName: toolCall.function.name, | ||
@@ -565,2 +565,3 @@ args: toolCall.function.arguments | ||
flush(controller) { | ||
var _a, _b; | ||
controller.enqueue({ | ||
@@ -570,3 +571,6 @@ type: "finish", | ||
logprobs, | ||
usage | ||
usage: { | ||
promptTokens: (_a = usage.promptTokens) != null ? _a : NaN, | ||
completionTokens: (_b = usage.completionTokens) != null ? _b : NaN | ||
} | ||
}); | ||
@@ -582,2 +586,6 @@ } | ||
}; | ||
var openAITokenUsageSchema = import_zod2.z.object({ | ||
prompt_tokens: import_zod2.z.number().nullish(), | ||
completion_tokens: import_zod2.z.number().nullish() | ||
}).nullish(); | ||
var openAIChatResponseSchema = import_zod2.z.object({ | ||
@@ -622,6 +630,3 @@ choices: import_zod2.z.array( | ||
), | ||
usage: import_zod2.z.object({ | ||
prompt_tokens: import_zod2.z.number(), | ||
completion_tokens: import_zod2.z.number() | ||
}) | ||
usage: openAITokenUsageSchema | ||
}); | ||
@@ -669,6 +674,3 @@ var openaiChatChunkSchema = import_zod2.z.union([ | ||
), | ||
usage: import_zod2.z.object({ | ||
prompt_tokens: import_zod2.z.number(), | ||
completion_tokens: import_zod2.z.number() | ||
}).nullish() | ||
usage: openAITokenUsageSchema | ||
}), | ||
@@ -675,0 +677,0 @@ openAIErrorDataSchema |
@@ -354,3 +354,3 @@ "use strict"; | ||
async doGenerate(options) { | ||
var _a, _b; | ||
var _a, _b, _c, _d, _e, _f; | ||
const { args, warnings } = this.getArgs(options); | ||
@@ -393,4 +393,4 @@ const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({ | ||
usage: { | ||
promptTokens: response.usage.prompt_tokens, | ||
completionTokens: response.usage.completion_tokens | ||
promptTokens: (_d = (_c = response.usage) == null ? void 0 : _c.prompt_tokens) != null ? _d : NaN, | ||
completionTokens: (_f = (_e = response.usage) == null ? void 0 : _e.completion_tokens) != null ? _f : NaN | ||
}, | ||
@@ -428,4 +428,4 @@ rawCall: { rawPrompt, rawSettings }, | ||
let usage = { | ||
promptTokens: Number.NaN, | ||
completionTokens: Number.NaN | ||
promptTokens: void 0, | ||
completionTokens: void 0 | ||
}; | ||
@@ -438,3 +438,3 @@ let logprobs; | ||
transform(chunk, controller) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n; | ||
if (!chunk.success) { | ||
@@ -453,4 +453,4 @@ finishReason = "error"; | ||
usage = { | ||
promptTokens: value.usage.prompt_tokens, | ||
completionTokens: value.usage.completion_tokens | ||
promptTokens: (_a = value.usage.prompt_tokens) != null ? _a : void 0, | ||
completionTokens: (_b = value.usage.completion_tokens) != null ? _b : void 0 | ||
}; | ||
@@ -503,3 +503,3 @@ } | ||
} | ||
if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) { | ||
if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) { | ||
throw new import_provider2.InvalidResponseDataError({ | ||
@@ -515,7 +515,7 @@ data: toolCallDelta, | ||
name: toolCallDelta.function.name, | ||
arguments: (_b = toolCallDelta.function.arguments) != null ? _b : "" | ||
arguments: (_d = toolCallDelta.function.arguments) != null ? _d : "" | ||
} | ||
}; | ||
const toolCall2 = toolCalls[index]; | ||
if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) { | ||
if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) { | ||
controller.enqueue({ | ||
@@ -531,3 +531,3 @@ type: "tool-call-delta", | ||
toolCallType: "function", | ||
toolCallId: (_e = toolCall2.id) != null ? _e : (0, import_provider_utils3.generateId)(), | ||
toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils3.generateId)(), | ||
toolName: toolCall2.function.name, | ||
@@ -540,4 +540,4 @@ args: toolCall2.function.arguments | ||
const toolCall = toolCalls[index]; | ||
if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) { | ||
toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : ""; | ||
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) { | ||
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : ""; | ||
} | ||
@@ -549,9 +549,9 @@ controller.enqueue({ | ||
toolName: toolCall.function.name, | ||
argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : "" | ||
argsTextDelta: (_k = toolCallDelta.function.arguments) != null ? _k : "" | ||
}); | ||
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) { | ||
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) { | ||
controller.enqueue({ | ||
type: "tool-call", | ||
toolCallType: "function", | ||
toolCallId: (_l = toolCall.id) != null ? _l : (0, import_provider_utils3.generateId)(), | ||
toolCallId: (_n = toolCall.id) != null ? _n : (0, import_provider_utils3.generateId)(), | ||
toolName: toolCall.function.name, | ||
@@ -565,2 +565,3 @@ args: toolCall.function.arguments | ||
flush(controller) { | ||
var _a, _b; | ||
controller.enqueue({ | ||
@@ -570,3 +571,6 @@ type: "finish", | ||
logprobs, | ||
usage | ||
usage: { | ||
promptTokens: (_a = usage.promptTokens) != null ? _a : NaN, | ||
completionTokens: (_b = usage.completionTokens) != null ? _b : NaN | ||
} | ||
}); | ||
@@ -582,2 +586,6 @@ } | ||
}; | ||
var openAITokenUsageSchema = import_zod2.z.object({ | ||
prompt_tokens: import_zod2.z.number().nullish(), | ||
completion_tokens: import_zod2.z.number().nullish() | ||
}).nullish(); | ||
var openAIChatResponseSchema = import_zod2.z.object({ | ||
@@ -622,6 +630,3 @@ choices: import_zod2.z.array( | ||
), | ||
usage: import_zod2.z.object({ | ||
prompt_tokens: import_zod2.z.number(), | ||
completion_tokens: import_zod2.z.number() | ||
}) | ||
usage: openAITokenUsageSchema | ||
}); | ||
@@ -669,6 +674,3 @@ var openaiChatChunkSchema = import_zod2.z.union([ | ||
), | ||
usage: import_zod2.z.object({ | ||
prompt_tokens: import_zod2.z.number(), | ||
completion_tokens: import_zod2.z.number() | ||
}).nullish() | ||
usage: openAITokenUsageSchema | ||
}), | ||
@@ -675,0 +677,0 @@ openAIErrorDataSchema |
@@ -351,3 +351,3 @@ "use strict"; | ||
async doGenerate(options) { | ||
var _a, _b; | ||
var _a, _b, _c, _d, _e, _f; | ||
const { args, warnings } = this.getArgs(options); | ||
@@ -390,4 +390,4 @@ const { responseHeaders, value: response } = await (0, import_provider_utils3.postJsonToApi)({ | ||
usage: { | ||
promptTokens: response.usage.prompt_tokens, | ||
completionTokens: response.usage.completion_tokens | ||
promptTokens: (_d = (_c = response.usage) == null ? void 0 : _c.prompt_tokens) != null ? _d : NaN, | ||
completionTokens: (_f = (_e = response.usage) == null ? void 0 : _e.completion_tokens) != null ? _f : NaN | ||
}, | ||
@@ -425,4 +425,4 @@ rawCall: { rawPrompt, rawSettings }, | ||
let usage = { | ||
promptTokens: Number.NaN, | ||
completionTokens: Number.NaN | ||
promptTokens: void 0, | ||
completionTokens: void 0 | ||
}; | ||
@@ -435,3 +435,3 @@ let logprobs; | ||
transform(chunk, controller) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n; | ||
if (!chunk.success) { | ||
@@ -450,4 +450,4 @@ finishReason = "error"; | ||
usage = { | ||
promptTokens: value.usage.prompt_tokens, | ||
completionTokens: value.usage.completion_tokens | ||
promptTokens: (_a = value.usage.prompt_tokens) != null ? _a : void 0, | ||
completionTokens: (_b = value.usage.completion_tokens) != null ? _b : void 0 | ||
}; | ||
@@ -500,3 +500,3 @@ } | ||
} | ||
if (((_a = toolCallDelta.function) == null ? void 0 : _a.name) == null) { | ||
if (((_c = toolCallDelta.function) == null ? void 0 : _c.name) == null) { | ||
throw new import_provider2.InvalidResponseDataError({ | ||
@@ -512,7 +512,7 @@ data: toolCallDelta, | ||
name: toolCallDelta.function.name, | ||
arguments: (_b = toolCallDelta.function.arguments) != null ? _b : "" | ||
arguments: (_d = toolCallDelta.function.arguments) != null ? _d : "" | ||
} | ||
}; | ||
const toolCall2 = toolCalls[index]; | ||
if (((_c = toolCall2.function) == null ? void 0 : _c.name) != null && ((_d = toolCall2.function) == null ? void 0 : _d.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) { | ||
if (((_e = toolCall2.function) == null ? void 0 : _e.name) != null && ((_f = toolCall2.function) == null ? void 0 : _f.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall2.function.arguments)) { | ||
controller.enqueue({ | ||
@@ -528,3 +528,3 @@ type: "tool-call-delta", | ||
toolCallType: "function", | ||
toolCallId: (_e = toolCall2.id) != null ? _e : (0, import_provider_utils3.generateId)(), | ||
toolCallId: (_g = toolCall2.id) != null ? _g : (0, import_provider_utils3.generateId)(), | ||
toolName: toolCall2.function.name, | ||
@@ -537,4 +537,4 @@ args: toolCall2.function.arguments | ||
const toolCall = toolCalls[index]; | ||
if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) { | ||
toolCall.function.arguments += (_h = (_g = toolCallDelta.function) == null ? void 0 : _g.arguments) != null ? _h : ""; | ||
if (((_h = toolCallDelta.function) == null ? void 0 : _h.arguments) != null) { | ||
toolCall.function.arguments += (_j = (_i = toolCallDelta.function) == null ? void 0 : _i.arguments) != null ? _j : ""; | ||
} | ||
@@ -546,9 +546,9 @@ controller.enqueue({ | ||
toolName: toolCall.function.name, | ||
argsTextDelta: (_i = toolCallDelta.function.arguments) != null ? _i : "" | ||
argsTextDelta: (_k = toolCallDelta.function.arguments) != null ? _k : "" | ||
}); | ||
if (((_j = toolCall.function) == null ? void 0 : _j.name) != null && ((_k = toolCall.function) == null ? void 0 : _k.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) { | ||
if (((_l = toolCall.function) == null ? void 0 : _l.name) != null && ((_m = toolCall.function) == null ? void 0 : _m.arguments) != null && (0, import_provider_utils3.isParsableJson)(toolCall.function.arguments)) { | ||
controller.enqueue({ | ||
type: "tool-call", | ||
toolCallType: "function", | ||
toolCallId: (_l = toolCall.id) != null ? _l : (0, import_provider_utils3.generateId)(), | ||
toolCallId: (_n = toolCall.id) != null ? _n : (0, import_provider_utils3.generateId)(), | ||
toolName: toolCall.function.name, | ||
@@ -562,2 +562,3 @@ args: toolCall.function.arguments | ||
flush(controller) { | ||
var _a, _b; | ||
controller.enqueue({ | ||
@@ -567,3 +568,6 @@ type: "finish", | ||
logprobs, | ||
usage | ||
usage: { | ||
promptTokens: (_a = usage.promptTokens) != null ? _a : NaN, | ||
completionTokens: (_b = usage.completionTokens) != null ? _b : NaN | ||
} | ||
}); | ||
@@ -579,2 +583,6 @@ } | ||
}; | ||
var openAITokenUsageSchema = import_zod2.z.object({ | ||
prompt_tokens: import_zod2.z.number().nullish(), | ||
completion_tokens: import_zod2.z.number().nullish() | ||
}).nullish(); | ||
var openAIChatResponseSchema = import_zod2.z.object({ | ||
@@ -619,6 +627,3 @@ choices: import_zod2.z.array( | ||
), | ||
usage: import_zod2.z.object({ | ||
prompt_tokens: import_zod2.z.number(), | ||
completion_tokens: import_zod2.z.number() | ||
}) | ||
usage: openAITokenUsageSchema | ||
}); | ||
@@ -666,6 +671,3 @@ var openaiChatChunkSchema = import_zod2.z.union([ | ||
), | ||
usage: import_zod2.z.object({ | ||
prompt_tokens: import_zod2.z.number(), | ||
completion_tokens: import_zod2.z.number() | ||
}).nullish() | ||
usage: openAITokenUsageSchema | ||
}), | ||
@@ -672,0 +674,0 @@ openAIErrorDataSchema |
{ | ||
"name": "@ai-sdk/openai", | ||
"version": "0.0.51", | ||
"version": "0.0.52", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
543966
6516