modelfusion 0.104.0 → 0.106.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.
Files changed (292) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/README.md +8 -10
  3. package/core/DefaultRun.cjs +0 -4
  4. package/core/DefaultRun.d.ts +0 -2
  5. package/core/DefaultRun.js +0 -4
  6. package/core/ExtensionFunctionEvent.d.ts +11 -0
  7. package/core/FunctionEvent.d.ts +2 -2
  8. package/extension/index.cjs +22 -3
  9. package/extension/index.d.ts +5 -1
  10. package/extension/index.js +4 -1
  11. package/index.cjs +0 -3
  12. package/index.d.ts +0 -3
  13. package/index.js +0 -3
  14. package/model-function/Delta.d.ts +1 -2
  15. package/model-function/executeStreamCall.cjs +6 -4
  16. package/model-function/executeStreamCall.d.ts +2 -2
  17. package/model-function/executeStreamCall.js +6 -4
  18. package/model-function/generate-speech/streamSpeech.cjs +1 -2
  19. package/model-function/generate-speech/streamSpeech.js +1 -2
  20. package/model-function/generate-structure/StructureFromTextStreamingModel.cjs +25 -29
  21. package/model-function/generate-structure/StructureFromTextStreamingModel.d.ts +3 -1
  22. package/model-function/generate-structure/StructureFromTextStreamingModel.js +25 -29
  23. package/model-function/generate-structure/StructureGenerationModel.d.ts +2 -0
  24. package/model-function/generate-structure/jsonStructurePrompt.cjs +42 -6
  25. package/model-function/generate-structure/jsonStructurePrompt.d.ts +12 -1
  26. package/model-function/generate-structure/jsonStructurePrompt.js +42 -5
  27. package/model-function/generate-structure/streamStructure.cjs +7 -8
  28. package/model-function/generate-structure/streamStructure.d.ts +1 -1
  29. package/model-function/generate-structure/streamStructure.js +7 -8
  30. package/model-function/generate-text/PromptTemplateFullTextModel.cjs +35 -0
  31. package/model-function/generate-text/PromptTemplateFullTextModel.d.ts +41 -0
  32. package/model-function/generate-text/PromptTemplateFullTextModel.js +31 -0
  33. package/model-function/generate-text/PromptTemplateTextGenerationModel.d.ts +2 -1
  34. package/model-function/generate-text/PromptTemplateTextGenerationModel.js +1 -1
  35. package/model-function/generate-text/PromptTemplateTextStreamingModel.cjs +3 -0
  36. package/model-function/generate-text/PromptTemplateTextStreamingModel.d.ts +2 -1
  37. package/model-function/generate-text/PromptTemplateTextStreamingModel.js +3 -0
  38. package/model-function/generate-text/TextGenerationModel.d.ts +2 -1
  39. package/model-function/generate-text/index.cjs +1 -0
  40. package/model-function/generate-text/index.d.ts +1 -0
  41. package/model-function/generate-text/index.js +1 -0
  42. package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.cjs +2 -2
  43. package/model-function/generate-text/prompt-template/AlpacaPromptTemplate.js +1 -1
  44. package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.cjs +8 -5
  45. package/model-function/generate-text/prompt-template/ChatMLPromptTemplate.js +7 -4
  46. package/model-function/generate-text/prompt-template/ChatPrompt.cjs +42 -0
  47. package/model-function/generate-text/prompt-template/ChatPrompt.d.ts +27 -5
  48. package/model-function/generate-text/prompt-template/ChatPrompt.js +41 -1
  49. package/model-function/generate-text/prompt-template/{Content.cjs → ContentPart.cjs} +1 -1
  50. package/model-function/generate-text/prompt-template/ContentPart.d.ts +30 -0
  51. package/model-function/generate-text/prompt-template/{Content.js → ContentPart.js} +1 -1
  52. package/model-function/generate-text/prompt-template/InstructionPrompt.d.ts +3 -2
  53. package/model-function/generate-text/prompt-template/Llama2PromptTemplate.cjs +8 -5
  54. package/model-function/generate-text/prompt-template/Llama2PromptTemplate.d.ts +1 -1
  55. package/model-function/generate-text/prompt-template/Llama2PromptTemplate.js +6 -3
  56. package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.cjs +8 -4
  57. package/model-function/generate-text/prompt-template/NeuralChatPromptTemplate.js +6 -2
  58. package/model-function/generate-text/prompt-template/TextPromptTemplate.cjs +8 -4
  59. package/model-function/generate-text/prompt-template/TextPromptTemplate.js +6 -2
  60. package/model-function/generate-text/prompt-template/VicunaPromptTemplate.cjs +7 -3
  61. package/model-function/generate-text/prompt-template/VicunaPromptTemplate.js +6 -2
  62. package/model-function/generate-text/prompt-template/index.cjs +1 -1
  63. package/model-function/generate-text/prompt-template/index.d.ts +1 -1
  64. package/model-function/generate-text/prompt-template/index.js +1 -1
  65. package/model-function/generate-text/streamText.cjs +27 -28
  66. package/model-function/generate-text/streamText.d.ts +1 -0
  67. package/model-function/generate-text/streamText.js +27 -28
  68. package/model-function/index.cjs +0 -1
  69. package/model-function/index.d.ts +0 -1
  70. package/model-function/index.js +0 -1
  71. package/model-provider/anthropic/AnthropicPromptTemplate.cjs +7 -3
  72. package/model-provider/anthropic/AnthropicPromptTemplate.js +5 -1
  73. package/model-provider/anthropic/AnthropicTextGenerationModel.cjs +8 -14
  74. package/model-provider/anthropic/AnthropicTextGenerationModel.d.ts +11 -2
  75. package/model-provider/anthropic/AnthropicTextGenerationModel.js +8 -14
  76. package/model-provider/anthropic/AnthropicTextGenerationModel.test.cjs +44 -0
  77. package/model-provider/anthropic/AnthropicTextGenerationModel.test.js +42 -0
  78. package/model-provider/cohere/CohereTextEmbeddingModel.d.ts +3 -3
  79. package/model-provider/cohere/CohereTextGenerationModel.cjs +6 -44
  80. package/model-provider/cohere/CohereTextGenerationModel.d.ts +49 -15
  81. package/model-provider/cohere/CohereTextGenerationModel.js +7 -45
  82. package/model-provider/cohere/CohereTextGenerationModel.test.cjs +33 -0
  83. package/model-provider/cohere/CohereTextGenerationModel.test.js +31 -0
  84. package/model-provider/elevenlabs/ElevenLabsSpeechModel.cjs +1 -2
  85. package/model-provider/elevenlabs/ElevenLabsSpeechModel.js +1 -2
  86. package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.cjs +6 -1
  87. package/model-provider/llamacpp/LlamaCppBakLLaVA1PromptTemplate.js +6 -1
  88. package/model-provider/llamacpp/LlamaCppTextGenerationModel.cjs +7 -14
  89. package/model-provider/llamacpp/LlamaCppTextGenerationModel.d.ts +171 -20
  90. package/model-provider/llamacpp/LlamaCppTextGenerationModel.js +8 -15
  91. package/model-provider/llamacpp/LlamaCppTextGenerationModel.test.cjs +37 -0
  92. package/model-provider/llamacpp/LlamaCppTextGenerationModel.test.js +35 -0
  93. package/model-provider/mistral/MistralChatModel.cjs +30 -104
  94. package/model-provider/mistral/MistralChatModel.d.ts +47 -14
  95. package/model-provider/mistral/MistralChatModel.js +30 -104
  96. package/model-provider/mistral/MistralChatModel.test.cjs +51 -0
  97. package/model-provider/mistral/MistralChatModel.test.js +49 -0
  98. package/model-provider/mistral/MistralPromptTemplate.cjs +11 -4
  99. package/model-provider/mistral/MistralPromptTemplate.js +9 -2
  100. package/model-provider/mistral/MistralTextEmbeddingModel.d.ts +13 -13
  101. package/model-provider/ollama/OllamaChatModel.cjs +7 -43
  102. package/model-provider/ollama/OllamaChatModel.d.ts +67 -14
  103. package/model-provider/ollama/OllamaChatModel.js +8 -44
  104. package/model-provider/ollama/OllamaChatModel.test.cjs +27 -0
  105. package/model-provider/ollama/OllamaChatModel.test.js +25 -0
  106. package/model-provider/ollama/OllamaChatPromptTemplate.cjs +34 -4
  107. package/model-provider/ollama/OllamaChatPromptTemplate.js +34 -4
  108. package/model-provider/ollama/OllamaCompletionModel.cjs +22 -43
  109. package/model-provider/ollama/OllamaCompletionModel.d.ts +67 -10
  110. package/model-provider/ollama/OllamaCompletionModel.js +24 -45
  111. package/model-provider/ollama/OllamaCompletionModel.test.cjs +95 -13
  112. package/model-provider/ollama/OllamaCompletionModel.test.js +72 -13
  113. package/model-provider/openai/{chat/AbstractOpenAIChatModel.cjs → AbstractOpenAIChatModel.cjs} +71 -15
  114. package/model-provider/openai/{chat/AbstractOpenAIChatModel.d.ts → AbstractOpenAIChatModel.d.ts} +273 -19
  115. package/model-provider/openai/{chat/AbstractOpenAIChatModel.js → AbstractOpenAIChatModel.js} +71 -15
  116. package/model-provider/openai/{chat/OpenAIChatFunctionCallStructureGenerationModel.cjs → OpenAIChatFunctionCallStructureGenerationModel.cjs} +18 -2
  117. package/model-provider/openai/{chat/OpenAIChatFunctionCallStructureGenerationModel.d.ts → OpenAIChatFunctionCallStructureGenerationModel.d.ts} +41 -11
  118. package/model-provider/openai/{chat/OpenAIChatFunctionCallStructureGenerationModel.js → OpenAIChatFunctionCallStructureGenerationModel.js} +18 -2
  119. package/model-provider/openai/{chat/OpenAIChatMessage.d.ts → OpenAIChatMessage.d.ts} +3 -3
  120. package/model-provider/openai/{chat/OpenAIChatModel.cjs → OpenAIChatModel.cjs} +5 -5
  121. package/model-provider/openai/{chat/OpenAIChatModel.d.ts → OpenAIChatModel.d.ts} +12 -12
  122. package/model-provider/openai/{chat/OpenAIChatModel.js → OpenAIChatModel.js} +5 -5
  123. package/model-provider/openai/OpenAIChatModel.test.cjs +94 -0
  124. package/model-provider/openai/OpenAIChatModel.test.js +92 -0
  125. package/model-provider/openai/OpenAIChatPromptTemplate.cjs +114 -0
  126. package/model-provider/openai/{chat/OpenAIChatPromptTemplate.d.ts → OpenAIChatPromptTemplate.d.ts} +3 -3
  127. package/model-provider/openai/OpenAIChatPromptTemplate.js +107 -0
  128. package/model-provider/openai/OpenAICompletionModel.cjs +32 -84
  129. package/model-provider/openai/OpenAICompletionModel.d.ts +27 -10
  130. package/model-provider/openai/OpenAICompletionModel.js +33 -85
  131. package/model-provider/openai/OpenAICompletionModel.test.cjs +53 -0
  132. package/model-provider/openai/OpenAICompletionModel.test.js +51 -0
  133. package/model-provider/openai/OpenAIFacade.cjs +2 -2
  134. package/model-provider/openai/OpenAIFacade.d.ts +3 -3
  135. package/model-provider/openai/OpenAIFacade.js +2 -2
  136. package/model-provider/openai/OpenAITextEmbeddingModel.d.ts +12 -12
  137. package/model-provider/openai/OpenAITranscriptionModel.d.ts +17 -17
  138. package/model-provider/openai/TikTokenTokenizer.d.ts +1 -1
  139. package/model-provider/openai/{chat/countOpenAIChatMessageTokens.cjs → countOpenAIChatMessageTokens.cjs} +2 -2
  140. package/model-provider/openai/{chat/countOpenAIChatMessageTokens.js → countOpenAIChatMessageTokens.js} +2 -2
  141. package/model-provider/openai/index.cjs +6 -7
  142. package/model-provider/openai/index.d.ts +5 -7
  143. package/model-provider/openai/index.js +5 -6
  144. package/model-provider/openai-compatible/OpenAICompatibleChatModel.cjs +4 -4
  145. package/model-provider/openai-compatible/OpenAICompatibleChatModel.d.ts +6 -6
  146. package/model-provider/openai-compatible/OpenAICompatibleChatModel.js +4 -4
  147. package/model-provider/stability/StabilityImageGenerationModel.d.ts +5 -5
  148. package/package.json +13 -24
  149. package/test/JsonTestServer.cjs +33 -0
  150. package/test/JsonTestServer.d.ts +7 -0
  151. package/test/JsonTestServer.js +29 -0
  152. package/test/StreamingTestServer.cjs +55 -0
  153. package/test/StreamingTestServer.d.ts +7 -0
  154. package/test/StreamingTestServer.js +51 -0
  155. package/test/arrayFromAsync.cjs +13 -0
  156. package/test/arrayFromAsync.d.ts +1 -0
  157. package/test/arrayFromAsync.js +9 -0
  158. package/tool/generate-tool-call/TextGenerationToolCallModel.cjs +1 -1
  159. package/tool/generate-tool-call/TextGenerationToolCallModel.d.ts +1 -1
  160. package/tool/generate-tool-call/TextGenerationToolCallModel.js +1 -1
  161. package/tool/generate-tool-calls-or-text/TextGenerationToolCallsOrGenerateTextModel.d.ts +1 -11
  162. package/tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.d.ts +12 -0
  163. package/tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.js +1 -0
  164. package/tool/generate-tool-calls-or-text/index.cjs +1 -0
  165. package/tool/generate-tool-calls-or-text/index.d.ts +1 -0
  166. package/tool/generate-tool-calls-or-text/index.js +1 -0
  167. package/util/index.cjs +0 -1
  168. package/util/index.d.ts +0 -1
  169. package/util/index.js +0 -1
  170. package/util/streaming/createEventSourceResponseHandler.cjs +9 -0
  171. package/util/streaming/createEventSourceResponseHandler.d.ts +4 -0
  172. package/util/streaming/createEventSourceResponseHandler.js +5 -0
  173. package/util/streaming/createJsonStreamResponseHandler.cjs +9 -0
  174. package/util/streaming/createJsonStreamResponseHandler.d.ts +4 -0
  175. package/util/streaming/createJsonStreamResponseHandler.js +5 -0
  176. package/util/streaming/parseEventSourceStreamAsAsyncIterable.cjs +52 -0
  177. package/util/streaming/parseEventSourceStreamAsAsyncIterable.d.ts +6 -0
  178. package/util/streaming/parseEventSourceStreamAsAsyncIterable.js +48 -0
  179. package/util/streaming/parseJsonStreamAsAsyncIterable.cjs +21 -0
  180. package/util/streaming/parseJsonStreamAsAsyncIterable.d.ts +6 -0
  181. package/util/streaming/parseJsonStreamAsAsyncIterable.js +17 -0
  182. package/browser/MediaSourceAppender.cjs +0 -54
  183. package/browser/MediaSourceAppender.d.ts +0 -11
  184. package/browser/MediaSourceAppender.js +0 -50
  185. package/browser/convertAudioChunksToBase64.cjs +0 -8
  186. package/browser/convertAudioChunksToBase64.d.ts +0 -4
  187. package/browser/convertAudioChunksToBase64.js +0 -4
  188. package/browser/convertBlobToBase64.cjs +0 -23
  189. package/browser/convertBlobToBase64.d.ts +0 -1
  190. package/browser/convertBlobToBase64.js +0 -19
  191. package/browser/index.cjs +0 -22
  192. package/browser/index.d.ts +0 -6
  193. package/browser/index.js +0 -6
  194. package/browser/invokeFlow.cjs +0 -23
  195. package/browser/invokeFlow.d.ts +0 -8
  196. package/browser/invokeFlow.js +0 -19
  197. package/browser/readEventSource.cjs +0 -29
  198. package/browser/readEventSource.d.ts +0 -9
  199. package/browser/readEventSource.js +0 -25
  200. package/browser/readEventSourceStream.cjs +0 -35
  201. package/browser/readEventSourceStream.d.ts +0 -7
  202. package/browser/readEventSourceStream.js +0 -31
  203. package/composed-function/index.cjs +0 -19
  204. package/composed-function/index.d.ts +0 -3
  205. package/composed-function/index.js +0 -3
  206. package/composed-function/summarize/SummarizationFunction.d.ts +0 -4
  207. package/composed-function/summarize/summarizeRecursively.cjs +0 -19
  208. package/composed-function/summarize/summarizeRecursively.d.ts +0 -11
  209. package/composed-function/summarize/summarizeRecursively.js +0 -15
  210. package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.cjs +0 -25
  211. package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.d.ts +0 -24
  212. package/composed-function/summarize/summarizeRecursivelyWithTextGenerationAndTokenSplitting.js +0 -21
  213. package/cost/Cost.cjs +0 -38
  214. package/cost/Cost.d.ts +0 -16
  215. package/cost/Cost.js +0 -34
  216. package/cost/CostCalculator.d.ts +0 -8
  217. package/cost/calculateCost.cjs +0 -28
  218. package/cost/calculateCost.d.ts +0 -7
  219. package/cost/calculateCost.js +0 -24
  220. package/cost/index.cjs +0 -19
  221. package/cost/index.d.ts +0 -3
  222. package/cost/index.js +0 -3
  223. package/guard/GuardEvent.cjs +0 -2
  224. package/guard/GuardEvent.d.ts +0 -7
  225. package/guard/fixStructure.cjs +0 -75
  226. package/guard/fixStructure.d.ts +0 -64
  227. package/guard/fixStructure.js +0 -71
  228. package/guard/guard.cjs +0 -79
  229. package/guard/guard.d.ts +0 -29
  230. package/guard/guard.js +0 -75
  231. package/guard/index.cjs +0 -19
  232. package/guard/index.d.ts +0 -3
  233. package/guard/index.js +0 -3
  234. package/model-function/SuccessfulModelCall.cjs +0 -10
  235. package/model-function/SuccessfulModelCall.d.ts +0 -12
  236. package/model-function/SuccessfulModelCall.js +0 -6
  237. package/model-function/generate-text/prompt-template/Content.d.ts +0 -25
  238. package/model-provider/openai/OpenAICostCalculator.cjs +0 -89
  239. package/model-provider/openai/OpenAICostCalculator.d.ts +0 -6
  240. package/model-provider/openai/OpenAICostCalculator.js +0 -85
  241. package/model-provider/openai/chat/OpenAIChatModel.test.cjs +0 -61
  242. package/model-provider/openai/chat/OpenAIChatModel.test.js +0 -59
  243. package/model-provider/openai/chat/OpenAIChatPromptTemplate.cjs +0 -70
  244. package/model-provider/openai/chat/OpenAIChatPromptTemplate.js +0 -63
  245. package/model-provider/openai/chat/OpenAIChatStreamIterable.cjs +0 -156
  246. package/model-provider/openai/chat/OpenAIChatStreamIterable.d.ts +0 -19
  247. package/model-provider/openai/chat/OpenAIChatStreamIterable.js +0 -152
  248. package/server/fastify/AssetStorage.cjs +0 -2
  249. package/server/fastify/AssetStorage.d.ts +0 -17
  250. package/server/fastify/DefaultFlow.cjs +0 -22
  251. package/server/fastify/DefaultFlow.d.ts +0 -16
  252. package/server/fastify/DefaultFlow.js +0 -18
  253. package/server/fastify/FileSystemAssetStorage.cjs +0 -60
  254. package/server/fastify/FileSystemAssetStorage.d.ts +0 -19
  255. package/server/fastify/FileSystemAssetStorage.js +0 -56
  256. package/server/fastify/FileSystemLogger.cjs +0 -49
  257. package/server/fastify/FileSystemLogger.d.ts +0 -18
  258. package/server/fastify/FileSystemLogger.js +0 -45
  259. package/server/fastify/Flow.cjs +0 -2
  260. package/server/fastify/Flow.d.ts +0 -9
  261. package/server/fastify/FlowRun.cjs +0 -71
  262. package/server/fastify/FlowRun.d.ts +0 -28
  263. package/server/fastify/FlowRun.js +0 -67
  264. package/server/fastify/FlowSchema.cjs +0 -2
  265. package/server/fastify/FlowSchema.d.ts +0 -5
  266. package/server/fastify/Logger.cjs +0 -2
  267. package/server/fastify/Logger.d.ts +0 -13
  268. package/server/fastify/PathProvider.cjs +0 -34
  269. package/server/fastify/PathProvider.d.ts +0 -12
  270. package/server/fastify/PathProvider.js +0 -30
  271. package/server/fastify/index.cjs +0 -24
  272. package/server/fastify/index.d.ts +0 -8
  273. package/server/fastify/index.js +0 -8
  274. package/server/fastify/modelFusionFlowPlugin.cjs +0 -103
  275. package/server/fastify/modelFusionFlowPlugin.d.ts +0 -12
  276. package/server/fastify/modelFusionFlowPlugin.js +0 -99
  277. package/util/getAudioFileExtension.cjs +0 -29
  278. package/util/getAudioFileExtension.d.ts +0 -1
  279. package/util/getAudioFileExtension.js +0 -25
  280. /package/{composed-function/summarize/SummarizationFunction.cjs → core/ExtensionFunctionEvent.cjs} +0 -0
  281. /package/{composed-function/summarize/SummarizationFunction.js → core/ExtensionFunctionEvent.js} +0 -0
  282. /package/{cost/CostCalculator.js → model-provider/anthropic/AnthropicTextGenerationModel.test.d.ts} +0 -0
  283. /package/{guard/GuardEvent.js → model-provider/cohere/CohereTextGenerationModel.test.d.ts} +0 -0
  284. /package/model-provider/{openai/chat/OpenAIChatModel.test.d.ts → llamacpp/LlamaCppTextGenerationModel.test.d.ts} +0 -0
  285. /package/{server/fastify/AssetStorage.js → model-provider/mistral/MistralChatModel.test.d.ts} +0 -0
  286. /package/{server/fastify/Flow.js → model-provider/ollama/OllamaChatModel.test.d.ts} +0 -0
  287. /package/model-provider/openai/{chat/OpenAIChatMessage.cjs → OpenAIChatMessage.cjs} +0 -0
  288. /package/model-provider/openai/{chat/OpenAIChatMessage.js → OpenAIChatMessage.js} +0 -0
  289. /package/{server/fastify/FlowSchema.js → model-provider/openai/OpenAIChatModel.test.d.ts} +0 -0
  290. /package/{server/fastify/Logger.js → model-provider/openai/OpenAICompletionModel.test.d.ts} +0 -0
  291. /package/model-provider/openai/{chat/countOpenAIChatMessageTokens.d.ts → countOpenAIChatMessageTokens.d.ts} +0 -0
  292. /package/{cost/CostCalculator.cjs → tool/generate-tool-calls-or-text/ToolCallsOrGenerateTextPromptTemplate.cjs} +0 -0
