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,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Completions,
|
|
3
2
|
type ChatCompletionChunk,
|
|
4
3
|
type ChatCompletionCreateParamsStreaming,
|
|
5
4
|
} from "../resources/chat/completions";
|
|
@@ -7,6 +6,8 @@ import { RunnerOptions, type AbstractChatCompletionRunnerEvents } from './Abstra
|
|
|
7
6
|
import { type ReadableStream } from "../_shims/index";
|
|
8
7
|
import { RunnableTools, type BaseFunctionsArgs, type RunnableFunctions } from './RunnableFunction';
|
|
9
8
|
import { ChatCompletionSnapshot, ChatCompletionStream } from './ChatCompletionStream';
|
|
9
|
+
import OpenAI from "../index";
|
|
10
|
+
import { AutoParseableTool } from "./parser";
|
|
10
11
|
|
|
11
12
|
export interface ChatCompletionStreamEvents extends AbstractChatCompletionRunnerEvents {
|
|
12
13
|
content: (contentDelta: string, contentSnapshot: string) => void;
|
|
@@ -24,45 +25,48 @@ export type ChatCompletionStreamingToolRunnerParams<FunctionsArgs extends BaseFu
|
|
|
24
25
|
ChatCompletionCreateParamsStreaming,
|
|
25
26
|
'tools'
|
|
26
27
|
> & {
|
|
27
|
-
tools: RunnableTools<FunctionsArgs
|
|
28
|
+
tools: RunnableTools<FunctionsArgs> | AutoParseableTool<any, true>[];
|
|
28
29
|
};
|
|
29
30
|
|
|
30
|
-
export class ChatCompletionStreamingRunner
|
|
31
|
-
extends ChatCompletionStream
|
|
31
|
+
export class ChatCompletionStreamingRunner<ParsedT = null>
|
|
32
|
+
extends ChatCompletionStream<ParsedT>
|
|
32
33
|
implements AsyncIterable<ChatCompletionChunk>
|
|
33
34
|
{
|
|
34
|
-
static override fromReadableStream(stream: ReadableStream): ChatCompletionStreamingRunner {
|
|
35
|
-
const runner = new ChatCompletionStreamingRunner();
|
|
35
|
+
static override fromReadableStream(stream: ReadableStream): ChatCompletionStreamingRunner<null> {
|
|
36
|
+
const runner = new ChatCompletionStreamingRunner(null);
|
|
36
37
|
runner._run(() => runner._fromReadableStream(stream));
|
|
37
38
|
return runner;
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
/** @deprecated - please use `runTools` instead. */
|
|
41
42
|
static runFunctions<T extends (string | object)[]>(
|
|
42
|
-
|
|
43
|
+
client: OpenAI,
|
|
43
44
|
params: ChatCompletionStreamingFunctionRunnerParams<T>,
|
|
44
45
|
options?: RunnerOptions,
|
|
45
|
-
): ChatCompletionStreamingRunner {
|
|
46
|
-
const runner = new ChatCompletionStreamingRunner();
|
|
46
|
+
): ChatCompletionStreamingRunner<null> {
|
|
47
|
+
const runner = new ChatCompletionStreamingRunner(null);
|
|
47
48
|
const opts = {
|
|
48
49
|
...options,
|
|
49
50
|
headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'runFunctions' },
|
|
50
51
|
};
|
|
51
|
-
runner._run(() => runner._runFunctions(
|
|
52
|
+
runner._run(() => runner._runFunctions(client, params, opts));
|
|
52
53
|
return runner;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
static runTools<T extends (string | object)[]>(
|
|
56
|
-
|
|
56
|
+
static runTools<T extends (string | object)[], ParsedT = null>(
|
|
57
|
+
client: OpenAI,
|
|
57
58
|
params: ChatCompletionStreamingToolRunnerParams<T>,
|
|
58
59
|
options?: RunnerOptions,
|
|
59
|
-
): ChatCompletionStreamingRunner {
|
|
60
|
-
const runner = new ChatCompletionStreamingRunner(
|
|
60
|
+
): ChatCompletionStreamingRunner<ParsedT> {
|
|
61
|
+
const runner = new ChatCompletionStreamingRunner<ParsedT>(
|
|
62
|
+
// @ts-expect-error TODO these types are incompatible
|
|
63
|
+
params,
|
|
64
|
+
);
|
|
61
65
|
const opts = {
|
|
62
66
|
...options,
|
|
63
67
|
headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'runTools' },
|
|
64
68
|
};
|
|
65
|
-
runner._run(() => runner._runTools(
|
|
69
|
+
runner._run(() => runner._runTools(client, params, opts));
|
|
66
70
|
return runner;
|
|
67
71
|
}
|
|
68
72
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import * as Core from "../core";
|
|
2
1
|
import { APIUserAbortError, OpenAIError } from "../error";
|
|
3
|
-
import { Run, RunSubmitToolOutputsParamsBase } from "../resources/beta/threads/runs/runs";
|
|
4
|
-
import { RunCreateParamsBase, Runs } from "../resources/beta/threads/runs/runs";
|
|
5
|
-
import { ThreadCreateAndRunParamsBase, Threads } from "../resources/beta/threads/threads";
|
|
6
2
|
|
|
7
|
-
export
|
|
8
|
-
Events extends CustomEvents<any> = AbstractAssistantRunnerEvents,
|
|
9
|
-
> {
|
|
3
|
+
export class EventStream<EventTypes extends BaseEvents> {
|
|
10
4
|
controller: AbortController = new AbortController();
|
|
11
5
|
|
|
12
6
|
#connectedPromise: Promise<void>;
|
|
@@ -17,7 +11,9 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
17
11
|
#resolveEndPromise: () => void = () => {};
|
|
18
12
|
#rejectEndPromise: (error: OpenAIError) => void = () => {};
|
|
19
13
|
|
|
20
|
-
#listeners: {
|
|
14
|
+
#listeners: {
|
|
15
|
+
[Event in keyof EventTypes]?: EventListeners<EventTypes, Event>;
|
|
16
|
+
} = {};
|
|
21
17
|
|
|
22
18
|
#ended = false;
|
|
23
19
|
#errored = false;
|
|
@@ -43,22 +39,18 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
43
39
|
this.#endPromise.catch(() => {});
|
|
44
40
|
}
|
|
45
41
|
|
|
46
|
-
protected _run(executor: () => Promise<any>) {
|
|
42
|
+
protected _run(this: EventStream<EventTypes>, executor: () => Promise<any>) {
|
|
47
43
|
// Unfortunately if we call `executor()` immediately we get runtime errors about
|
|
48
44
|
// references to `this` before the `super()` constructor call returns.
|
|
49
45
|
setTimeout(() => {
|
|
50
46
|
executor().then(() => {
|
|
51
|
-
|
|
47
|
+
this._emitFinal();
|
|
52
48
|
this._emit('end');
|
|
53
|
-
}, this.#handleError);
|
|
49
|
+
}, this.#handleError.bind(this));
|
|
54
50
|
}, 0);
|
|
55
51
|
}
|
|
56
52
|
|
|
57
|
-
protected
|
|
58
|
-
return run;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected _connected() {
|
|
53
|
+
protected _connected(this: EventStream<EventTypes>) {
|
|
62
54
|
if (this.ended) return;
|
|
63
55
|
this.#resolveConnectedPromise();
|
|
64
56
|
this._emit('connect');
|
|
@@ -87,8 +79,8 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
87
79
|
* called, multiple times.
|
|
88
80
|
* @returns this ChatCompletionStream, so that calls can be chained
|
|
89
81
|
*/
|
|
90
|
-
on<Event extends keyof
|
|
91
|
-
const listeners:
|
|
82
|
+
on<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {
|
|
83
|
+
const listeners: EventListeners<EventTypes, Event> =
|
|
92
84
|
this.#listeners[event] || (this.#listeners[event] = []);
|
|
93
85
|
listeners.push({ listener });
|
|
94
86
|
return this;
|
|
@@ -101,7 +93,7 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
101
93
|
* off() must be called multiple times to remove each instance.
|
|
102
94
|
* @returns this ChatCompletionStream, so that calls can be chained
|
|
103
95
|
*/
|
|
104
|
-
off<Event extends keyof
|
|
96
|
+
off<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {
|
|
105
97
|
const listeners = this.#listeners[event];
|
|
106
98
|
if (!listeners) return this;
|
|
107
99
|
const index = listeners.findIndex((l) => l.listener === listener);
|
|
@@ -114,8 +106,8 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
114
106
|
* this listener is removed and then invoked.
|
|
115
107
|
* @returns this ChatCompletionStream, so that calls can be chained
|
|
116
108
|
*/
|
|
117
|
-
once<Event extends keyof
|
|
118
|
-
const listeners:
|
|
109
|
+
once<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this {
|
|
110
|
+
const listeners: EventListeners<EventTypes, Event> =
|
|
119
111
|
this.#listeners[event] || (this.#listeners[event] = []);
|
|
120
112
|
listeners.push({ listener, once: true });
|
|
121
113
|
return this;
|
|
@@ -132,12 +124,12 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
132
124
|
*
|
|
133
125
|
* const message = await stream.emitted('message') // rejects if the stream errors
|
|
134
126
|
*/
|
|
135
|
-
emitted<Event extends keyof
|
|
127
|
+
emitted<Event extends keyof EventTypes>(
|
|
136
128
|
event: Event,
|
|
137
129
|
): Promise<
|
|
138
|
-
EventParameters<
|
|
139
|
-
: EventParameters<
|
|
140
|
-
: EventParameters<
|
|
130
|
+
EventParameters<EventTypes, Event> extends [infer Param] ? Param
|
|
131
|
+
: EventParameters<EventTypes, Event> extends [] ? void
|
|
132
|
+
: EventParameters<EventTypes, Event>
|
|
141
133
|
> {
|
|
142
134
|
return new Promise((resolve, reject) => {
|
|
143
135
|
this.#catchingPromiseCreated = true;
|
|
@@ -151,7 +143,7 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
151
143
|
await this.#endPromise;
|
|
152
144
|
}
|
|
153
145
|
|
|
154
|
-
#handleError
|
|
146
|
+
#handleError(this: EventStream<EventTypes>, error: unknown) {
|
|
155
147
|
this.#errored = true;
|
|
156
148
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
157
149
|
error = new APIUserAbortError();
|
|
@@ -170,9 +162,15 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
170
162
|
return this._emit('error', openAIError);
|
|
171
163
|
}
|
|
172
164
|
return this._emit('error', new OpenAIError(String(error)));
|
|
173
|
-
}
|
|
165
|
+
}
|
|
174
166
|
|
|
175
|
-
|
|
167
|
+
_emit<Event extends keyof BaseEvents>(event: Event, ...args: EventParameters<BaseEvents, Event>): void;
|
|
168
|
+
_emit<Event extends keyof EventTypes>(event: Event, ...args: EventParameters<EventTypes, Event>): void;
|
|
169
|
+
_emit<Event extends keyof EventTypes>(
|
|
170
|
+
this: EventStream<EventTypes>,
|
|
171
|
+
event: Event,
|
|
172
|
+
...args: EventParameters<EventTypes, Event>
|
|
173
|
+
) {
|
|
176
174
|
// make sure we don't emit any events after end
|
|
177
175
|
if (this.#ended) {
|
|
178
176
|
return;
|
|
@@ -183,10 +181,10 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
183
181
|
this.#resolveEndPromise();
|
|
184
182
|
}
|
|
185
183
|
|
|
186
|
-
const listeners:
|
|
184
|
+
const listeners: EventListeners<EventTypes, Event> | undefined = this.#listeners[event];
|
|
187
185
|
if (listeners) {
|
|
188
186
|
this.#listeners[event] = listeners.filter((l) => !l.once) as any;
|
|
189
|
-
listeners.forEach(({ listener }: any) => listener(...args));
|
|
187
|
+
listeners.forEach(({ listener }: any) => listener(...(args as any)));
|
|
190
188
|
}
|
|
191
189
|
|
|
192
190
|
if (event === 'abort') {
|
|
@@ -219,121 +217,22 @@ export abstract class AbstractAssistantStreamRunner<
|
|
|
219
217
|
}
|
|
220
218
|
}
|
|
221
219
|
|
|
222
|
-
protected
|
|
223
|
-
body: ThreadCreateAndRunParamsBase,
|
|
224
|
-
thread: Threads,
|
|
225
|
-
options?: Core.RequestOptions,
|
|
226
|
-
): Promise<Run> {
|
|
227
|
-
return await this._createThreadAssistantStream(thread, body, options);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
protected async _runAssistantStream(
|
|
231
|
-
threadId: string,
|
|
232
|
-
runs: Runs,
|
|
233
|
-
params: RunCreateParamsBase,
|
|
234
|
-
options?: Core.RequestOptions,
|
|
235
|
-
): Promise<Run> {
|
|
236
|
-
return await this._createAssistantStream(runs, threadId, params, options);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
protected async _runToolAssistantStream(
|
|
240
|
-
threadId: string,
|
|
241
|
-
runId: string,
|
|
242
|
-
runs: Runs,
|
|
243
|
-
params: RunSubmitToolOutputsParamsBase,
|
|
244
|
-
options?: Core.RequestOptions,
|
|
245
|
-
): Promise<Run> {
|
|
246
|
-
return await this._createToolAssistantStream(runs, threadId, runId, params, options);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
protected async _createThreadAssistantStream(
|
|
250
|
-
thread: Threads,
|
|
251
|
-
body: ThreadCreateAndRunParamsBase,
|
|
252
|
-
options?: Core.RequestOptions,
|
|
253
|
-
): Promise<Run> {
|
|
254
|
-
const signal = options?.signal;
|
|
255
|
-
if (signal) {
|
|
256
|
-
if (signal.aborted) this.controller.abort();
|
|
257
|
-
signal.addEventListener('abort', () => this.controller.abort());
|
|
258
|
-
}
|
|
259
|
-
// this.#validateParams(params);
|
|
260
|
-
|
|
261
|
-
const runResult = await thread.createAndRun(
|
|
262
|
-
{ ...body, stream: false },
|
|
263
|
-
{ ...options, signal: this.controller.signal },
|
|
264
|
-
);
|
|
265
|
-
this._connected();
|
|
266
|
-
return this._addRun(runResult as Run);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
protected async _createToolAssistantStream(
|
|
270
|
-
run: Runs,
|
|
271
|
-
threadId: string,
|
|
272
|
-
runId: string,
|
|
273
|
-
params: RunSubmitToolOutputsParamsBase,
|
|
274
|
-
options?: Core.RequestOptions,
|
|
275
|
-
): Promise<Run> {
|
|
276
|
-
const signal = options?.signal;
|
|
277
|
-
if (signal) {
|
|
278
|
-
if (signal.aborted) this.controller.abort();
|
|
279
|
-
signal.addEventListener('abort', () => this.controller.abort());
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const runResult = await run.submitToolOutputs(
|
|
283
|
-
threadId,
|
|
284
|
-
runId,
|
|
285
|
-
{ ...params, stream: false },
|
|
286
|
-
{ ...options, signal: this.controller.signal },
|
|
287
|
-
);
|
|
288
|
-
this._connected();
|
|
289
|
-
return this._addRun(runResult as Run);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
protected async _createAssistantStream(
|
|
293
|
-
run: Runs,
|
|
294
|
-
threadId: string,
|
|
295
|
-
params: RunCreateParamsBase,
|
|
296
|
-
options?: Core.RequestOptions,
|
|
297
|
-
): Promise<Run> {
|
|
298
|
-
const signal = options?.signal;
|
|
299
|
-
if (signal) {
|
|
300
|
-
if (signal.aborted) this.controller.abort();
|
|
301
|
-
signal.addEventListener('abort', () => this.controller.abort());
|
|
302
|
-
}
|
|
303
|
-
// this.#validateParams(params);
|
|
304
|
-
|
|
305
|
-
const runResult = await run.create(
|
|
306
|
-
threadId,
|
|
307
|
-
{ ...params, stream: false },
|
|
308
|
-
{ ...options, signal: this.controller.signal },
|
|
309
|
-
);
|
|
310
|
-
this._connected();
|
|
311
|
-
return this._addRun(runResult as Run);
|
|
312
|
-
}
|
|
220
|
+
protected _emitFinal(): void {}
|
|
313
221
|
}
|
|
314
222
|
|
|
315
|
-
type
|
|
316
|
-
[k in Event]: k extends keyof AbstractAssistantRunnerEvents ? AbstractAssistantRunnerEvents[k]
|
|
317
|
-
: (...args: any[]) => void;
|
|
318
|
-
};
|
|
223
|
+
type EventListener<Events, EventType extends keyof Events> = Events[EventType];
|
|
319
224
|
|
|
320
|
-
type
|
|
321
|
-
|
|
322
|
-
) ?
|
|
323
|
-
AbstractAssistantRunnerEvents[Event]
|
|
324
|
-
: Events[Event];
|
|
325
|
-
|
|
326
|
-
type ListenersForEvent<Events extends CustomEvents<any>, Event extends keyof Events> = Array<{
|
|
327
|
-
listener: ListenerForEvent<Events, Event>;
|
|
225
|
+
type EventListeners<Events, EventType extends keyof Events> = Array<{
|
|
226
|
+
listener: EventListener<Events, EventType>;
|
|
328
227
|
once?: boolean;
|
|
329
228
|
}>;
|
|
330
|
-
type EventParameters<Events extends CustomEvents<any>, Event extends keyof Events> = Parameters<
|
|
331
|
-
ListenerForEvent<Events, Event>
|
|
332
|
-
>;
|
|
333
229
|
|
|
334
|
-
export
|
|
230
|
+
export type EventParameters<Events, EventType extends keyof Events> = {
|
|
231
|
+
[Event in EventType]: EventListener<Events, EventType> extends (...args: infer P) => any ? P : never;
|
|
232
|
+
}[EventType];
|
|
233
|
+
|
|
234
|
+
export interface BaseEvents {
|
|
335
235
|
connect: () => void;
|
|
336
|
-
run: (run: Run) => void;
|
|
337
236
|
error: (error: OpenAIError) => void;
|
|
338
237
|
abort: (error: APIUserAbortError) => void;
|
|
339
238
|
end: () => void;
|
|
@@ -12,7 +12,7 @@ export type RunnableFunctionWithParse<Args extends object> = {
|
|
|
12
12
|
*/
|
|
13
13
|
function: (
|
|
14
14
|
args: Args,
|
|
15
|
-
runner: ChatCompletionRunner | ChatCompletionStreamingRunner
|
|
15
|
+
runner: ChatCompletionRunner<unknown> | ChatCompletionStreamingRunner<unknown>,
|
|
16
16
|
) => PromiseOrValue<unknown>;
|
|
17
17
|
/**
|
|
18
18
|
* @param input the raw args from the OpenAI function call.
|
|
@@ -31,6 +31,7 @@ export type RunnableFunctionWithParse<Args extends object> = {
|
|
|
31
31
|
* The name of the function to be called. Will default to function.name if omitted.
|
|
32
32
|
*/
|
|
33
33
|
name?: string | undefined;
|
|
34
|
+
strict?: boolean | undefined;
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
export type RunnableFunctionWithoutParse = {
|
|
@@ -40,7 +41,7 @@ export type RunnableFunctionWithoutParse = {
|
|
|
40
41
|
*/
|
|
41
42
|
function: (
|
|
42
43
|
args: string,
|
|
43
|
-
runner: ChatCompletionRunner | ChatCompletionStreamingRunner
|
|
44
|
+
runner: ChatCompletionRunner<unknown> | ChatCompletionStreamingRunner<unknown>,
|
|
44
45
|
) => PromiseOrValue<unknown>;
|
|
45
46
|
/**
|
|
46
47
|
* The parameters the function accepts, describes as a JSON Schema object.
|
|
@@ -54,6 +55,7 @@ export type RunnableFunctionWithoutParse = {
|
|
|
54
55
|
* The name of the function to be called. Will default to function.name if omitted.
|
|
55
56
|
*/
|
|
56
57
|
name?: string | undefined;
|
|
58
|
+
strict?: boolean | undefined;
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
export type RunnableFunction<Args extends object | string> =
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ChatCompletion,
|
|
3
|
+
ChatCompletionCreateParams,
|
|
4
|
+
ChatCompletionMessageToolCall,
|
|
5
|
+
ChatCompletionTool,
|
|
6
|
+
} from '../resources/chat/completions';
|
|
7
|
+
import {
|
|
8
|
+
ChatCompletionStreamingToolRunnerParams,
|
|
9
|
+
ChatCompletionStreamParams,
|
|
10
|
+
ChatCompletionToolRunnerParams,
|
|
11
|
+
ParsedChatCompletion,
|
|
12
|
+
ParsedChoice,
|
|
13
|
+
ParsedFunctionToolCall,
|
|
14
|
+
} from '../resources/beta/chat/completions';
|
|
15
|
+
import { ResponseFormatJSONSchema } from '../resources/shared';
|
|
16
|
+
import { ContentFilterFinishReasonError, LengthFinishReasonError, OpenAIError } from "../error";
|
|
17
|
+
|
|
18
|
+
type AnyChatCompletionCreateParams =
|
|
19
|
+
| ChatCompletionCreateParams
|
|
20
|
+
| ChatCompletionToolRunnerParams<any>
|
|
21
|
+
| ChatCompletionStreamingToolRunnerParams<any>
|
|
22
|
+
| ChatCompletionStreamParams;
|
|
23
|
+
|
|
24
|
+
export type ExtractParsedContentFromParams<Params extends AnyChatCompletionCreateParams> =
|
|
25
|
+
Params['response_format'] extends AutoParseableResponseFormat<infer P> ? P : null;
|
|
26
|
+
|
|
27
|
+
export type AutoParseableResponseFormat<ParsedT> = ResponseFormatJSONSchema & {
|
|
28
|
+
__output: ParsedT; // type-level only
|
|
29
|
+
|
|
30
|
+
$brand: 'auto-parseable-response-format';
|
|
31
|
+
$parseRaw(content: string): ParsedT;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function makeParseableResponseFormat<ParsedT>(
|
|
35
|
+
response_format: ResponseFormatJSONSchema,
|
|
36
|
+
parser: (content: string) => ParsedT,
|
|
37
|
+
): AutoParseableResponseFormat<ParsedT> {
|
|
38
|
+
const obj = { ...response_format };
|
|
39
|
+
|
|
40
|
+
Object.defineProperties(obj, {
|
|
41
|
+
$brand: {
|
|
42
|
+
value: 'auto-parseable-response-format',
|
|
43
|
+
enumerable: false,
|
|
44
|
+
},
|
|
45
|
+
$parseRaw: {
|
|
46
|
+
value: parser,
|
|
47
|
+
enumerable: false,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return obj as AutoParseableResponseFormat<ParsedT>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isAutoParsableResponseFormat<ParsedT>(
|
|
55
|
+
response_format: any,
|
|
56
|
+
): response_format is AutoParseableResponseFormat<ParsedT> {
|
|
57
|
+
return response_format?.['$brand'] === 'auto-parseable-response-format';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
type ToolOptions = {
|
|
61
|
+
name: string;
|
|
62
|
+
arguments: any;
|
|
63
|
+
function?: ((args: any) => any) | undefined;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type AutoParseableTool<
|
|
67
|
+
OptionsT extends ToolOptions,
|
|
68
|
+
HasFunction = OptionsT['function'] extends Function ? true : false,
|
|
69
|
+
> = ChatCompletionTool & {
|
|
70
|
+
__arguments: OptionsT['arguments']; // type-level only
|
|
71
|
+
__name: OptionsT['name']; // type-level only
|
|
72
|
+
__hasFunction: HasFunction; // type-level only
|
|
73
|
+
|
|
74
|
+
$brand: 'auto-parseable-tool';
|
|
75
|
+
$callback: ((args: OptionsT['arguments']) => any) | undefined;
|
|
76
|
+
$parseRaw(args: string): OptionsT['arguments'];
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export function makeParseableTool<OptionsT extends ToolOptions>(
|
|
80
|
+
tool: ChatCompletionTool,
|
|
81
|
+
{
|
|
82
|
+
parser,
|
|
83
|
+
callback,
|
|
84
|
+
}: {
|
|
85
|
+
parser: (content: string) => OptionsT['arguments'];
|
|
86
|
+
callback: ((args: any) => any) | undefined;
|
|
87
|
+
},
|
|
88
|
+
): AutoParseableTool<OptionsT['arguments']> {
|
|
89
|
+
const obj = { ...tool };
|
|
90
|
+
|
|
91
|
+
Object.defineProperties(obj, {
|
|
92
|
+
$brand: {
|
|
93
|
+
value: 'auto-parseable-tool',
|
|
94
|
+
enumerable: false,
|
|
95
|
+
},
|
|
96
|
+
$parseRaw: {
|
|
97
|
+
value: parser,
|
|
98
|
+
enumerable: false,
|
|
99
|
+
},
|
|
100
|
+
$callback: {
|
|
101
|
+
value: callback,
|
|
102
|
+
enumerable: false,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return obj as AutoParseableTool<OptionsT['arguments']>;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function isAutoParsableTool(tool: any): tool is AutoParseableTool<any> {
|
|
110
|
+
return tool?.['$brand'] === 'auto-parseable-tool';
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function maybeParseChatCompletion<
|
|
114
|
+
Params extends ChatCompletionCreateParams | null,
|
|
115
|
+
ParsedT = Params extends null ? null : ExtractParsedContentFromParams<NonNullable<Params>>,
|
|
116
|
+
>(completion: ChatCompletion, params: Params): ParsedChatCompletion<ParsedT> {
|
|
117
|
+
if (!params || !hasAutoParseableInput(params)) {
|
|
118
|
+
return {
|
|
119
|
+
...completion,
|
|
120
|
+
choices: completion.choices.map((choice) => ({
|
|
121
|
+
...choice,
|
|
122
|
+
message: { ...choice.message, parsed: null, tool_calls: choice.message.tool_calls ?? [] },
|
|
123
|
+
})),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return parseChatCompletion(completion, params);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function parseChatCompletion<
|
|
131
|
+
Params extends ChatCompletionCreateParams,
|
|
132
|
+
ParsedT = ExtractParsedContentFromParams<Params>,
|
|
133
|
+
>(completion: ChatCompletion, params: Params): ParsedChatCompletion<ParsedT> {
|
|
134
|
+
const choices: Array<ParsedChoice<ParsedT>> = completion.choices.map((choice): ParsedChoice<ParsedT> => {
|
|
135
|
+
if (choice.finish_reason === 'length') {
|
|
136
|
+
throw new LengthFinishReasonError();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (choice.finish_reason === 'content_filter') {
|
|
140
|
+
throw new ContentFilterFinishReasonError();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return {
|
|
144
|
+
...choice,
|
|
145
|
+
message: {
|
|
146
|
+
...choice.message,
|
|
147
|
+
tool_calls: choice.message.tool_calls?.map((toolCall) => parseToolCall(params, toolCall)) ?? [],
|
|
148
|
+
parsed:
|
|
149
|
+
choice.message.content && !choice.message.refusal ?
|
|
150
|
+
parseResponseFormat(params, choice.message.content)
|
|
151
|
+
: null,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return { ...completion, choices };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function parseResponseFormat<
|
|
160
|
+
Params extends ChatCompletionCreateParams,
|
|
161
|
+
ParsedT = ExtractParsedContentFromParams<Params>,
|
|
162
|
+
>(params: Params, content: string): ParsedT | null {
|
|
163
|
+
if (params.response_format?.type !== 'json_schema') {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (params.response_format?.type === 'json_schema') {
|
|
168
|
+
if ('$parseRaw' in params.response_format) {
|
|
169
|
+
const response_format = params.response_format as AutoParseableResponseFormat<ParsedT>;
|
|
170
|
+
|
|
171
|
+
return response_format.$parseRaw(content);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return JSON.parse(content);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function parseToolCall<Params extends ChatCompletionCreateParams>(
|
|
181
|
+
params: Params,
|
|
182
|
+
toolCall: ChatCompletionMessageToolCall,
|
|
183
|
+
): ParsedFunctionToolCall {
|
|
184
|
+
const inputTool = params.tools?.find((inputTool) => inputTool.function?.name === toolCall.function.name);
|
|
185
|
+
return {
|
|
186
|
+
...toolCall,
|
|
187
|
+
function: {
|
|
188
|
+
...toolCall.function,
|
|
189
|
+
parsed_arguments:
|
|
190
|
+
isAutoParsableTool(inputTool) ? inputTool.$parseRaw(toolCall.function.arguments)
|
|
191
|
+
: inputTool?.function.strict ? JSON.parse(toolCall.function.arguments)
|
|
192
|
+
: null,
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function shouldParseToolCall(
|
|
198
|
+
params: ChatCompletionCreateParams | null | undefined,
|
|
199
|
+
toolCall: ChatCompletionMessageToolCall,
|
|
200
|
+
): boolean {
|
|
201
|
+
if (!params) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const inputTool = params.tools?.find((inputTool) => inputTool.function?.name === toolCall.function.name);
|
|
206
|
+
return isAutoParsableTool(inputTool) || inputTool?.function.strict || false;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function hasAutoParseableInput(params: AnyChatCompletionCreateParams): boolean {
|
|
210
|
+
if (isAutoParsableResponseFormat(params.response_format)) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return (
|
|
215
|
+
params.tools?.some(
|
|
216
|
+
(t) => isAutoParsableTool(t) || (t.type === 'function' && t.function.strict === true),
|
|
217
|
+
) ?? false
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function validateInputTools(tools: ChatCompletionTool[] | undefined) {
|
|
222
|
+
for (const tool of tools ?? []) {
|
|
223
|
+
if (tool.type !== 'function') {
|
|
224
|
+
throw new OpenAIError(
|
|
225
|
+
`Currently only \`function\` tool types support auto-parsing; Received \`${tool.type}\``,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (tool.function.strict !== true) {
|
|
230
|
+
throw new OpenAIError(
|
|
231
|
+
`The \`${tool.function.name}\` tool is not marked with \`strict: true\`. Only strict function tools can be auto-parsed`,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
3
|
import { APIResource } from '../../resource';
|
|
4
|
+
import * as AudioAPI from './audio';
|
|
4
5
|
import * as SpeechAPI from './speech';
|
|
5
6
|
import * as TranscriptionsAPI from './transcriptions';
|
|
6
7
|
import * as TranslationsAPI from './translations';
|
|
@@ -11,7 +12,10 @@ export class Audio extends APIResource {
|
|
|
11
12
|
speech: SpeechAPI.Speech = new SpeechAPI.Speech(this._client);
|
|
12
13
|
}
|
|
13
14
|
|
|
15
|
+
export type AudioModel = 'whisper-1';
|
|
16
|
+
|
|
14
17
|
export namespace Audio {
|
|
18
|
+
export import AudioModel = AudioAPI.AudioModel;
|
|
15
19
|
export import Transcriptions = TranscriptionsAPI.Transcriptions;
|
|
16
20
|
export import Transcription = TranscriptionsAPI.Transcription;
|
|
17
21
|
export import TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
|
|
@@ -19,5 +23,6 @@ export namespace Audio {
|
|
|
19
23
|
export import Translation = TranslationsAPI.Translation;
|
|
20
24
|
export import TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
|
|
21
25
|
export import Speech = SpeechAPI.Speech;
|
|
26
|
+
export import SpeechModel = SpeechAPI.SpeechModel;
|
|
22
27
|
export import SpeechCreateParams = SpeechAPI.SpeechCreateParams;
|
|
23
28
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
2
|
|
|
3
|
-
export { Audio } from './audio';
|
|
4
|
-
export { SpeechCreateParams, Speech } from './speech';
|
|
3
|
+
export { AudioModel, Audio } from './audio';
|
|
4
|
+
export { SpeechModel, SpeechCreateParams, Speech } from './speech';
|
|
5
5
|
export { Transcription, TranscriptionCreateParams, Transcriptions } from './transcriptions';
|
|
6
6
|
export { Translation, TranslationCreateParams, Translations } from './translations';
|
|
@@ -14,6 +14,8 @@ export class Speech extends APIResource {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
export type SpeechModel = 'tts-1' | 'tts-1-hd';
|
|
18
|
+
|
|
17
19
|
export interface SpeechCreateParams {
|
|
18
20
|
/**
|
|
19
21
|
* The text to generate audio for. The maximum length is 4096 characters.
|
|
@@ -24,7 +26,7 @@ export interface SpeechCreateParams {
|
|
|
24
26
|
* One of the available [TTS models](https://platform.openai.com/docs/models/tts):
|
|
25
27
|
* `tts-1` or `tts-1-hd`
|
|
26
28
|
*/
|
|
27
|
-
model: (string & {}) |
|
|
29
|
+
model: (string & {}) | SpeechModel;
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* The voice to use when generating the audio. Supported voices are `alloy`,
|
|
@@ -48,5 +50,6 @@ export interface SpeechCreateParams {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
export namespace Speech {
|
|
53
|
+
export import SpeechModel = SpeechAPI.SpeechModel;
|
|
51
54
|
export import SpeechCreateParams = SpeechAPI.SpeechCreateParams;
|
|
52
55
|
}
|