openai 4.53.2 → 4.55.0
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 +29 -0
- package/README.md +2 -2
- package/_vendor/partial-json-parser/parser.d.ts +3 -0
- package/_vendor/partial-json-parser/parser.d.ts.map +1 -0
- package/_vendor/partial-json-parser/parser.js +226 -0
- package/_vendor/partial-json-parser/parser.js.map +1 -0
- package/_vendor/partial-json-parser/parser.mjs +223 -0
- package/_vendor/partial-json-parser/parser.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/Options.d.ts +32 -0
- package/_vendor/zod-to-json-schema/Options.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/Options.js +36 -0
- package/_vendor/zod-to-json-schema/Options.js.map +1 -0
- package/_vendor/zod-to-json-schema/Options.mjs +32 -0
- package/_vendor/zod-to-json-schema/Options.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/Refs.d.ts +15 -0
- package/_vendor/zod-to-json-schema/Refs.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/Refs.js +26 -0
- package/_vendor/zod-to-json-schema/Refs.js.map +1 -0
- package/_vendor/zod-to-json-schema/Refs.mjs +22 -0
- package/_vendor/zod-to-json-schema/Refs.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/errorMessages.d.ts +12 -0
- package/_vendor/zod-to-json-schema/errorMessages.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/errorMessages.js +20 -0
- package/_vendor/zod-to-json-schema/errorMessages.js.map +1 -0
- package/_vendor/zod-to-json-schema/errorMessages.mjs +15 -0
- package/_vendor/zod-to-json-schema/errorMessages.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/index.d.ts +38 -0
- package/_vendor/zod-to-json-schema/index.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/index.js +54 -0
- package/_vendor/zod-to-json-schema/index.js.map +1 -0
- package/_vendor/zod-to-json-schema/index.mjs +38 -0
- package/_vendor/zod-to-json-schema/index.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parseDef.d.ts +38 -0
- package/_vendor/zod-to-json-schema/parseDef.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parseDef.js +168 -0
- package/_vendor/zod-to-json-schema/parseDef.js.map +1 -0
- package/_vendor/zod-to-json-schema/parseDef.mjs +164 -0
- package/_vendor/zod-to-json-schema/parseDef.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/any.d.ts +3 -0
- package/_vendor/zod-to-json-schema/parsers/any.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/any.js +8 -0
- package/_vendor/zod-to-json-schema/parsers/any.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/any.mjs +4 -0
- package/_vendor/zod-to-json-schema/parsers/any.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/array.d.ts +13 -0
- package/_vendor/zod-to-json-schema/parsers/array.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/array.js +30 -0
- package/_vendor/zod-to-json-schema/parsers/array.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/array.mjs +26 -0
- package/_vendor/zod-to-json-schema/parsers/array.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.d.ts +15 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.js +54 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.mjs +50 -0
- package/_vendor/zod-to-json-schema/parsers/bigint.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.js +10 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.mjs +6 -0
- package/_vendor/zod-to-json-schema/parsers/boolean.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/branded.d.ts +4 -0
- package/_vendor/zod-to-json-schema/parsers/branded.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/branded.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/branded.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/branded.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/branded.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/catch.d.ts +4 -0
- package/_vendor/zod-to-json-schema/parsers/catch.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/catch.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/catch.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/catch.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/catch.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/date.d.ts +16 -0
- package/_vendor/zod-to-json-schema/parsers/date.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/date.js +51 -0
- package/_vendor/zod-to-json-schema/parsers/date.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/date.mjs +47 -0
- package/_vendor/zod-to-json-schema/parsers/date.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/default.d.ts +7 -0
- package/_vendor/zod-to-json-schema/parsers/default.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/default.js +12 -0
- package/_vendor/zod-to-json-schema/parsers/default.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/default.mjs +8 -0
- package/_vendor/zod-to-json-schema/parsers/default.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/effects.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/effects.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/effects.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/effects.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/effects.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/effects.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/enum.d.ts +7 -0
- package/_vendor/zod-to-json-schema/parsers/enum.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/enum.js +11 -0
- package/_vendor/zod-to-json-schema/parsers/enum.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/enum.mjs +7 -0
- package/_vendor/zod-to-json-schema/parsers/enum.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.d.ts +9 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.js +54 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.mjs +50 -0
- package/_vendor/zod-to-json-schema/parsers/intersection.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/literal.d.ts +10 -0
- package/_vendor/zod-to-json-schema/parsers/literal.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/literal.js +26 -0
- package/_vendor/zod-to-json-schema/parsers/literal.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/literal.mjs +22 -0
- package/_vendor/zod-to-json-schema/parsers/literal.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/map.d.ts +16 -0
- package/_vendor/zod-to-json-schema/parsers/map.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/map.js +30 -0
- package/_vendor/zod-to-json-schema/parsers/map.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/map.mjs +26 -0
- package/_vendor/zod-to-json-schema/parsers/map.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.d.ts +7 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.js +21 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.mjs +17 -0
- package/_vendor/zod-to-json-schema/parsers/nativeEnum.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/never.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/never.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/never.js +10 -0
- package/_vendor/zod-to-json-schema/parsers/never.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/never.mjs +6 -0
- package/_vendor/zod-to-json-schema/parsers/never.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/null.d.ts +6 -0
- package/_vendor/zod-to-json-schema/parsers/null.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/null.js +15 -0
- package/_vendor/zod-to-json-schema/parsers/null.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/null.mjs +11 -0
- package/_vendor/zod-to-json-schema/parsers/null.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.d.ts +11 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.js +35 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.mjs +31 -0
- package/_vendor/zod-to-json-schema/parsers/nullable.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/number.d.ts +14 -0
- package/_vendor/zod-to-json-schema/parsers/number.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/number.js +57 -0
- package/_vendor/zod-to-json-schema/parsers/number.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/number.mjs +53 -0
- package/_vendor/zod-to-json-schema/parsers/number.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/object.d.ts +11 -0
- package/_vendor/zod-to-json-schema/parsers/object.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/object.js +51 -0
- package/_vendor/zod-to-json-schema/parsers/object.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/object.mjs +47 -0
- package/_vendor/zod-to-json-schema/parsers/object.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/optional.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/optional.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/optional.js +25 -0
- package/_vendor/zod-to-json-schema/parsers/optional.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/optional.mjs +21 -0
- package/_vendor/zod-to-json-schema/parsers/optional.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.ts +6 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.js +25 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.mjs +21 -0
- package/_vendor/zod-to-json-schema/parsers/pipeline.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/promise.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/promise.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/promise.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/promise.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/promise.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/promise.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.d.ts +4 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.js +9 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.mjs +5 -0
- package/_vendor/zod-to-json-schema/parsers/readonly.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/record.d.ts +14 -0
- package/_vendor/zod-to-json-schema/parsers/record.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/record.js +50 -0
- package/_vendor/zod-to-json-schema/parsers/record.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/record.mjs +46 -0
- package/_vendor/zod-to-json-schema/parsers/record.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/set.d.ts +14 -0
- package/_vendor/zod-to-json-schema/parsers/set.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/set.js +25 -0
- package/_vendor/zod-to-json-schema/parsers/set.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/set.mjs +21 -0
- package/_vendor/zod-to-json-schema/parsers/set.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/string.d.ts +70 -0
- package/_vendor/zod-to-json-schema/parsers/string.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/string.js +316 -0
- package/_vendor/zod-to-json-schema/parsers/string.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/string.mjs +312 -0
- package/_vendor/zod-to-json-schema/parsers/string.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.d.ts +14 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.js +37 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.mjs +33 -0
- package/_vendor/zod-to-json-schema/parsers/tuple.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.d.ts +5 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.js +10 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.mjs +6 -0
- package/_vendor/zod-to-json-schema/parsers/undefined.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/union.d.ts +24 -0
- package/_vendor/zod-to-json-schema/parsers/union.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/union.js +77 -0
- package/_vendor/zod-to-json-schema/parsers/union.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/union.mjs +73 -0
- package/_vendor/zod-to-json-schema/parsers/union.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.d.ts +3 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.js +8 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.js.map +1 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.mjs +4 -0
- package/_vendor/zod-to-json-schema/parsers/unknown.mjs.map +1 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.d.ts +11 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.d.ts.map +1 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.js +53 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.js.map +1 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.mjs +50 -0
- package/_vendor/zod-to-json-schema/zodToJsonSchema.mjs.map +1 -0
- package/error.d.ts +6 -0
- package/error.d.ts.map +1 -1
- package/error.js +13 -1
- package/error.js.map +1 -1
- package/error.mjs +10 -0
- package/error.mjs.map +1 -1
- package/helpers/zod.d.ts +57 -0
- package/helpers/zod.d.ts.map +1 -0
- package/helpers/zod.js +79 -0
- package/helpers/zod.js.map +1 -0
- package/helpers/zod.mjs +74 -0
- package/helpers/zod.mjs.map +1 -0
- package/index.d.mts +8 -0
- package/index.d.ts +8 -0
- package/index.d.ts.map +1 -1
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/lib/AbstractChatCompletionRunner.d.ts +15 -68
- package/lib/AbstractChatCompletionRunner.d.ts.map +1 -1
- package/lib/AbstractChatCompletionRunner.js +47 -200
- package/lib/AbstractChatCompletionRunner.js.map +1 -1
- package/lib/AbstractChatCompletionRunner.mjs +48 -201
- package/lib/AbstractChatCompletionRunner.mjs.map +1 -1
- package/lib/AssistantStream.d.ts +10 -6
- package/lib/AssistantStream.d.ts.map +1 -1
- package/lib/AssistantStream.js +18 -6
- package/lib/AssistantStream.js.map +1 -1
- package/lib/AssistantStream.mjs +18 -6
- package/lib/AssistantStream.mjs.map +1 -1
- package/lib/ChatCompletionRunner.d.ts +8 -6
- package/lib/ChatCompletionRunner.d.ts.map +1 -1
- package/lib/ChatCompletionRunner.js +4 -4
- package/lib/ChatCompletionRunner.js.map +1 -1
- package/lib/ChatCompletionRunner.mjs +4 -4
- package/lib/ChatCompletionRunner.mjs.map +1 -1
- package/lib/ChatCompletionStream.d.ts +71 -12
- package/lib/ChatCompletionStream.d.ts.map +1 -1
- package/lib/ChatCompletionStream.js +233 -42
- package/lib/ChatCompletionStream.js.map +1 -1
- package/lib/ChatCompletionStream.mjs +234 -43
- package/lib/ChatCompletionStream.mjs.map +1 -1
- package/lib/ChatCompletionStreamingRunner.d.ts +8 -6
- package/lib/ChatCompletionStreamingRunner.d.ts.map +1 -1
- package/lib/ChatCompletionStreamingRunner.js +9 -7
- package/lib/ChatCompletionStreamingRunner.js.map +1 -1
- package/lib/ChatCompletionStreamingRunner.mjs +9 -7
- package/lib/ChatCompletionStreamingRunner.mjs.map +1 -1
- package/lib/EventStream.d.ts +63 -0
- package/lib/EventStream.d.ts.map +1 -0
- package/lib/EventStream.js +200 -0
- package/lib/EventStream.js.map +1 -0
- package/lib/EventStream.mjs +196 -0
- package/lib/EventStream.mjs.map +1 -0
- package/lib/RunnableFunction.d.ts +4 -2
- package/lib/RunnableFunction.d.ts.map +1 -1
- package/lib/RunnableFunction.js.map +1 -1
- package/lib/RunnableFunction.mjs.map +1 -1
- package/lib/parser.d.ts +37 -0
- package/lib/parser.d.ts.map +1 -0
- package/lib/parser.js +133 -0
- package/lib/parser.js.map +1 -0
- package/lib/parser.mjs +121 -0
- package/lib/parser.mjs.map +1 -0
- package/package.json +10 -2
- package/resources/audio/audio.d.ts +4 -0
- package/resources/audio/audio.d.ts.map +1 -1
- package/resources/audio/audio.js.map +1 -1
- package/resources/audio/audio.mjs.map +1 -1
- package/resources/audio/index.d.ts +2 -2
- package/resources/audio/index.d.ts.map +1 -1
- package/resources/audio/index.js.map +1 -1
- package/resources/audio/index.mjs.map +1 -1
- package/resources/audio/speech.d.ts +3 -1
- package/resources/audio/speech.d.ts.map +1 -1
- package/resources/audio/speech.js.map +1 -1
- package/resources/audio/speech.mjs.map +1 -1
- package/resources/audio/transcriptions.d.ts +2 -1
- package/resources/audio/transcriptions.d.ts.map +1 -1
- package/resources/audio/transcriptions.js.map +1 -1
- package/resources/audio/transcriptions.mjs.map +1 -1
- package/resources/audio/translations.d.ts +2 -1
- package/resources/audio/translations.d.ts.map +1 -1
- package/resources/audio/translations.js.map +1 -1
- package/resources/audio/translations.mjs.map +1 -1
- package/resources/beta/assistants.d.ts +19 -3
- package/resources/beta/assistants.d.ts.map +1 -1
- package/resources/beta/assistants.js.map +1 -1
- package/resources/beta/assistants.mjs.map +1 -1
- package/resources/beta/beta.d.ts +0 -1
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/chat/completions.d.ts +25 -5
- package/resources/beta/chat/completions.d.ts.map +1 -1
- package/resources/beta/chat/completions.js +17 -5
- package/resources/beta/chat/completions.js.map +1 -1
- package/resources/beta/chat/completions.mjs +17 -5
- package/resources/beta/chat/completions.mjs.map +1 -1
- package/resources/beta/index.d.ts +1 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/threads/index.d.ts +2 -2
- package/resources/beta/threads/index.d.ts.map +1 -1
- package/resources/beta/threads/index.js.map +1 -1
- package/resources/beta/threads/index.mjs.map +1 -1
- package/resources/beta/threads/messages.d.ts +28 -2
- package/resources/beta/threads/messages.d.ts.map +1 -1
- package/resources/beta/threads/messages.js.map +1 -1
- package/resources/beta/threads/messages.mjs.map +1 -1
- package/resources/beta/threads/runs/runs.d.ts +12 -1
- package/resources/beta/threads/runs/runs.d.ts.map +1 -1
- package/resources/beta/threads/runs/runs.js.map +1 -1
- package/resources/beta/threads/runs/runs.mjs.map +1 -1
- package/resources/beta/threads/threads.d.ts +22 -8
- package/resources/beta/threads/threads.d.ts.map +1 -1
- package/resources/beta/threads/threads.js.map +1 -1
- package/resources/beta/threads/threads.mjs.map +1 -1
- package/resources/beta/vector-stores/files.d.ts +1 -1
- package/resources/beta/vector-stores/files.d.ts.map +1 -1
- package/resources/chat/chat.d.ts +2 -1
- package/resources/chat/chat.d.ts.map +1 -1
- package/resources/chat/chat.js.map +1 -1
- package/resources/chat/chat.mjs.map +1 -1
- package/resources/chat/completions.d.ts +37 -26
- package/resources/chat/completions.d.ts.map +1 -1
- package/resources/chat/completions.js.map +1 -1
- package/resources/chat/completions.mjs.map +1 -1
- package/resources/chat/index.d.ts +1 -1
- package/resources/chat/index.d.ts.map +1 -1
- package/resources/chat/index.js.map +1 -1
- package/resources/chat/index.mjs.map +1 -1
- package/resources/fine-tuning/jobs/jobs.d.ts +3 -3
- package/resources/fine-tuning/jobs/jobs.d.ts.map +1 -1
- package/resources/images.d.ts +5 -3
- package/resources/images.d.ts.map +1 -1
- package/resources/images.js.map +1 -1
- package/resources/images.mjs.map +1 -1
- package/resources/index.d.ts +3 -3
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/moderations.d.ts +3 -1
- package/resources/moderations.d.ts.map +1 -1
- package/resources/moderations.js.map +1 -1
- package/resources/moderations.mjs.map +1 -1
- package/resources/shared.d.ts +53 -0
- package/resources/shared.d.ts.map +1 -1
- package/src/_vendor/partial-json-parser/README.md +3 -0
- package/src/_vendor/partial-json-parser/parser.ts +264 -0
- package/src/_vendor/zod-to-json-schema/Options.ts +73 -0
- package/src/_vendor/zod-to-json-schema/Refs.ts +39 -0
- package/src/_vendor/zod-to-json-schema/errorMessages.ts +31 -0
- package/src/_vendor/zod-to-json-schema/index.ts +37 -0
- package/src/_vendor/zod-to-json-schema/parseDef.ts +231 -0
- package/src/_vendor/zod-to-json-schema/parsers/any.ts +5 -0
- package/src/_vendor/zod-to-json-schema/parsers/array.ts +36 -0
- package/src/_vendor/zod-to-json-schema/parsers/bigint.ts +60 -0
- package/src/_vendor/zod-to-json-schema/parsers/boolean.ts +9 -0
- package/src/_vendor/zod-to-json-schema/parsers/branded.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/catch.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/date.ts +83 -0
- package/src/_vendor/zod-to-json-schema/parsers/default.ts +10 -0
- package/src/_vendor/zod-to-json-schema/parsers/effects.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/enum.ts +13 -0
- package/src/_vendor/zod-to-json-schema/parsers/intersection.ts +64 -0
- package/src/_vendor/zod-to-json-schema/parsers/literal.ts +37 -0
- package/src/_vendor/zod-to-json-schema/parsers/map.ts +42 -0
- package/src/_vendor/zod-to-json-schema/parsers/nativeEnum.ts +27 -0
- package/src/_vendor/zod-to-json-schema/parsers/never.ts +9 -0
- package/src/_vendor/zod-to-json-schema/parsers/null.ts +16 -0
- package/src/_vendor/zod-to-json-schema/parsers/nullable.ts +49 -0
- package/src/_vendor/zod-to-json-schema/parsers/number.ts +62 -0
- package/src/_vendor/zod-to-json-schema/parsers/object.ts +63 -0
- package/src/_vendor/zod-to-json-schema/parsers/optional.ts +25 -0
- package/src/_vendor/zod-to-json-schema/parsers/pipeline.ts +28 -0
- package/src/_vendor/zod-to-json-schema/parsers/promise.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/readonly.ts +7 -0
- package/src/_vendor/zod-to-json-schema/parsers/record.ts +73 -0
- package/src/_vendor/zod-to-json-schema/parsers/set.ts +36 -0
- package/src/_vendor/zod-to-json-schema/parsers/string.ts +400 -0
- package/src/_vendor/zod-to-json-schema/parsers/tuple.ts +54 -0
- package/src/_vendor/zod-to-json-schema/parsers/undefined.ts +9 -0
- package/src/_vendor/zod-to-json-schema/parsers/union.ts +119 -0
- package/src/_vendor/zod-to-json-schema/parsers/unknown.ts +5 -0
- package/src/_vendor/zod-to-json-schema/zodToJsonSchema.ts +91 -0
- package/src/error.ts +12 -0
- package/src/helpers/zod.ts +102 -0
- package/src/index.ts +8 -0
- package/src/lib/AbstractChatCompletionRunner.ts +72 -258
- package/src/lib/AssistantStream.ts +47 -19
- package/src/lib/ChatCompletionRunner.ts +16 -12
- package/src/lib/ChatCompletionStream.ts +423 -47
- package/src/lib/ChatCompletionStreamingRunner.ts +19 -15
- package/src/lib/{AbstractAssistantStreamRunner.ts → EventStream.ts} +37 -138
- package/src/lib/RunnableFunction.ts +4 -2
- package/src/lib/parser.ts +235 -0
- package/src/resources/audio/audio.ts +5 -0
- package/src/resources/audio/index.ts +2 -2
- package/src/resources/audio/speech.ts +4 -1
- package/src/resources/audio/transcriptions.ts +2 -1
- package/src/resources/audio/translations.ts +2 -1
- package/src/resources/beta/assistants.ts +19 -26
- package/src/resources/beta/beta.ts +0 -1
- package/src/resources/beta/chat/completions.ts +77 -27
- package/src/resources/beta/index.ts +0 -1
- package/src/resources/beta/threads/index.ts +2 -1
- package/src/resources/beta/threads/messages.ts +41 -2
- package/src/resources/beta/threads/runs/runs.ts +12 -25
- package/src/resources/beta/threads/threads.ts +26 -32
- package/src/resources/beta/vector-stores/files.ts +1 -1
- package/src/resources/chat/chat.ts +2 -0
- package/src/resources/chat/completions.ts +47 -27
- package/src/resources/chat/index.ts +1 -0
- package/src/resources/fine-tuning/jobs/jobs.ts +3 -3
- package/src/resources/images.ts +6 -3
- package/src/resources/index.ts +9 -2
- package/src/resources/moderations.ts +4 -1
- package/src/resources/shared.ts +62 -0
- package/src/version.ts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/lib/AbstractAssistantStreamRunner.d.ts +0 -74
- package/lib/AbstractAssistantStreamRunner.d.ts.map +0 -1
- package/lib/AbstractAssistantStreamRunner.js +0 -246
- package/lib/AbstractAssistantStreamRunner.js.map +0 -1
- package/lib/AbstractAssistantStreamRunner.mjs +0 -242
- package/lib/AbstractAssistantStreamRunner.mjs.map +0 -1
- package/lib/ChatCompletionRunFunctions.test.d.ts +0 -2
- package/lib/ChatCompletionRunFunctions.test.d.ts.map +0 -1
- package/lib/ChatCompletionRunFunctions.test.js +0 -2177
- package/lib/ChatCompletionRunFunctions.test.js.map +0 -1
- package/lib/ChatCompletionRunFunctions.test.mjs +0 -2172
- package/lib/ChatCompletionRunFunctions.test.mjs.map +0 -1
- package/src/lib/ChatCompletionRunFunctions.test.ts +0 -2328
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import * as Core from "../core";
|
|
2
|
-
import { OpenAIError, APIUserAbortError } from "../error";
|
|
3
2
|
import {
|
|
4
|
-
|
|
3
|
+
OpenAIError,
|
|
4
|
+
APIUserAbortError,
|
|
5
|
+
LengthFinishReasonError,
|
|
6
|
+
ContentFilterFinishReasonError,
|
|
7
|
+
} from "../error";
|
|
8
|
+
import {
|
|
9
|
+
ChatCompletionTokenLogprob,
|
|
5
10
|
type ChatCompletion,
|
|
6
11
|
type ChatCompletionChunk,
|
|
7
12
|
type ChatCompletionCreateParams,
|
|
13
|
+
type ChatCompletionCreateParamsStreaming,
|
|
8
14
|
type ChatCompletionCreateParamsBase,
|
|
9
15
|
} from "../resources/chat/completions";
|
|
10
16
|
import {
|
|
@@ -13,22 +19,125 @@ import {
|
|
|
13
19
|
} from './AbstractChatCompletionRunner';
|
|
14
20
|
import { type ReadableStream } from "../_shims/index";
|
|
15
21
|
import { Stream } from "../streaming";
|
|
22
|
+
import OpenAI from "../index";
|
|
23
|
+
import { ParsedChatCompletion } from "../resources/beta/chat/completions";
|
|
24
|
+
import {
|
|
25
|
+
AutoParseableResponseFormat,
|
|
26
|
+
hasAutoParseableInput,
|
|
27
|
+
isAutoParsableResponseFormat,
|
|
28
|
+
isAutoParsableTool,
|
|
29
|
+
maybeParseChatCompletion,
|
|
30
|
+
shouldParseToolCall,
|
|
31
|
+
} from "./parser";
|
|
32
|
+
import { partialParse } from '../_vendor/partial-json-parser/parser';
|
|
33
|
+
|
|
34
|
+
export interface ContentDeltaEvent {
|
|
35
|
+
delta: string;
|
|
36
|
+
snapshot: string;
|
|
37
|
+
parsed: unknown | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface ContentDoneEvent<ParsedT = null> {
|
|
41
|
+
content: string;
|
|
42
|
+
parsed: ParsedT | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface RefusalDeltaEvent {
|
|
46
|
+
delta: string;
|
|
47
|
+
snapshot: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface RefusalDoneEvent {
|
|
51
|
+
refusal: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface FunctionToolCallArgumentsDeltaEvent {
|
|
55
|
+
name: string;
|
|
56
|
+
|
|
57
|
+
index: number;
|
|
58
|
+
|
|
59
|
+
arguments: string;
|
|
60
|
+
|
|
61
|
+
parsed_arguments: unknown;
|
|
62
|
+
|
|
63
|
+
arguments_delta: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface FunctionToolCallArgumentsDoneEvent {
|
|
67
|
+
name: string;
|
|
68
|
+
|
|
69
|
+
index: number;
|
|
70
|
+
|
|
71
|
+
arguments: string;
|
|
16
72
|
|
|
17
|
-
|
|
73
|
+
parsed_arguments: unknown;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface LogProbsContentDeltaEvent {
|
|
77
|
+
content: Array<ChatCompletionTokenLogprob>;
|
|
78
|
+
snapshot: Array<ChatCompletionTokenLogprob>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface LogProbsContentDoneEvent {
|
|
82
|
+
content: Array<ChatCompletionTokenLogprob>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface LogProbsRefusalDeltaEvent {
|
|
86
|
+
refusal: Array<ChatCompletionTokenLogprob>;
|
|
87
|
+
snapshot: Array<ChatCompletionTokenLogprob>;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface LogProbsRefusalDoneEvent {
|
|
91
|
+
refusal: Array<ChatCompletionTokenLogprob>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export interface ChatCompletionStreamEvents<ParsedT = null> extends AbstractChatCompletionRunnerEvents {
|
|
18
95
|
content: (contentDelta: string, contentSnapshot: string) => void;
|
|
19
96
|
chunk: (chunk: ChatCompletionChunk, snapshot: ChatCompletionSnapshot) => void;
|
|
97
|
+
|
|
98
|
+
'content.delta': (props: ContentDeltaEvent) => void;
|
|
99
|
+
'content.done': (props: ContentDoneEvent<ParsedT>) => void;
|
|
100
|
+
|
|
101
|
+
'refusal.delta': (props: RefusalDeltaEvent) => void;
|
|
102
|
+
'refusal.done': (props: RefusalDoneEvent) => void;
|
|
103
|
+
|
|
104
|
+
'tool_calls.function.arguments.delta': (props: FunctionToolCallArgumentsDeltaEvent) => void;
|
|
105
|
+
'tool_calls.function.arguments.done': (props: FunctionToolCallArgumentsDoneEvent) => void;
|
|
106
|
+
|
|
107
|
+
'logprobs.content.delta': (props: LogProbsContentDeltaEvent) => void;
|
|
108
|
+
'logprobs.content.done': (props: LogProbsContentDoneEvent) => void;
|
|
109
|
+
|
|
110
|
+
'logprobs.refusal.delta': (props: LogProbsRefusalDeltaEvent) => void;
|
|
111
|
+
'logprobs.refusal.done': (props: LogProbsRefusalDoneEvent) => void;
|
|
20
112
|
}
|
|
21
113
|
|
|
22
114
|
export type ChatCompletionStreamParams = Omit<ChatCompletionCreateParamsBase, 'stream'> & {
|
|
23
115
|
stream?: true;
|
|
24
116
|
};
|
|
25
117
|
|
|
26
|
-
|
|
27
|
-
|
|
118
|
+
interface ChoiceEventState {
|
|
119
|
+
content_done: boolean;
|
|
120
|
+
refusal_done: boolean;
|
|
121
|
+
logprobs_content_done: boolean;
|
|
122
|
+
logprobs_refusal_done: boolean;
|
|
123
|
+
current_tool_call_index: number | null;
|
|
124
|
+
done_tool_calls: Set<number>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export class ChatCompletionStream<ParsedT = null>
|
|
128
|
+
extends AbstractChatCompletionRunner<ChatCompletionStreamEvents<ParsedT>, ParsedT>
|
|
28
129
|
implements AsyncIterable<ChatCompletionChunk>
|
|
29
130
|
{
|
|
131
|
+
#params: ChatCompletionCreateParams | null;
|
|
132
|
+
#choiceEventStates: ChoiceEventState[];
|
|
30
133
|
#currentChatCompletionSnapshot: ChatCompletionSnapshot | undefined;
|
|
31
134
|
|
|
135
|
+
constructor(params: ChatCompletionCreateParams | null) {
|
|
136
|
+
super();
|
|
137
|
+
this.#params = params;
|
|
138
|
+
this.#choiceEventStates = [];
|
|
139
|
+
}
|
|
140
|
+
|
|
32
141
|
get currentChatCompletionSnapshot(): ChatCompletionSnapshot | undefined {
|
|
33
142
|
return this.#currentChatCompletionSnapshot;
|
|
34
143
|
}
|
|
@@ -40,21 +149,21 @@ export class ChatCompletionStream
|
|
|
40
149
|
* Note that messages sent to the model do not appear in `.on('message')`
|
|
41
150
|
* in this context.
|
|
42
151
|
*/
|
|
43
|
-
static fromReadableStream(stream: ReadableStream): ChatCompletionStream {
|
|
44
|
-
const runner = new ChatCompletionStream();
|
|
152
|
+
static fromReadableStream(stream: ReadableStream): ChatCompletionStream<null> {
|
|
153
|
+
const runner = new ChatCompletionStream(null);
|
|
45
154
|
runner._run(() => runner._fromReadableStream(stream));
|
|
46
155
|
return runner;
|
|
47
156
|
}
|
|
48
157
|
|
|
49
|
-
static createChatCompletion(
|
|
50
|
-
|
|
158
|
+
static createChatCompletion<ParsedT>(
|
|
159
|
+
client: OpenAI,
|
|
51
160
|
params: ChatCompletionStreamParams,
|
|
52
161
|
options?: Core.RequestOptions,
|
|
53
|
-
): ChatCompletionStream {
|
|
54
|
-
const runner = new ChatCompletionStream();
|
|
162
|
+
): ChatCompletionStream<ParsedT> {
|
|
163
|
+
const runner = new ChatCompletionStream<ParsedT>(params as ChatCompletionCreateParamsStreaming);
|
|
55
164
|
runner._run(() =>
|
|
56
165
|
runner._runChatCompletion(
|
|
57
|
-
|
|
166
|
+
client,
|
|
58
167
|
{ ...params, stream: true },
|
|
59
168
|
{ ...options, headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' } },
|
|
60
169
|
),
|
|
@@ -66,17 +175,184 @@ export class ChatCompletionStream
|
|
|
66
175
|
if (this.ended) return;
|
|
67
176
|
this.#currentChatCompletionSnapshot = undefined;
|
|
68
177
|
}
|
|
69
|
-
|
|
178
|
+
|
|
179
|
+
#getChoiceEventState(choice: ChatCompletionSnapshot.Choice): ChoiceEventState {
|
|
180
|
+
let state = this.#choiceEventStates[choice.index];
|
|
181
|
+
if (state) {
|
|
182
|
+
return state;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
state = {
|
|
186
|
+
content_done: false,
|
|
187
|
+
refusal_done: false,
|
|
188
|
+
logprobs_content_done: false,
|
|
189
|
+
logprobs_refusal_done: false,
|
|
190
|
+
done_tool_calls: new Set(),
|
|
191
|
+
current_tool_call_index: null,
|
|
192
|
+
};
|
|
193
|
+
this.#choiceEventStates[choice.index] = state;
|
|
194
|
+
return state;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
#addChunk(this: ChatCompletionStream<ParsedT>, chunk: ChatCompletionChunk) {
|
|
70
198
|
if (this.ended) return;
|
|
199
|
+
|
|
71
200
|
const completion = this.#accumulateChatCompletion(chunk);
|
|
72
201
|
this._emit('chunk', chunk, completion);
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
202
|
+
|
|
203
|
+
for (const choice of chunk.choices) {
|
|
204
|
+
const choiceSnapshot = completion.choices[choice.index]!;
|
|
205
|
+
|
|
206
|
+
if (
|
|
207
|
+
choice.delta.content != null &&
|
|
208
|
+
choiceSnapshot.message?.role === 'assistant' &&
|
|
209
|
+
choiceSnapshot.message?.content
|
|
210
|
+
) {
|
|
211
|
+
this._emit('content', choice.delta.content, choiceSnapshot.message.content);
|
|
212
|
+
this._emit('content.delta', {
|
|
213
|
+
delta: choice.delta.content,
|
|
214
|
+
snapshot: choiceSnapshot.message.content,
|
|
215
|
+
parsed: choiceSnapshot.message.parsed,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (
|
|
220
|
+
choice.delta.refusal != null &&
|
|
221
|
+
choiceSnapshot.message?.role === 'assistant' &&
|
|
222
|
+
choiceSnapshot.message?.refusal
|
|
223
|
+
) {
|
|
224
|
+
this._emit('refusal.delta', {
|
|
225
|
+
delta: choice.delta.refusal,
|
|
226
|
+
snapshot: choiceSnapshot.message.refusal,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (choice.logprobs?.content != null && choiceSnapshot.message?.role === 'assistant') {
|
|
231
|
+
this._emit('logprobs.content.delta', {
|
|
232
|
+
content: choice.logprobs?.content,
|
|
233
|
+
snapshot: choiceSnapshot.logprobs?.content ?? [],
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (choice.logprobs?.refusal != null && choiceSnapshot.message?.role === 'assistant') {
|
|
238
|
+
this._emit('logprobs.refusal.delta', {
|
|
239
|
+
refusal: choice.logprobs?.refusal,
|
|
240
|
+
snapshot: choiceSnapshot.logprobs?.refusal ?? [],
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const state = this.#getChoiceEventState(choiceSnapshot);
|
|
245
|
+
|
|
246
|
+
if (choiceSnapshot.finish_reason) {
|
|
247
|
+
this.#emitContentDoneEvents(choiceSnapshot);
|
|
248
|
+
|
|
249
|
+
if (state.current_tool_call_index != null) {
|
|
250
|
+
this.#emitToolCallDoneEvent(choiceSnapshot, state.current_tool_call_index);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
for (const toolCall of choice.delta.tool_calls ?? []) {
|
|
255
|
+
if (state.current_tool_call_index !== toolCall.index) {
|
|
256
|
+
this.#emitContentDoneEvents(choiceSnapshot);
|
|
257
|
+
|
|
258
|
+
// new tool call started, the previous one is done
|
|
259
|
+
if (state.current_tool_call_index != null) {
|
|
260
|
+
this.#emitToolCallDoneEvent(choiceSnapshot, state.current_tool_call_index);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
state.current_tool_call_index = toolCall.index;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
for (const toolCallDelta of choice.delta.tool_calls ?? []) {
|
|
268
|
+
const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallDelta.index];
|
|
269
|
+
if (!toolCallSnapshot?.type) {
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (toolCallSnapshot?.type === 'function') {
|
|
274
|
+
this._emit('tool_calls.function.arguments.delta', {
|
|
275
|
+
name: toolCallSnapshot.function?.name,
|
|
276
|
+
index: toolCallDelta.index,
|
|
277
|
+
arguments: toolCallSnapshot.function.arguments,
|
|
278
|
+
parsed_arguments: toolCallSnapshot.function.parsed_arguments,
|
|
279
|
+
arguments_delta: toolCallDelta.function?.arguments ?? '',
|
|
280
|
+
});
|
|
281
|
+
} else {
|
|
282
|
+
assertNever(toolCallSnapshot?.type);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
77
285
|
}
|
|
78
286
|
}
|
|
79
|
-
|
|
287
|
+
|
|
288
|
+
#emitToolCallDoneEvent(choiceSnapshot: ChatCompletionSnapshot.Choice, toolCallIndex: number) {
|
|
289
|
+
const state = this.#getChoiceEventState(choiceSnapshot);
|
|
290
|
+
if (state.done_tool_calls.has(toolCallIndex)) {
|
|
291
|
+
// we've already fired the done event
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const toolCallSnapshot = choiceSnapshot.message.tool_calls?.[toolCallIndex];
|
|
296
|
+
if (!toolCallSnapshot) {
|
|
297
|
+
throw new Error('no tool call snapshot');
|
|
298
|
+
}
|
|
299
|
+
if (!toolCallSnapshot.type) {
|
|
300
|
+
throw new Error('tool call snapshot missing `type`');
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (toolCallSnapshot.type === 'function') {
|
|
304
|
+
const inputTool = this.#params?.tools?.find(
|
|
305
|
+
(tool) => tool.type === 'function' && tool.function.name === toolCallSnapshot.function.name,
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
this._emit('tool_calls.function.arguments.done', {
|
|
309
|
+
name: toolCallSnapshot.function.name,
|
|
310
|
+
index: toolCallIndex,
|
|
311
|
+
arguments: toolCallSnapshot.function.arguments,
|
|
312
|
+
parsed_arguments:
|
|
313
|
+
isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCallSnapshot.function.arguments)
|
|
314
|
+
: inputTool?.function.strict ? JSON.parse(toolCallSnapshot.function.arguments)
|
|
315
|
+
: null,
|
|
316
|
+
});
|
|
317
|
+
} else {
|
|
318
|
+
assertNever(toolCallSnapshot.type);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
#emitContentDoneEvents(choiceSnapshot: ChatCompletionSnapshot.Choice) {
|
|
323
|
+
const state = this.#getChoiceEventState(choiceSnapshot);
|
|
324
|
+
|
|
325
|
+
if (choiceSnapshot.message.content && !state.content_done) {
|
|
326
|
+
state.content_done = true;
|
|
327
|
+
|
|
328
|
+
const responseFormat = this.#getAutoParseableResponseFormat();
|
|
329
|
+
|
|
330
|
+
this._emit('content.done', {
|
|
331
|
+
content: choiceSnapshot.message.content,
|
|
332
|
+
parsed: responseFormat ? responseFormat.$parseRaw(choiceSnapshot.message.content) : (null as any),
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (choiceSnapshot.message.refusal && !state.refusal_done) {
|
|
337
|
+
state.refusal_done = true;
|
|
338
|
+
|
|
339
|
+
this._emit('refusal.done', { refusal: choiceSnapshot.message.refusal });
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (choiceSnapshot.logprobs?.content && !state.logprobs_content_done) {
|
|
343
|
+
state.logprobs_content_done = true;
|
|
344
|
+
|
|
345
|
+
this._emit('logprobs.content.done', { content: choiceSnapshot.logprobs.content });
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (choiceSnapshot.logprobs?.refusal && !state.logprobs_refusal_done) {
|
|
349
|
+
state.logprobs_refusal_done = true;
|
|
350
|
+
|
|
351
|
+
this._emit('logprobs.refusal.done', { refusal: choiceSnapshot.logprobs.refusal });
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
#endRequest(): ParsedChatCompletion<ParsedT> {
|
|
80
356
|
if (this.ended) {
|
|
81
357
|
throw new OpenAIError(`stream has ended, this shouldn't happen`);
|
|
82
358
|
}
|
|
@@ -85,21 +361,24 @@ export class ChatCompletionStream
|
|
|
85
361
|
throw new OpenAIError(`request ended without sending any chunks`);
|
|
86
362
|
}
|
|
87
363
|
this.#currentChatCompletionSnapshot = undefined;
|
|
88
|
-
|
|
364
|
+
this.#choiceEventStates = [];
|
|
365
|
+
return finalizeChatCompletion(snapshot, this.#params);
|
|
89
366
|
}
|
|
90
367
|
|
|
91
368
|
protected override async _createChatCompletion(
|
|
92
|
-
|
|
369
|
+
client: OpenAI,
|
|
93
370
|
params: ChatCompletionCreateParams,
|
|
94
371
|
options?: Core.RequestOptions,
|
|
95
|
-
): Promise<
|
|
372
|
+
): Promise<ParsedChatCompletion<ParsedT>> {
|
|
373
|
+
super._createChatCompletion;
|
|
96
374
|
const signal = options?.signal;
|
|
97
375
|
if (signal) {
|
|
98
376
|
if (signal.aborted) this.controller.abort();
|
|
99
377
|
signal.addEventListener('abort', () => this.controller.abort());
|
|
100
378
|
}
|
|
101
379
|
this.#beginRequest();
|
|
102
|
-
|
|
380
|
+
|
|
381
|
+
const stream = await client.chat.completions.create(
|
|
103
382
|
{ ...params, stream: true },
|
|
104
383
|
{ ...options, signal: this.controller.signal },
|
|
105
384
|
);
|
|
@@ -141,6 +420,15 @@ export class ChatCompletionStream
|
|
|
141
420
|
return this._addChatCompletion(this.#endRequest());
|
|
142
421
|
}
|
|
143
422
|
|
|
423
|
+
#getAutoParseableResponseFormat(): AutoParseableResponseFormat<ParsedT> | null {
|
|
424
|
+
const responseFormat = this.#params?.response_format;
|
|
425
|
+
if (isAutoParsableResponseFormat<ParsedT>(responseFormat)) {
|
|
426
|
+
return responseFormat;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
|
|
144
432
|
#accumulateChatCompletion(chunk: ChatCompletionChunk): ChatCompletionSnapshot {
|
|
145
433
|
let snapshot = this.#currentChatCompletionSnapshot;
|
|
146
434
|
const { choices, ...rest } = chunk;
|
|
@@ -163,23 +451,48 @@ export class ChatCompletionStream
|
|
|
163
451
|
if (!choice.logprobs) {
|
|
164
452
|
choice.logprobs = Object.assign({}, logprobs);
|
|
165
453
|
} else {
|
|
166
|
-
const { content, ...rest } = logprobs;
|
|
454
|
+
const { content, refusal, ...rest } = logprobs;
|
|
455
|
+
assertIsEmpty(rest);
|
|
167
456
|
Object.assign(choice.logprobs, rest);
|
|
457
|
+
|
|
168
458
|
if (content) {
|
|
169
459
|
choice.logprobs.content ??= [];
|
|
170
460
|
choice.logprobs.content.push(...content);
|
|
171
461
|
}
|
|
462
|
+
|
|
463
|
+
if (refusal) {
|
|
464
|
+
choice.logprobs.refusal ??= [];
|
|
465
|
+
choice.logprobs.refusal.push(...refusal);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (finish_reason) {
|
|
471
|
+
choice.finish_reason = finish_reason;
|
|
472
|
+
|
|
473
|
+
if (this.#params && hasAutoParseableInput(this.#params)) {
|
|
474
|
+
if (finish_reason === 'length') {
|
|
475
|
+
throw new LengthFinishReasonError();
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (finish_reason === 'content_filter') {
|
|
479
|
+
throw new ContentFilterFinishReasonError();
|
|
480
|
+
}
|
|
172
481
|
}
|
|
173
482
|
}
|
|
174
483
|
|
|
175
|
-
if (finish_reason) choice.finish_reason = finish_reason;
|
|
176
484
|
Object.assign(choice, other);
|
|
177
485
|
|
|
178
486
|
if (!delta) continue; // Shouldn't happen; just in case.
|
|
179
|
-
|
|
487
|
+
|
|
488
|
+
const { content, refusal, function_call, role, tool_calls, ...rest } = delta;
|
|
489
|
+
assertIsEmpty(rest);
|
|
180
490
|
Object.assign(choice.message, rest);
|
|
181
491
|
|
|
182
|
-
if (
|
|
492
|
+
if (refusal) {
|
|
493
|
+
choice.message.refusal = (choice.message.refusal || '') + refusal;
|
|
494
|
+
}
|
|
495
|
+
|
|
183
496
|
if (role) choice.message.role = role;
|
|
184
497
|
if (function_call) {
|
|
185
498
|
if (!choice.message.function_call) {
|
|
@@ -192,23 +505,39 @@ export class ChatCompletionStream
|
|
|
192
505
|
}
|
|
193
506
|
}
|
|
194
507
|
}
|
|
508
|
+
if (content) {
|
|
509
|
+
choice.message.content = (choice.message.content || '') + content;
|
|
510
|
+
|
|
511
|
+
if (!choice.message.refusal && this.#getAutoParseableResponseFormat()) {
|
|
512
|
+
choice.message.parsed = partialParse(choice.message.content);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
195
516
|
if (tool_calls) {
|
|
196
517
|
if (!choice.message.tool_calls) choice.message.tool_calls = [];
|
|
518
|
+
|
|
197
519
|
for (const { index, id, type, function: fn, ...rest } of tool_calls) {
|
|
198
|
-
const tool_call = (choice.message.tool_calls[index] ??=
|
|
520
|
+
const tool_call = (choice.message.tool_calls[index] ??=
|
|
521
|
+
{} as ChatCompletionSnapshot.Choice.Message.ToolCall);
|
|
199
522
|
Object.assign(tool_call, rest);
|
|
200
523
|
if (id) tool_call.id = id;
|
|
201
524
|
if (type) tool_call.type = type;
|
|
202
|
-
if (fn) tool_call.function ??= { arguments: '' };
|
|
525
|
+
if (fn) tool_call.function ??= { name: fn.name ?? '', arguments: '' };
|
|
203
526
|
if (fn?.name) tool_call.function!.name = fn.name;
|
|
204
|
-
if (fn?.arguments)
|
|
527
|
+
if (fn?.arguments) {
|
|
528
|
+
tool_call.function!.arguments += fn.arguments;
|
|
529
|
+
|
|
530
|
+
if (shouldParseToolCall(this.#params, tool_call)) {
|
|
531
|
+
tool_call.function!.parsed_arguments = partialParse(tool_call.function!.arguments);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
205
534
|
}
|
|
206
535
|
}
|
|
207
536
|
}
|
|
208
537
|
return snapshot;
|
|
209
538
|
}
|
|
210
539
|
|
|
211
|
-
[Symbol.asyncIterator](): AsyncIterator<ChatCompletionChunk> {
|
|
540
|
+
[Symbol.asyncIterator](this: ChatCompletionStream<ParsedT>): AsyncIterator<ChatCompletionChunk> {
|
|
212
541
|
const pushQueue: ChatCompletionChunk[] = [];
|
|
213
542
|
const readQueue: {
|
|
214
543
|
resolve: (chunk: ChatCompletionChunk | undefined) => void;
|
|
@@ -275,29 +604,50 @@ export class ChatCompletionStream
|
|
|
275
604
|
}
|
|
276
605
|
}
|
|
277
606
|
|
|
278
|
-
function finalizeChatCompletion(
|
|
607
|
+
function finalizeChatCompletion<ParsedT>(
|
|
608
|
+
snapshot: ChatCompletionSnapshot,
|
|
609
|
+
params: ChatCompletionCreateParams | null,
|
|
610
|
+
): ParsedChatCompletion<ParsedT> {
|
|
279
611
|
const { id, choices, created, model, system_fingerprint, ...rest } = snapshot;
|
|
280
|
-
|
|
612
|
+
const completion: ChatCompletion = {
|
|
281
613
|
...rest,
|
|
282
614
|
id,
|
|
283
615
|
choices: choices.map(
|
|
284
616
|
({ message, finish_reason, index, logprobs, ...choiceRest }): ChatCompletion.Choice => {
|
|
285
|
-
if (!finish_reason)
|
|
617
|
+
if (!finish_reason) {
|
|
618
|
+
throw new OpenAIError(`missing finish_reason for choice ${index}`);
|
|
619
|
+
}
|
|
620
|
+
|
|
286
621
|
const { content = null, function_call, tool_calls, ...messageRest } = message;
|
|
287
622
|
const role = message.role as 'assistant'; // this is what we expect; in theory it could be different which would make our types a slight lie but would be fine.
|
|
288
|
-
if (!role)
|
|
623
|
+
if (!role) {
|
|
624
|
+
throw new OpenAIError(`missing role for choice ${index}`);
|
|
625
|
+
}
|
|
626
|
+
|
|
289
627
|
if (function_call) {
|
|
290
628
|
const { arguments: args, name } = function_call;
|
|
291
|
-
if (args == null)
|
|
292
|
-
|
|
629
|
+
if (args == null) {
|
|
630
|
+
throw new OpenAIError(`missing function_call.arguments for choice ${index}`);
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if (!name) {
|
|
634
|
+
throw new OpenAIError(`missing function_call.name for choice ${index}`);
|
|
635
|
+
}
|
|
636
|
+
|
|
293
637
|
return {
|
|
294
638
|
...choiceRest,
|
|
295
|
-
message: {
|
|
639
|
+
message: {
|
|
640
|
+
content,
|
|
641
|
+
function_call: { arguments: args, name },
|
|
642
|
+
role,
|
|
643
|
+
refusal: message.refusal ?? null,
|
|
644
|
+
},
|
|
296
645
|
finish_reason,
|
|
297
646
|
index,
|
|
298
647
|
logprobs,
|
|
299
648
|
};
|
|
300
649
|
}
|
|
650
|
+
|
|
301
651
|
if (tool_calls) {
|
|
302
652
|
return {
|
|
303
653
|
...choiceRest,
|
|
@@ -308,21 +658,26 @@ function finalizeChatCompletion(snapshot: ChatCompletionSnapshot): ChatCompletio
|
|
|
308
658
|
...messageRest,
|
|
309
659
|
role,
|
|
310
660
|
content,
|
|
661
|
+
refusal: message.refusal ?? null,
|
|
311
662
|
tool_calls: tool_calls.map((tool_call, i) => {
|
|
312
663
|
const { function: fn, type, id, ...toolRest } = tool_call;
|
|
313
664
|
const { arguments: args, name, ...fnRest } = fn || {};
|
|
314
|
-
if (id == null)
|
|
665
|
+
if (id == null) {
|
|
315
666
|
throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].id\n${str(snapshot)}`);
|
|
316
|
-
|
|
667
|
+
}
|
|
668
|
+
if (type == null) {
|
|
317
669
|
throw new OpenAIError(`missing choices[${index}].tool_calls[${i}].type\n${str(snapshot)}`);
|
|
318
|
-
|
|
670
|
+
}
|
|
671
|
+
if (name == null) {
|
|
319
672
|
throw new OpenAIError(
|
|
320
673
|
`missing choices[${index}].tool_calls[${i}].function.name\n${str(snapshot)}`,
|
|
321
674
|
);
|
|
322
|
-
|
|
675
|
+
}
|
|
676
|
+
if (args == null) {
|
|
323
677
|
throw new OpenAIError(
|
|
324
678
|
`missing choices[${index}].tool_calls[${i}].function.arguments\n${str(snapshot)}`,
|
|
325
679
|
);
|
|
680
|
+
}
|
|
326
681
|
|
|
327
682
|
return { ...toolRest, id, type, function: { ...fnRest, name, arguments: args } };
|
|
328
683
|
}),
|
|
@@ -331,7 +686,7 @@ function finalizeChatCompletion(snapshot: ChatCompletionSnapshot): ChatCompletio
|
|
|
331
686
|
}
|
|
332
687
|
return {
|
|
333
688
|
...choiceRest,
|
|
334
|
-
message: { ...messageRest, content, role },
|
|
689
|
+
message: { ...messageRest, content, role, refusal: message.refusal ?? null },
|
|
335
690
|
finish_reason,
|
|
336
691
|
index,
|
|
337
692
|
logprobs,
|
|
@@ -343,6 +698,8 @@ function finalizeChatCompletion(snapshot: ChatCompletionSnapshot): ChatCompletio
|
|
|
343
698
|
object: 'chat.completion',
|
|
344
699
|
...(system_fingerprint ? { system_fingerprint } : {}),
|
|
345
700
|
};
|
|
701
|
+
|
|
702
|
+
return maybeParseChatCompletion(completion, params);
|
|
346
703
|
}
|
|
347
704
|
|
|
348
705
|
function str(x: unknown) {
|
|
@@ -425,6 +782,10 @@ export namespace ChatCompletionSnapshot {
|
|
|
425
782
|
*/
|
|
426
783
|
content?: string | null;
|
|
427
784
|
|
|
785
|
+
refusal?: string | null;
|
|
786
|
+
|
|
787
|
+
parsed?: unknown | null;
|
|
788
|
+
|
|
428
789
|
/**
|
|
429
790
|
* The name and arguments of a function that should be called, as generated by the
|
|
430
791
|
* model.
|
|
@@ -444,14 +805,14 @@ export namespace ChatCompletionSnapshot {
|
|
|
444
805
|
/**
|
|
445
806
|
* The ID of the tool call.
|
|
446
807
|
*/
|
|
447
|
-
id
|
|
808
|
+
id: string;
|
|
448
809
|
|
|
449
|
-
function
|
|
810
|
+
function: ToolCall.Function;
|
|
450
811
|
|
|
451
812
|
/**
|
|
452
813
|
* The type of the tool.
|
|
453
814
|
*/
|
|
454
|
-
type
|
|
815
|
+
type: 'function';
|
|
455
816
|
}
|
|
456
817
|
|
|
457
818
|
export namespace ToolCall {
|
|
@@ -462,12 +823,14 @@ export namespace ChatCompletionSnapshot {
|
|
|
462
823
|
* hallucinate parameters not defined by your function schema. Validate the
|
|
463
824
|
* arguments in your code before calling your function.
|
|
464
825
|
*/
|
|
465
|
-
arguments
|
|
826
|
+
arguments: string;
|
|
827
|
+
|
|
828
|
+
parsed_arguments?: unknown;
|
|
466
829
|
|
|
467
830
|
/**
|
|
468
831
|
* The name of the function to call.
|
|
469
832
|
*/
|
|
470
|
-
name
|
|
833
|
+
name: string;
|
|
471
834
|
}
|
|
472
835
|
}
|
|
473
836
|
|
|
@@ -492,3 +855,16 @@ export namespace ChatCompletionSnapshot {
|
|
|
492
855
|
}
|
|
493
856
|
}
|
|
494
857
|
}
|
|
858
|
+
|
|
859
|
+
type AssertIsEmpty<T extends {}> = keyof T extends never ? T : never;
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Ensures the given argument is an empty object, useful for
|
|
863
|
+
* asserting that all known properties on an object have been
|
|
864
|
+
* destructured.
|
|
865
|
+
*/
|
|
866
|
+
function assertIsEmpty<T extends {}>(obj: AssertIsEmpty<T>): asserts obj is AssertIsEmpty<T> {
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
function assertNever(_x: never) {}
|