@@ -5,14 +5,12 @@ const zod_1 = require("zod");
5
5
  const callWithRetryAndThrottle_js_1 = require("../../core/api/callWithRetryAndThrottle.cjs");
6
6
  const postToApi_js_1 = require("../../core/api/postToApi.cjs");
7
7
  const ZodSchema_js_1 = require("../../core/schema/ZodSchema.cjs");
8
- const parseJSON_js_1 = require("../../core/schema/parseJSON.cjs");
9
8
  const AbstractModel_js_1 = require("../../model-function/AbstractModel.cjs");
10
9
  const PromptTemplateTextStreamingModel_js_1 = require("../../model-function/generate-text/PromptTemplateTextStreamingModel.cjs");
11
10
  const TextGenerationModel_js_1 = require("../../model-function/generate-text/TextGenerationModel.cjs");
12
11
  const TextPromptTemplate_js_1 = require("../../model-function/generate-text/prompt-template/TextPromptTemplate.cjs");
13
12
  const countTokens_js_1 = require("../../model-function/tokenize-text/countTokens.cjs");
14
- const AsyncQueue_js_1 = require("../../util/AsyncQueue.cjs");
15
- const parseEventSourceStream_js_1 = require("../../util/streaming/parseEventSourceStream.cjs");
13
+ const createEventSourceResponseHandler_js_1 = require("../../util/streaming/createEventSourceResponseHandler.cjs");
16
14
  const OpenAIApiConfiguration_js_1 = require("./OpenAIApiConfiguration.cjs");
