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
@@ -0,0 +1,30 @@
1
+ export interface TextPart {
2
+ type: "text";
3
+ /**
4
+ * The text content.
5
+ */
6
+ text: string;
7
+ }
8
+ export interface ImagePart {
9
+ type: "image";
10
+ /**
11
+ * Base-64 encoded image.
12
+ */
13
+ base64Image: string;
14
+ /**
15
+ * Optional mime type of the image.
16
+ */
17
+ mimeType?: string;
18
+ }
19
+ export interface ToolCallPart {
20
+ type: "tool-call";
21
+ id: string;
22
+ name: string;
23
+ args: unknown;
24
+ }
25
+ export interface ToolResponsePart {
26
+ type: "tool-response";
27
+ id: string;
28
+ response: unknown;
29
+ }
30
+ export declare function validateContentIsString(content: string | unknown, prompt: unknown): string;
@@ -1,7 +1,7 @@
1
1
  import { InvalidPromptError } from "./InvalidPromptError.js";
2
2
  export function validateContentIsString(content, prompt) {
3
3
  if (typeof content !== "string") {
4
- throw new InvalidPromptError("only text prompts are are supported by this prompt template", prompt);
4
+ throw new InvalidPromptError("Only text prompts are are supported by this prompt template.", prompt);
5
5
  }
6
6
  return content;
7
7
  }
@@ -1,4 +1,4 @@
1
- import { Content } from "./Content.js";
1
+ import { ImagePart, TextPart } from "./ContentPart";
2
2
  /**
3
3
  * A single text instruction prompt. It can contain an optional system message to define
4
4
  * the role and behavior of the language model.
@@ -22,10 +22,11 @@ export interface InstructionPrompt {
22
22
  /**
23
23
  * The instruction for the model.
24
24
  */
25
- instruction: Content;
25
+ instruction: InstructionContent;
26
26
  /**
27
27
  * Response prefix that will be injected in the prompt at the beginning of the response.
28
28
  * This is useful for guiding the model by starting its response with a specific text.
29
29
  */
30
30
  responsePrefix?: string;
31
31
  }
32
+ export type InstructionContent = string | Array<TextPart | ImagePart>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateLlama2Prompt = exports.chat = exports.instruction = exports.text = void 0;
4
- const Content_js_1 = require("./Content.cjs");
4
+ const ContentPart_js_1 = require("./ContentPart.cjs");
5
5
  const InvalidPromptError_js_1 = require("./InvalidPromptError.cjs");
6
6
  // see https://github.com/facebookresearch/llama/blob/6c7fe276574e78057f917549435a2554000a876d/llama/generation.py#L44
7
7
  const BEGIN_SEGMENT = "<s>";
@@ -15,7 +15,7 @@ const END_SYSTEM = "\n<</SYS>>\n\n";
15
15
  *
16
16
  * Llama 2 prompt template:
17
17
  * ```
18
- * <s>[INST]{ instruction } [/INST]
18
+ * <s>[INST] { instruction } [/INST]
19
19
  * ```
20
20
  *
21
21
  * @see https://www.philschmid.de/llama-2#how-to-prompt-llama-2-chat