17
15
  const OpenAIError_js_1 = require("./OpenAIError.cjs");
18
16
  const TikTokenTokenizer_js_1 = require("./TikTokenTokenizer.cjs");
@@ -186,18 +184,17 @@ class OpenAICompletionModel extends AbstractModel_js_1.AbstractModel {
186
184
  ? options.run?.userId
187
185
  : undefined;
188
186
  const abortSignal = options.run?.abortSignal;
189
- let { stopSequences } = this.settings;
190
187
  const openaiResponseFormat = options.responseFormat;
188
+ // empty arrays are not allowed for stop:
189
+ const stopSequences = this.settings.stopSequences != null &&
190
+ Array.isArray(this.settings.stopSequences) &&
191
+ this.settings.stopSequences.length === 0
192
+ ? undefined
193
+ : this.settings.stopSequences;
191
194
  return (0, callWithRetryAndThrottle_js_1.callWithRetryAndThrottle)({
192
195
  retry: api.retry,
193
196
  throttle: api.throttle,
194
197
  call: async () => {
195
- // empty arrays are not allowed for stop:
196
- if (stopSequences != null &&
197
- Array.isArray(stopSequences) &&
198
- stopSequences.length === 0) {
199
- stopSequences = undefined;
200
- }
201
198
  return (0, postToApi_js_1.postJsonToApi)({
202
199
  url: api.assembleUrl("/completions"),
203
200
  headers: api.headers,
@@ -212,7 +209,7 @@ class OpenAICompletionModel extends AbstractModel_js_1.AbstractModel {
212
209
  n: this.settings.numberOfGenerations,
213
210
  logprobs: this.settings.logprobs,
214
211
  echo: this.settings.echo,
215
- stop: this.settings.stopSequences,
212
+ stop: stopSequences,
216
213
  seed: this.settings.seed,
217
214
  presence_penalty: this.settings.presencePenalty,
218
215
  frequency_penalty: this.settings.frequencyPenalty,
@@ -281,6 +278,14 @@ class OpenAICompletionModel extends AbstractModel_js_1.AbstractModel {
281
278
  responseFormat: exports.OpenAITextResponseFormat.deltaIterable,
282
279
  });
283
280
  }
281
+ extractTextDelta(delta) {
282
+ const chunk = delta;
283
+ const firstChoice = chunk.choices[0];
284
+ if (firstChoice.index > 0) {
285
+ return undefined;
286
+ }
287
+ return chunk.choices[0].text;
288
+ }
284
289
  /**
285
290
  * Returns this model with an instruction prompt template.
286
291
  */
@@ -330,6 +335,21 @@ const OpenAICompletionResponseSchema = zod_1.z.object({
330
335
  total_tokens: zod_1.z.number(),
331
336
  }),
332
337
  });
338
+ const openaiCompletionStreamChunkSchema = (0, ZodSchema_js_1.zodSchema)(zod_1.z.object({
339
+ choices: zod_1.z.array(zod_1.z.object({
340
+ text: zod_1.z.string(),
341
+ finish_reason: zod_1.z
342
+ .enum(["stop", "length", "content_filter"])
343
+ .optional()
344
+ .nullable(),
345
+ index: zod_1.z.number(),
346
+ })),
347
+ created: zod_1.z.number(),
348
+ id: zod_1.z.string(),
349
+ model: zod_1.z.string(),
350
+ system_fingerprint: zod_1.z.string().optional(),
351
+ object: zod_1.z.literal("text_completion"),
352
+ }));
333
353
  exports.OpenAITextResponseFormat = {
334
354
  /**
335
355
  * Returns the response as a JSON object.
@@ -344,78 +364,6 @@ exports.OpenAITextResponseFormat = {
344
364
  */
345
365
  deltaIterable: {
346
366
  stream: true,
347
- handler: async ({ response }) => createOpenAITextFullDeltaIterableQueue(response.body),
367
+ handler: (0, createEventSourceResponseHandler_js_1.createEventSourceResponseHandler)(openaiCompletionStreamChunkSchema),
348
368
  },
349
369
  };
350
- const textResponseStreamEventSchema = new ZodSchema_js_1.ZodSchema(zod_1.z.object({
351
- choices: zod_1.z.array(zod_1.z.object({
352
- text: zod_1.z.string(),
353
- finish_reason: zod_1.z
354
- .enum(["stop", "length", "content_filter"])
355
- .optional()
356
- .nullable(),
357
- index: zod_1.z.number(),
358
- })),
359
- created: zod_1.z.number(),
360
- id: zod_1.z.string(),
361
- model: zod_1.z.string(),
362
- system_fingerprint: zod_1.z.string().optional(),
363
- object: zod_1.z.literal("text_completion"),
364
- }));
365
- async function createOpenAITextFullDeltaIterableQueue(stream) {
366
- const queue = new AsyncQueue_js_1.AsyncQueue();
367
- const streamDelta = [];
368
- // process the stream asynchonously (no 'await' on purpose):
369
- (0, parseEventSourceStream_js_1.parseEventSourceStream)({ stream })
370
- .then(async (events) => {
371
- try {
372
- for await (const event of events) {
373
- const data = event.data;
374
- if (data === "[DONE]") {
375
- queue.close();
376
- return;
377
- }
378
- const eventData = (0, parseJSON_js_1.parseJSON)({
379
- text: data,
380
- schema: textResponseStreamEventSchema,
381
- });
382
- for (let i = 0; i < eventData.choices.length; i++) {
383
- const eventChoice = eventData.choices[i];
384
- const delta = eventChoice.text;
385
- if (streamDelta[i] == null) {
386
- streamDelta[i] = {
387
- content: "",
388
- isComplete: false,
389
- delta: "",
390
- };
391
- }
392
- const choice = streamDelta[i];
393
- choice.delta = delta;
394
- if (eventChoice.finish_reason != null) {
395
- choice.isComplete = true;
396
- }
397
- choice.content += delta;
398
- }
399
- // Since we're mutating the choices array in an async scenario,
400
- // we need to make a deep copy:
401
- const streamDeltaDeepCopy = JSON.parse(JSON.stringify(streamDelta));
402
- queue.push({
403
- type: "delta",
404
- fullDelta: streamDeltaDeepCopy,
405
- valueDelta: streamDeltaDeepCopy[0].delta,
406
- });
407
- }
408
- }
409
- catch (error) {
410
- queue.push({ type: "error", error });
411
- queue.close();
412
- return;
413
- }
414
- })
415
- .catch((error) => {
416
- queue.push({ type: "error", error });
417
- queue.close();
418
- return;
419
- });
420
- return queue;
421
- }
@@ -3,7 +3,6 @@ import { FunctionOptions } from "../../core/FunctionOptions.js";
3
3
  import { ApiConfiguration } from "../../core/api/ApiConfiguration.js";
4
4
  import { ResponseHandler } from "../../core/api/postToApi.js";
5
5
  import { AbstractModel } from "../../model-function/AbstractModel.js";
6
- import { Delta } from "../../model-function/Delta.js";
7
6
  import { PromptTemplateTextStreamingModel } from "../../model-function/generate-text/PromptTemplateTextStreamingModel.js";
8
7
  import { TextGenerationModelSettings, TextStreamingModel } from "../../model-function/generate-text/TextGenerationModel.js";
9
8
  import { TextGenerationPromptTemplate } from "../../model-function/generate-text/TextGenerationPromptTemplate.js";
@@ -174,7 +173,19 @@ export declare class OpenAICompletionModel extends AbstractModel<OpenAICompletio
174
173
  };
175
174
  }>;
176
175
  private translateFinishReason;
177
- doStreamText(prompt: string, options?: FunctionOptions): Promise<AsyncIterable<Delta<string>>>;
176
+ doStreamText(prompt: string, options?: FunctionOptions): Promise<AsyncIterable<import("../../index.js").Delta<{
177
+ object: "text_completion";
178
+ model: string;
179
+ id: string;
180
+ created: number;
181
+ choices: {
182
+ text: string;
183
+ index: number;
184
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
185
+ }[];
186
+ system_fingerprint?: string | undefined;
187
+ }>>>;
188
+ extractTextDelta(delta: unknown): string | undefined;
178
189
  /**
179
190
  * Returns this model with an instruction prompt template.
180
191
  */
@@ -269,7 +280,7 @@ export declare const OpenAITextResponseFormat: {
269
280
  * Returns the response as a JSON object.
270
281
  */
271
282
  json: {
272
- stream: false;
283
+ stream: boolean;
273
284
  handler: ResponseHandler<{
274
285
  object: "text_completion";
275
286
  usage: {
@@ -294,15 +305,21 @@ export declare const OpenAITextResponseFormat: {
294
305
  * of the response stream.
295
306
  */
296
307
  deltaIterable: {
297
- stream: true;
308
+ stream: boolean;
298
309
  handler: ({ response }: {
299
310
  response: Response;
300
- }) => Promise<AsyncIterable<Delta<string>>>;
311
+ }) => Promise<AsyncIterable<import("../../index.js").Delta<{
312
+ object: "text_completion";
313
+ model: string;
314
+ id: string;
315
+ created: number;
316
+ choices: {
317
+ text: string;
318
+ index: number;
319
+ finish_reason?: "length" | "stop" | "content_filter" | null | undefined;
320
+ }[];
321
+ system_fingerprint?: string | undefined;
322
+ }>>>;
301
323
  };
302
324
  };
303
- export type OpenAICompletionDelta = Array<{
304
- content: string;
305
- isComplete: boolean;
306
- delta: string;
307
- }>;
308
325
  export {};
@@ -1,15 +1,13 @@
1
1
  import { z } from "zod";
2
2
  import { callWithRetryAndThrottle } from "../../core/api/callWithRetryAndThrottle.js";
3
3
  import { createJsonResponseHandler, postJsonToApi, } from "../../core/api/postToApi.js";
4
- import { ZodSchema } from "../../core/schema/ZodSchema.js";
5
- import { parseJSON } from "../../core/schema/parseJSON.js";
4
+ import { zodSchema } from "../../core/schema/ZodSchema.js";
6
5
  import { AbstractModel } from "../../model-function/AbstractModel.js";
7
6
  import { PromptTemplateTextStreamingModel } from "../../model-function/generate-text/PromptTemplateTextStreamingModel.js";
8
7
  import { textGenerationModelProperties, } from "../../model-function/generate-text/TextGenerationModel.js";
9
8
  import { chat, instruction, } from "../../model-function/generate-text/prompt-template/TextPromptTemplate.js";
10
9
  import { countTokens } from "../../model-function/tokenize-text/countTokens.js";
11
- import { AsyncQueue } from "../../util/AsyncQueue.js";
12
- import { parseEventSourceStream } from "../../util/streaming/parseEventSourceStream.js";
10
+ import { createEventSourceResponseHandler } from "../../util/streaming/createEventSourceResponseHandler.js";
13
11
  import { OpenAIApiConfiguration } from "./OpenAIApiConfiguration.js";
14
12
  import { failedOpenAICallResponseHandler } from "./OpenAIError.js";
15
13
  import { TikTokenTokenizer } from "./TikTokenTokenizer.js";
@@ -180,18 +178,17 @@ export class OpenAICompletionModel extends AbstractModel {
180
178
  ? options.run?.userId
181
179
  : undefined;
182
180
  const abortSignal = options.run?.abortSignal;
183
- let { stopSequences } = this.settings;
184
181
  const openaiResponseFormat = options.responseFormat;
182
+ // empty arrays are not allowed for stop:
183
+ const stopSequences = this.settings.stopSequences != null &&
184
+ Array.isArray(this.settings.stopSequences) &&
185
+ this.settings.stopSequences.length === 0
186
+ ? undefined
187
+ : this.settings.stopSequences;
185
188
  return callWithRetryAndThrottle({
186
189
  retry: api.retry,
187
190
  throttle: api.throttle,
188
191
  call: async () => {
189
- // empty arrays are not allowed for stop:
190
- if (stopSequences != null &&
191
- Array.isArray(stopSequences) &&
192
- stopSequences.length === 0) {
193
- stopSequences = undefined;
194
- }
195
192
  return postJsonToApi({
196
193
  url: api.assembleUrl("/completions"),
197
194
  headers: api.headers,
@@ -206,7 +203,7 @@ export class OpenAICompletionModel extends AbstractModel {
206
203
  n: this.settings.numberOfGenerations,
207
204
  logprobs: this.settings.logprobs,
208
205
  echo: this.settings.echo,
209
- stop: this.settings.stopSequences,
206
+ stop: stopSequences,
210
207
  seed: this.settings.seed,
211
208
  presence_penalty: this.settings.presencePenalty,
212
209
  frequency_penalty: this.settings.frequencyPenalty,
@@ -275,6 +272,14 @@ export class OpenAICompletionModel extends AbstractModel {
275
272
  responseFormat: OpenAITextResponseFormat.deltaIterable,
276
273
  });
277
274
  }
275
+ extractTextDelta(delta) {
276
+ const chunk = delta;
277
+ const firstChoice = chunk.choices[0];
278
+ if (firstChoice.index > 0) {
279
+ return undefined;
280
+ }
281
+ return chunk.choices[0].text;
282
+ }
278
283
  /**
279
284
  * Returns this model with an instruction prompt template.
280
285
  */
@@ -323,6 +328,21 @@ const OpenAICompletionResponseSchema = z.object({
323
328
  total_tokens: z.number(),
324
329
  }),
325
330
  });
331
+ const openaiCompletionStreamChunkSchema = zodSchema(z.object({
332
+ choices: z.array(z.object({
333
+ text: z.string(),
334
+ finish_reason: z
335
+ .enum(["stop", "length", "content_filter"])
336
+ .optional()
337
+ .nullable(),
338
+ index: z.number(),
339
+ })),
340
+ created: z.number(),
341
+ id: z.string(),
342
+ model: z.string(),
343
+ system_fingerprint: z.string().optional(),
344
+ object: z.literal("text_completion"),
345
+ }));
326
346
  export const OpenAITextResponseFormat = {
327
347
  /**
328
348
  * Returns the response as a JSON object.
@@ -337,78 +357,6 @@ export const OpenAITextResponseFormat = {
337
357
  */
338
358
  deltaIterable: {
339
359
  stream: true,
340
- handler: async ({ response }) => createOpenAITextFullDeltaIterableQueue(response.body),
360
+ handler: createEventSourceResponseHandler(openaiCompletionStreamChunkSchema),
341
361
  },
342
362
  };
343
- const textResponseStreamEventSchema = new ZodSchema(z.object({
344
- choices: z.array(z.object({
345
- text: z.string(),
346
- finish_reason: z
347
- .enum(["stop", "length", "content_filter"])
348
- .optional()
349
- .nullable(),
350
- index: z.number(),
351
- })),
352
- created: z.number(),
353
- id: z.string(),
354
- model: z.string(),
355
- system_fingerprint: z.string().optional(),
356
- object: z.literal("text_completion"),
357
- }));
358
- async function createOpenAITextFullDeltaIterableQueue(stream) {
359
- const queue = new AsyncQueue();
360
- const streamDelta = [];
361
- // process the stream asynchonously (no 'await' on purpose):
362
- parseEventSourceStream({ stream })
363
- .then(async (events) => {
364
- try {
365
- for await (const event of events) {
366
- const data = event.data;
367
- if (data === "[DONE]") {
368
- queue.close();
369
- return;
370
- }
371
- const eventData = parseJSON({
372
- text: data,
373
- schema: textResponseStreamEventSchema,
374
- });
375
- for (let i = 0; i < eventData.choices.length; i++) {
376
- const eventChoice = eventData.choices[i];
377
- const delta = eventChoice.text;
378
- if (streamDelta[i] == null) {
379
- streamDelta[i] = {
380
- content: "",
381
- isComplete: false,
382
- delta: "",
383
- };
384
- }
385
- const choice = streamDelta[i];
386
- choice.delta = delta;
387
- if (eventChoice.finish_reason != null) {
388
- choice.isComplete = true;
389
- }
390
- choice.content += delta;
391
- }
392
- // Since we're mutating the choices array in an async scenario,
393
- // we need to make a deep copy:
394
- const streamDeltaDeepCopy = JSON.parse(JSON.stringify(streamDelta));
395
- queue.push({
396
- type: "delta",
397
- fullDelta: streamDeltaDeepCopy,
398
- valueDelta: streamDeltaDeepCopy[0].delta,
399
- });
400
- }
401
- }
402
- catch (error) {
403
- queue.push({ type: "error", error });
404
- queue.close();
405
- return;
406
- }
407
- })
408
- .catch((error) => {
409
- queue.push({ type: "error", error });
410
- queue.close();
411
- return;
412
- });
413
- return queue;
414
- }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const streamText_js_1 = require("../../model-function/generate-text/streamText.cjs");
4
+ const StreamingTestServer_js_1 = require("../../test/StreamingTestServer.cjs");
5
+ const arrayFromAsync_js_1 = require("../../test/arrayFromAsync.cjs");
6
+ const OpenAIApiConfiguration_js_1 = require("./OpenAIApiConfiguration.cjs");
7
+ const OpenAICompletionModel_js_1 = require("./OpenAICompletionModel.cjs");
8
+ describe("streamText", () => {
9
+ const server = new StreamingTestServer_js_1.StreamingTestServer("https://api.openai.com/v1/completions");
10
+ server.setupTestEnvironment();
11
+ it("should return only values from the first choice when using streamText", async () => {
12
+ server.responseChunks = [
13
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
14
+ `"choices":[{"text":"Hello","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
15
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
16
+ `"choices":[{"text":", ","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
17
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
18
+ `"choices":[{"text":"world!","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
19
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
20
+ `"choices":[{"text":"","index":0,"logprobs":null,"finish_reason":"length"}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
21
+ "data: [DONE]\n\n",
22
+ ];
23
+ const stream = await (0, streamText_js_1.streamText)(new OpenAICompletionModel_js_1.OpenAICompletionModel({
24
+ api: new OpenAIApiConfiguration_js_1.OpenAIApiConfiguration({ apiKey: "test-key" }),
25
+ model: "gpt-3.5-turbo-instruct",
26
+ }), "hello");
27
+ // note: space moved to last chunk bc of trimming
28
+ expect(await (0, arrayFromAsync_js_1.arrayFromAsync)(stream)).toStrictEqual([
29
+ "Hello",
30
+ ",",
31
+ " world!",
32
+ ]);
33
+ });
34
+ it("should return only values from the first choice when using streamText", async () => {
35
+ server.responseChunks = [
36
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
37
+ `"choices":[{"text":"A","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
38
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
39
+ `"choices":[{"text":"B","index":1,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
40
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
41
+ `"choices":[{"text":"","index":0,"logprobs":null,"finish_reason":"length"}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
42
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
43
+ `"choices":[{"text":"","index":1,"logprobs":null,"finish_reason":"length"}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
44
+ "data: [DONE]\n\n",
45
+ ];
46
+ const stream = await (0, streamText_js_1.streamText)(new OpenAICompletionModel_js_1.OpenAICompletionModel({
47
+ api: new OpenAIApiConfiguration_js_1.OpenAIApiConfiguration({ apiKey: "test-key" }),
48
+ model: "gpt-3.5-turbo-instruct",
49
+ numberOfGenerations: 2,
50
+ }), "test prompt");
51
+ expect(await (0, arrayFromAsync_js_1.arrayFromAsync)(stream)).toStrictEqual(["A"]);
52
+ });
53
+ });
@@ -0,0 +1,51 @@
1
+ import { streamText } from "../../model-function/generate-text/streamText.js";
2
+ import { StreamingTestServer } from "../../test/StreamingTestServer.js";
3
+ import { arrayFromAsync } from "../../test/arrayFromAsync.js";
4
+ import { OpenAIApiConfiguration } from "./OpenAIApiConfiguration.js";
5
+ import { OpenAICompletionModel } from "./OpenAICompletionModel.js";
6
+ describe("streamText", () => {
7
+ const server = new StreamingTestServer("https://api.openai.com/v1/completions");
8
+ server.setupTestEnvironment();
9
+ it("should return only values from the first choice when using streamText", async () => {
10
+ server.responseChunks = [
11
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
12
+ `"choices":[{"text":"Hello","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
13
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
14
+ `"choices":[{"text":", ","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
15
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
16
+ `"choices":[{"text":"world!","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
17
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
18
+ `"choices":[{"text":"","index":0,"logprobs":null,"finish_reason":"length"}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
19
+ "data: [DONE]\n\n",
20
+ ];
21
+ const stream = await streamText(new OpenAICompletionModel({
22
+ api: new OpenAIApiConfiguration({ apiKey: "test-key" }),
23
+ model: "gpt-3.5-turbo-instruct",
24
+ }), "hello");
25
+ // note: space moved to last chunk bc of trimming
26
+ expect(await arrayFromAsync(stream)).toStrictEqual([
27
+ "Hello",
28
+ ",",
29
+ " world!",
30
+ ]);
31
+ });
32
+ it("should return only values from the first choice when using streamText", async () => {
33
+ server.responseChunks = [
34
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
35
+ `"choices":[{"text":"A","index":0,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
36
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
37
+ `"choices":[{"text":"B","index":1,"logprobs":null,"finish_reason":null}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
38
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
39
+ `"choices":[{"text":"","index":0,"logprobs":null,"finish_reason":"length"}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
40
+ `data: {"id":"cmpl-8ZNls6dH7X2jUAJbY5joSWF9L0AD3","object":"text_completion","created":1703443548,` +
41
+ `"choices":[{"text":"","index":1,"logprobs":null,"finish_reason":"length"}],"model":"gpt-3.5-turbo-instruct"}\n\n`,
42
+ "data: [DONE]\n\n",
43
+ ];
44
+ const stream = await streamText(new OpenAICompletionModel({
45
+ api: new OpenAIApiConfiguration({ apiKey: "test-key" }),
46
+ model: "gpt-3.5-turbo-instruct",
47
+ numberOfGenerations: 2,
48
+ }), "test prompt");
49
+ expect(await arrayFromAsync(stream)).toStrictEqual(["A"]);
50
+ });
51
+ });
@@ -7,7 +7,7 @@ const OpenAISpeechModel_js_1 = require("./OpenAISpeechModel.cjs");
7
7
  const OpenAITextEmbeddingModel_js_1 = require("./OpenAITextEmbeddingModel.cjs");
8
8
  const OpenAITranscriptionModel_js_1 = require("./OpenAITranscriptionModel.cjs");
9
9
  const TikTokenTokenizer_js_1 = require("./TikTokenTokenizer.cjs");
10
- const OpenAIChatModel_js_1 = require("./chat/OpenAIChatModel.cjs");
10
+ const OpenAIChatModel_js_1 = require("./OpenAIChatModel.cjs");
11
11
  /**
12
12
  * Create a text generation model that calls the OpenAI text completion API.
13
13
  *
@@ -148,5 +148,5 @@ function Tokenizer(settings) {
148
148
  return new TikTokenTokenizer_js_1.TikTokenTokenizer(settings);
149
149
  }
150
150
  exports.Tokenizer = Tokenizer;
151
- var OpenAIChatMessage_js_1 = require("./chat/OpenAIChatMessage.cjs");
151
+ var OpenAIChatMessage_js_1 = require("./OpenAIChatMessage.cjs");
152
152
  Object.defineProperty(exports, "ChatMessage", { enumerable: true, get: function () { return OpenAIChatMessage_js_1.OpenAIChatMessage; } });
@@ -4,7 +4,7 @@ import { OpenAISpeechModel, OpenAISpeechModelSettings } from "./OpenAISpeechMode
4
4
  import { OpenAITextEmbeddingModel, OpenAITextEmbeddingModelSettings } from "./OpenAITextEmbeddingModel.js";
5
5
  import { OpenAITranscriptionModel, OpenAITranscriptionModelSettings } from "./OpenAITranscriptionModel.js";
6
6
  import { TikTokenTokenizer, TikTokenTokenizerSettings } from "./TikTokenTokenizer.js";
7
- import { OpenAIChatModel, OpenAIChatSettings } from "./chat/OpenAIChatModel.js";
7
+ import { OpenAIChatModel, OpenAIChatSettings } from "./OpenAIChatModel.js";
8
8
  /**
9
9
  * Create a text generation model that calls the OpenAI text completion API.
10
10
  *
@@ -124,5 +124,5 @@ export declare function ImageGenerator(settings: OpenAIImageGenerationSettings):
124
124
  * @returns A new instance of {@link TikTokenTokenizer}.
125
125
  */
126
126
  export declare function Tokenizer(settings: TikTokenTokenizerSettings): TikTokenTokenizer;
127
- export { OpenAIChatMessage as ChatMessage } from "./chat/OpenAIChatMessage.js";
128
- export { OpenAIChatPrompt as ChatPrompt } from "./chat/AbstractOpenAIChatModel.js";
127
+ export { OpenAIChatMessage as ChatMessage } from "./OpenAIChatMessage.js";
128
+ export { OpenAIChatPrompt as ChatPrompt } from "./AbstractOpenAIChatModel.js";
@@ -4,7 +4,7 @@ import { OpenAISpeechModel, } from "./OpenAISpeechModel.js";
4
4
  import { OpenAITextEmbeddingModel, } from "./OpenAITextEmbeddingModel.js";
5
5
  import { OpenAITranscriptionModel, } from "./OpenAITranscriptionModel.js";
6
6
  import { TikTokenTokenizer, } from "./TikTokenTokenizer.js";
7
- import { OpenAIChatModel } from "./chat/OpenAIChatModel.js";
7
+ import { OpenAIChatModel } from "./OpenAIChatModel.js";
8
8
  /**
9
9
  * Create a text generation model that calls the OpenAI text completion API.
10
10
  *
@@ -138,4 +138,4 @@ export function ImageGenerator(settings) {
138
138
  export function Tokenizer(settings) {
139
139
  return new TikTokenTokenizer(settings);
140
140
  }
141
- export { OpenAIChatMessage as ChatMessage } from "./chat/OpenAIChatMessage.js";
141
+ export { OpenAIChatMessage as ChatMessage } from "./OpenAIChatMessage.js";
@@ -52,16 +52,16 @@ export declare class OpenAITextEmbeddingModel extends AbstractModel<OpenAITextEm
52
52
  doEmbedValues(texts: string[], options?: FunctionOptions): Promise<{
53
53
  response: {
54
54
  object: "list";
55
- usage: {
56
- prompt_tokens: number;
57
- total_tokens: number;
58
- };
59
- model: string;
60
55
  data: {
61
56
  object: "embedding";
62
57
  embedding: number[];
63
58
  index: number;
64
59
  }[];
60
+ usage: {
61
+ prompt_tokens: number;
62
+ total_tokens: number;
63
+ };
64
+ model: string;
65
65
  };
66
66
  embeddings: number[][];
67
67
  }>;
@@ -95,28 +95,28 @@ declare const openAITextEmbeddingResponseSchema: z.ZodObject<{
95
95
  }>;
96
96
  }, "strip", z.ZodTypeAny, {
97
97
  object: "list";
98
- usage: {
99
- prompt_tokens: number;
100
- total_tokens: number;
101
- };
102
- model: string;
103
98
  data: {
104
99
  object: "embedding";
105
100
  embedding: number[];
106
101
  index: number;
107
102
  }[];
108
- }, {
109
- object: "list";
110
103
  usage: {
111
104
  prompt_tokens: number;
112
105
  total_tokens: number;
113
106
  };
114
107
  model: string;
108
+ }, {
109
+ object: "list";
115
110
  data: {
116
111
  object: "embedding";
117
112
  embedding: number[];
118
113
  index: number;
119
114
  }[];
115
+ usage: {
116
+ prompt_tokens: number;
117
+ total_tokens: number;
118
+ };
119
+ model: string;
120
120
  }>;
121
121
  export type OpenAITextEmbeddingResponse = z.infer<typeof openAITextEmbeddingResponseSchema>;
122
122
  export {};