@@ -48,7 +48,7 @@ function instruction() {
48
48
  return {
49
49
  stopSequences: [END_SEGMENT],
50
50
  format(prompt) {
51
- const instruction = (0, Content_js_1.validateContentIsString)(prompt.instruction, prompt);
51
+ const instruction = (0, ContentPart_js_1.validateContentIsString)(prompt.instruction, prompt);
52
52
  return `${BEGIN_SEGMENT}${BEGIN_INSTRUCTION}${prompt.system != null
53
53
  ? `${BEGIN_SYSTEM}${prompt.system}${END_SYSTEM}`
54
54
  : ""}${instruction}${END_INSTRUCTION}${prompt.responsePrefix ?? ""}`;
@@ -80,14 +80,17 @@ function chat() {
80
80
  for (const { role, content } of prompt.messages) {
81
81
  switch (role) {
82
82
  case "user": {
83
- const textContent = (0, Content_js_1.validateContentIsString)(content, prompt);
83
+ const textContent = (0, ContentPart_js_1.validateContentIsString)(content, prompt);
84
84
  text += `${BEGIN_SEGMENT}${BEGIN_INSTRUCTION}${textContent}${END_INSTRUCTION}`;
85
85
  break;
86
86
  }
87
87
  case "assistant": {
88
- text += `${content}${END_SEGMENT}`;
88
+ text += `${(0, ContentPart_js_1.validateContentIsString)(content, prompt)}${END_SEGMENT}`;
89
89
  break;
90
90
  }
91
+ case "tool": {
92
+ throw new InvalidPromptError_js_1.InvalidPromptError("Tool messages are not supported.", prompt);
93
+ }
91
94
  default: {
92
95
  const _exhaustiveCheck = role;
93
96
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
@@ -6,7 +6,7 @@ import { InstructionPrompt } from "./InstructionPrompt.js";
6
6
  *
7
7
  * Llama 2 prompt template:
8
8
  * ```
9
- * <s>[INST]{ instruction } [/INST]
9
+ * <s>[INST] { instruction } [/INST]
10
10
  * ```
11
11
  *
12
12
  * @see https://www.philschmid.de/llama-2#how-to-prompt-llama-2-chat
@@ -1,4 +1,4 @@
1
- import { validateContentIsString } from "./Content.js";
1
+ import { validateContentIsString } from "./ContentPart.js";
2
2
  import { InvalidPromptError } from "./InvalidPromptError.js";
3
3
  // see https://github.com/facebookresearch/llama/blob/6c7fe276574e78057f917549435a2554000a876d/llama/generation.py#L44
4
4
  const BEGIN_SEGMENT = "<s>";
@@ -12,7 +12,7 @@ const END_SYSTEM = "\n<</SYS>>\n\n";
12
12
  *
13
13
  * Llama 2 prompt template:
14
14
  * ```
15
- * <s>[INST]{ instruction } [/INST]
15
+ * <s>[INST] { instruction } [/INST]
16
16
  * ```
17
17
  *
18
18
  * @see https://www.philschmid.de/llama-2#how-to-prompt-llama-2-chat
@@ -80,9 +80,12 @@ export function chat() {
80
80
  break;
81
81
  }
82
82
  case "assistant": {
83
- text += `${content}${END_SEGMENT}`;
83
+ text += `${validateContentIsString(content, prompt)}${END_SEGMENT}`;
84
84
  break;
85
85
  }
86
+ case "tool": {
87
+ throw new InvalidPromptError("Tool messages are not supported.", prompt);
88
+ }
86
89
  default: {
87
90
  const _exhaustiveCheck = role;
88
91
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chat = exports.instruction = exports.text = void 0;
4
- const Content_js_1 = require("./Content.cjs");
4
+ const ContentPart_js_1 = require("./ContentPart.cjs");
5
+ const InvalidPromptError_js_1 = require("./InvalidPromptError.cjs");
5
6
  const roleNames = {
6
7
  system: "System",
7
8
  user: "User",
@@ -36,7 +37,7 @@ exports.text = text;
36
37
  const instruction = () => ({
37
38
  stopSequences: [],
38
39
  format(prompt) {
39
- const instruction = (0, Content_js_1.validateContentIsString)(prompt.instruction, prompt);
40
+ const instruction = (0, ContentPart_js_1.validateContentIsString)(prompt.instruction, prompt);
40
41
  return (segment("system", prompt.system) +
41
42
  segment("user", instruction) +
42
43
  segmentStart("assistant") +
@@ -58,14 +59,17 @@ function chat() {
58
59
  for (const { role, content } of prompt.messages) {
59
60
  switch (role) {
60
61
  case "user": {
61
- const textContent = (0, Content_js_1.validateContentIsString)(content, prompt);
62
+ const textContent = (0, ContentPart_js_1.validateContentIsString)(content, prompt);
62
63
  text += segment("user", textContent);
63
64
  break;
64
65
  }
65
66
  case "assistant": {
66
- text += segment("assistant", content);
67
+ text += segment("assistant", (0, ContentPart_js_1.validateContentIsString)(content, prompt));
67
68
  break;
68
69
  }
70
+ case "tool": {
71
+ throw new InvalidPromptError_js_1.InvalidPromptError("Tool messages are not supported.", prompt);
72
+ }
69
73
  default: {
70
74
  const _exhaustiveCheck = role;
71
75
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
@@ -1,4 +1,5 @@
1
- import { validateContentIsString } from "./Content.js";
1
+ import { validateContentIsString } from "./ContentPart.js";
2
+ import { InvalidPromptError } from "./InvalidPromptError.js";
2
3
  const roleNames = {
3
4
  system: "System",
4
5
  user: "User",
@@ -58,9 +59,12 @@ export function chat() {
58
59
  break;
59
60
  }
60
61
  case "assistant": {
61
- text += segment("assistant", content);
62
+ text += segment("assistant", validateContentIsString(content, prompt));
62
63
  break;
63
64
  }
65
+ case "tool": {
66
+ throw new InvalidPromptError("Tool messages are not supported.", prompt);
67
+ }
64
68
  default: {
65
69
  const _exhaustiveCheck = role;
66
70
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chat = exports.instruction = exports.text = void 0;
4
- const Content_js_1 = require("./Content.cjs");
4
+ const ContentPart_js_1 = require("./ContentPart.cjs");
5
+ const InvalidPromptError_js_1 = require("./InvalidPromptError.cjs");
5
6
  /**
6
7
  * Formats a text prompt as a basic text prompt. Does not change the text prompt in any way.
7
8
  */
@@ -20,7 +21,7 @@ const instruction = () => ({
20
21
  if (prompt.system != null) {
21
22
  text += `${prompt.system}\n\n`;
22
23
  }
23
- text += `${(0, Content_js_1.validateContentIsString)(prompt.instruction, prompt)}\n\n`;
24
+ text += `${(0, ContentPart_js_1.validateContentIsString)(prompt.instruction, prompt)}\n\n`;
24
25
  if (prompt.responsePrefix != null) {
25
26
  text += prompt.responsePrefix;
26
27
  }
@@ -43,13 +44,16 @@ const chat = ({ user = "user", assistant = "assistant", system, } = {}) => ({
43
44
  for (const { role, content } of prompt.messages) {
44
45
  switch (role) {
45
46
  case "user": {
46
- text += `${user}:\n${(0, Content_js_1.validateContentIsString)(content, prompt)}\n\n`;
47
+ text += `${user}:\n${(0, ContentPart_js_1.validateContentIsString)(content, prompt)}\n\n`;
47
48
  break;
48
49
  }
49
50
  case "assistant": {
50
- text += `${assistant}:\n${content}\n\n`;
51
+ text += `${assistant}:\n${(0, ContentPart_js_1.validateContentIsString)(content, prompt)}\n\n`;
51
52
  break;
52
53
  }
54
+ case "tool": {
55
+ throw new InvalidPromptError_js_1.InvalidPromptError("Tool messages are not supported.", prompt);
56
+ }
53
57
  default: {
54
58
  const _exhaustiveCheck = role;
55
59
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
@@ -1,4 +1,5 @@
1
- import { validateContentIsString } from "./Content.js";
1
+ import { validateContentIsString } from "./ContentPart.js";
2
+ import { InvalidPromptError } from "./InvalidPromptError.js";
2
3
  /**
3
4
  * Formats a text prompt as a basic text prompt. Does not change the text prompt in any way.
4
5
  */
@@ -42,9 +43,12 @@ export const chat = ({ user = "user", assistant = "assistant", system, } = {}) =
42
43
  break;
43
44
  }
44
45
  case "assistant": {
45
- text += `${assistant}:\n${content}\n\n`;
46
+ text += `${assistant}:\n${validateContentIsString(content, prompt)}\n\n`;
46
47
  break;
47
48
  }
49
+ case "tool": {
50
+ throw new InvalidPromptError("Tool messages are not supported.", prompt);
51
+ }
48
52
  default: {
49
53
  const _exhaustiveCheck = role;
50
54
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chat = void 0;
4
- const Content_js_1 = require("./Content.cjs");
4
+ const ContentPart_js_1 = require("./ContentPart.cjs");
5
+ const InvalidPromptError_js_1 = require("./InvalidPromptError.cjs");
5
6
  // default Vicuna 1 system message
6
7
  const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial intelligence assistant. " +
7
8
  "The assistant gives helpful, detailed, and polite answers to the user's questions.";
@@ -27,14 +28,17 @@ function chat() {
27
28
  for (const { role, content } of prompt.messages) {
28
29
  switch (role) {
29
30
  case "user": {
30
- const textContent = (0, Content_js_1.validateContentIsString)(content, prompt);
31
+ const textContent = (0, ContentPart_js_1.validateContentIsString)(content, prompt);
31
32
  text += `USER: ${textContent}\n`;
32
33
  break;
33
34
  }
34
35
  case "assistant": {
35
- text += `ASSISTANT: ${content}\n`;
36
+ text += `ASSISTANT: ${(0, ContentPart_js_1.validateContentIsString)(content, prompt)}\n`;
36
37
  break;
37
38
  }
39
+ case "tool": {
40
+ throw new InvalidPromptError_js_1.InvalidPromptError("Tool messages are not supported.", prompt);
41
+ }
38
42
  default: {
39
43
  const _exhaustiveCheck = role;
40
44
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
@@ -1,4 +1,5 @@
1
- import { validateContentIsString } from "./Content.js";
1
+ import { validateContentIsString } from "./ContentPart.js";
2
+ import { InvalidPromptError } from "./InvalidPromptError.js";
2
3
  // default Vicuna 1 system message
3
4
  const DEFAULT_SYSTEM_MESSAGE = "A chat between a curious user and an artificial intelligence assistant. " +
4
5
  "The assistant gives helpful, detailed, and polite answers to the user's questions.";
@@ -29,9 +30,12 @@ export function chat() {
29
30
  break;
30
31
  }
31
32
  case "assistant": {
32
- text += `ASSISTANT: ${content}\n`;
33
+ text += `ASSISTANT: ${validateContentIsString(content, prompt)}\n`;
33
34
  break;
34
35
  }
36
+ case "tool": {
37
+ throw new InvalidPromptError("Tool messages are not supported.", prompt);
38
+ }
35
39
  default: {
36
40
  const _exhaustiveCheck = role;
37
41
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
@@ -30,7 +30,7 @@ exports.VicunaPrompt = exports.TextPrompt = exports.NeuralChatPrompt = exports.L
30
30
  exports.AlpacaPrompt = __importStar(require("./AlpacaPromptTemplate.cjs"));
31
31
  exports.ChatMLPrompt = __importStar(require("./ChatMLPromptTemplate.cjs"));
32
32
  __exportStar(require("./ChatPrompt.cjs"), exports);
33
- __exportStar(require("./Content.cjs"), exports);
33
+ __exportStar(require("./ContentPart.cjs"), exports);
34
34
  __exportStar(require("./InstructionPrompt.cjs"), exports);
35
35
  __exportStar(require("./InvalidPromptError.cjs"), exports);
36
36
  exports.Llama2Prompt = __importStar(require("./Llama2PromptTemplate.cjs"));
@@ -1,7 +1,7 @@
1
1
  export * as AlpacaPrompt from "./AlpacaPromptTemplate.js";
2
2
  export * as ChatMLPrompt from "./ChatMLPromptTemplate.js";
3
3
  export * from "./ChatPrompt.js";
4
- export * from "./Content.js";
4
+ export * from "./ContentPart.js";
5
5
  export * from "./InstructionPrompt.js";
6
6
  export * from "./InvalidPromptError.js";
7
7
  export * as Llama2Prompt from "./Llama2PromptTemplate.js";
@@ -1,7 +1,7 @@
1
1
  export * as AlpacaPrompt from "./AlpacaPromptTemplate.js";
2
2
  export * as ChatMLPrompt from "./ChatMLPromptTemplate.js";
3
3
  export * from "./ChatPrompt.js";
4
- export * from "./Content.js";
4
+ export * from "./ContentPart.js";
5
5
  export * from "./InstructionPrompt.js";
6
6
  export * from "./InvalidPromptError.js";
7
7
  export * as Llama2Prompt from "./Llama2PromptTemplate.js";
@@ -5,9 +5,12 @@ const executeStreamCall_js_1 = require("../executeStreamCall.cjs");
5
5
  async function streamText(model, prompt, options) {
6
6
  const shouldTrimWhitespace = model.settings.trimWhitespace ?? true;
7
7
  let accumulatedText = "";
8
- let lastFullDelta;
9
8
  let isFirstDelta = true;
10
9
  let trailingWhitespace = "";
10
+ let resolveText;
11
+ const textPromise = new Promise((resolve) => {
12
+ resolveText = resolve;
13
+ });
11
14
  const fullResponse = await (0, executeStreamCall_js_1.executeStreamCall)({
12
15
  functionType: "stream-text",
13
16
  input: prompt,
@@ -15,39 +18,35 @@ async function streamText(model, prompt, options) {
15
18
  options,
16
19
  startStream: async (options) => model.doStreamText(prompt, options),
17
20
  processDelta: (delta) => {
18
- lastFullDelta = delta.fullDelta;
19
- let textDelta = delta.valueDelta;
20
- if (textDelta != null && textDelta.length > 0) {
21
- if (shouldTrimWhitespace) {
22
- if (isFirstDelta) {
23
- // remove leading whitespace:
24
- textDelta = textDelta.trimStart();
25
- }
26
- else {
27
- // restore trailing whitespace from previous chunk:
28
- textDelta = trailingWhitespace + textDelta;
29
- }
30
- // trim trailing whitespace and store it for the next chunk:
31
- const trailingWhitespaceMatch = textDelta.match(/\s+$/);
32
- trailingWhitespace = trailingWhitespaceMatch
33
- ? trailingWhitespaceMatch[0]
34
- : "";
35
- textDelta = textDelta.trimEnd();
36
- }
37
- isFirstDelta = false;
38
- accumulatedText += textDelta;
39
- return textDelta;
21
+ let textDelta = model.extractTextDelta(delta.deltaValue);
22
+ if (textDelta == null || textDelta.length === 0) {
23
+ return undefined;
24
+ }
25
+ if (shouldTrimWhitespace) {
26
+ textDelta = isFirstDelta
27
+ ? // remove leading whitespace:
28
+ textDelta.trimStart()
29
+ : // restore trailing whitespace from previous chunk:
30
+ trailingWhitespace + textDelta;
31
+ // trim trailing whitespace and store it for the next chunk:
32
+ const trailingWhitespaceMatch = textDelta.match(/\s+$/);
33
+ trailingWhitespace = trailingWhitespaceMatch
34
+ ? trailingWhitespaceMatch[0]
35
+ : "";
36
+ textDelta = textDelta.trimEnd();
40
37
  }
41
- return undefined;
38
+ isFirstDelta = false;
39
+ accumulatedText += textDelta;
40
+ return textDelta;
41
+ },
42
+ onDone: () => {
43
+ resolveText(accumulatedText);
42
44
  },
43
- getResult: () => ({
44
- response: lastFullDelta,
45
- value: accumulatedText,
46
- }),
47
45
  });
48
46
  return options?.fullResponse
49
47
  ? {
50
48
  textStream: fullResponse.value,
49
+ text: textPromise,
51
50
  metadata: fullResponse.metadata,
52
51
  }
53
52
  : fullResponse.value;
@@ -33,5 +33,6 @@ export declare function streamText<PROMPT>(model: TextStreamingModel<PROMPT>, pr
33
33
  fullResponse: true;
34
34
  }): Promise<{
35
35
  textStream: AsyncIterable<string>;
36
+ text: PromiseLike<string>;
36
37
  metadata: Omit<ModelCallMetadata, "durationInMs" | "finishTimestamp">;
37
38
  }>;
@@ -2,9 +2,12 @@ import { executeStreamCall } from "../executeStreamCall.js";
2
2
  export async function streamText(model, prompt, options) {
3
3
  const shouldTrimWhitespace = model.settings.trimWhitespace ?? true;
4
4
  let accumulatedText = "";
5
- let lastFullDelta;
6
5
  let isFirstDelta = true;
7
6
  let trailingWhitespace = "";
7
+ let resolveText;
8
+ const textPromise = new Promise((resolve) => {
9
+ resolveText = resolve;
10
+ });
8
11
  const fullResponse = await executeStreamCall({
9
12
  functionType: "stream-text",
10
13
  input: prompt,
@@ -12,39 +15,35 @@ export async function streamText(model, prompt, options) {
12
15
  options,
13
16
  startStream: async (options) => model.doStreamText(prompt, options),
14
17
  processDelta: (delta) => {
15
- lastFullDelta = delta.fullDelta;
16
- let textDelta = delta.valueDelta;
17
- if (textDelta != null && textDelta.length > 0) {
18
- if (shouldTrimWhitespace) {
19
- if (isFirstDelta) {
20
- // remove leading whitespace:
21
- textDelta = textDelta.trimStart();
22
- }
23
- else {
24
- // restore trailing whitespace from previous chunk:
25
- textDelta = trailingWhitespace + textDelta;
26
- }
27
- // trim trailing whitespace and store it for the next chunk:
28
- const trailingWhitespaceMatch = textDelta.match(/\s+$/);
29
- trailingWhitespace = trailingWhitespaceMatch
30
- ? trailingWhitespaceMatch[0]
31
- : "";
32
- textDelta = textDelta.trimEnd();
33
- }
34
- isFirstDelta = false;
35
- accumulatedText += textDelta;
36
- return textDelta;
18
+ let textDelta = model.extractTextDelta(delta.deltaValue);
19
+ if (textDelta == null || textDelta.length === 0) {
20
+ return undefined;
21
+ }
22
+ if (shouldTrimWhitespace) {
23
+ textDelta = isFirstDelta
24
+ ? // remove leading whitespace:
25
+ textDelta.trimStart()
26
+ : // restore trailing whitespace from previous chunk:
27
+ trailingWhitespace + textDelta;
28
+ // trim trailing whitespace and store it for the next chunk:
29
+ const trailingWhitespaceMatch = textDelta.match(/\s+$/);
30
+ trailingWhitespace = trailingWhitespaceMatch
31
+ ? trailingWhitespaceMatch[0]
32
+ : "";
33
+ textDelta = textDelta.trimEnd();
37
34
  }
38
- return undefined;
35
+ isFirstDelta = false;
36
+ accumulatedText += textDelta;
37
+ return textDelta;
38
+ },
39
+ onDone: () => {
40
+ resolveText(accumulatedText);
39
41
  },
40
- getResult: () => ({
41
- response: lastFullDelta,
42
- value: accumulatedText,
43
- }),
44
42
  });
45
43
  return options?.fullResponse
46
44
  ? {
47
45
  textStream: fullResponse.value,
46
+ text: textPromise,
48
47
  metadata: fullResponse.metadata,
49
48
  }
50
49
  : fullResponse.value;
@@ -20,7 +20,6 @@ __exportStar(require("./ModelCallEvent.cjs"), exports);
20
20
  __exportStar(require("./ModelCallMetadata.cjs"), exports);
21
21
  __exportStar(require("./ModelInformation.cjs"), exports);
22
22
  __exportStar(require("./PromptTemplate.cjs"), exports);
23
- __exportStar(require("./SuccessfulModelCall.cjs"), exports);
24
23
  __exportStar(require("./embed/EmbeddingEvent.cjs"), exports);
25
24
  __exportStar(require("./embed/EmbeddingModel.cjs"), exports);
26
25
  __exportStar(require("./embed/embed.cjs"), exports);
@@ -4,7 +4,6 @@ export * from "./ModelCallEvent.js";
4
4
  export * from "./ModelCallMetadata.js";
5
5
  export * from "./ModelInformation.js";
6
6
  export * from "./PromptTemplate.js";
7
- export * from "./SuccessfulModelCall.js";
8
7
  export * from "./embed/EmbeddingEvent.js";
9
8
  export * from "./embed/EmbeddingModel.js";
10
9
  export * from "./embed/embed.js";
@@ -4,7 +4,6 @@ export * from "./ModelCallEvent.js";
4
4
  export * from "./ModelCallMetadata.js";
5
5
  export * from "./ModelInformation.js";
6
6
  export * from "./PromptTemplate.js";
7
- export * from "./SuccessfulModelCall.js";
8
7
  export * from "./embed/EmbeddingEvent.js";
9
8
  export * from "./embed/EmbeddingModel.js";
10
9
  export * from "./embed/embed.js";
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.chat = exports.instruction = exports.text = void 0;
4
- const Content_js_1 = require("../../model-function/generate-text/prompt-template/Content.cjs");
4
+ const ContentPart_js_1 = require("../../model-function/generate-text/prompt-template/ContentPart.cjs");
5
+ const InvalidPromptError_js_1 = require("../../model-function/generate-text/prompt-template/InvalidPromptError.cjs");
5
6
  const HUMAN_PREFIX = "\n\nHuman:";
6
7
  const ASSISTANT_PREFIX = "\n\nAssistant:";
7
8
  /**
@@ -26,7 +27,7 @@ exports.text = text;
26
27
  function instruction() {
27
28
  return {
28
29
  format(prompt) {
29
- const instruction = (0, Content_js_1.validateContentIsString)(prompt.instruction, prompt);
30
+ const instruction = (0, ContentPart_js_1.validateContentIsString)(prompt.instruction, prompt);
30
31
  let text = prompt.system ?? "";
31
32
  text += HUMAN_PREFIX;
32
33
  text += instruction;
@@ -52,7 +53,7 @@ function chat() {
52
53
  for (const { role, content } of prompt.messages) {
53
54
  switch (role) {
54
55
  case "user": {
55
- const textContent = (0, Content_js_1.validateContentIsString)(content, prompt);
56
+ const textContent = (0, ContentPart_js_1.validateContentIsString)(content, prompt);
56
57
  text += HUMAN_PREFIX;
57
58
  text += textContent;
58
59
  break;
@@ -62,6 +63,9 @@ function chat() {
62
63
  text += content;
63
64
  break;
64
65
  }
66
+ case "tool": {
67
+ throw new InvalidPromptError_js_1.InvalidPromptError("Tool messages are not supported.", prompt);
68
+ }
65
69
  default: {
66
70
  const _exhaustiveCheck = role;
67
71
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
@@ -1,4 +1,5 @@
1
- import { validateContentIsString } from "../../model-function/generate-text/prompt-template/Content.js";
1
+ import { validateContentIsString } from "../../model-function/generate-text/prompt-template/ContentPart.js";
2
+ import { InvalidPromptError } from "../../model-function/generate-text/prompt-template/InvalidPromptError.js";
2
3
  const HUMAN_PREFIX = "\n\nHuman:";
3
4
  const ASSISTANT_PREFIX = "\n\nAssistant:";
4
5
  /**
@@ -57,6 +58,9 @@ export function chat() {
57
58
  text += content;
58
59
  break;
59
60
  }
61
+ case "tool": {
62
+ throw new InvalidPromptError("Tool messages are not supported.", prompt);
63
+ }
60
64
  default: {
61
65
  const _exhaustiveCheck = role;
62
66
  throw new Error(`Unsupported role: ${_exhaustiveCheck}`);