node-llama-cpp 3.0.0-beta.1 → 3.0.0-beta.11

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 (354) hide show
  1. package/README.md +2 -0
  2. package/dist/ChatWrapper.d.ts +49 -0
  3. package/dist/ChatWrapper.js +120 -0
  4. package/dist/ChatWrapper.js.map +1 -0
  5. package/dist/{utils/getBin.d.ts → bindings/AddonTypes.d.ts} +14 -4
  6. package/dist/bindings/AddonTypes.js +2 -0
  7. package/dist/bindings/AddonTypes.js.map +1 -0
  8. package/dist/bindings/Llama.d.ts +23 -0
  9. package/dist/bindings/Llama.js +225 -0
  10. package/dist/bindings/Llama.js.map +1 -0
  11. package/dist/bindings/getLlama.d.ts +103 -0
  12. package/dist/bindings/getLlama.js +228 -0
  13. package/dist/bindings/getLlama.js.map +1 -0
  14. package/dist/bindings/types.d.ts +33 -0
  15. package/dist/bindings/types.js +30 -0
  16. package/dist/bindings/types.js.map +1 -0
  17. package/dist/bindings/utils/NoBinaryFoundError.d.ts +2 -0
  18. package/dist/bindings/utils/NoBinaryFoundError.js +7 -0
  19. package/dist/bindings/utils/NoBinaryFoundError.js.map +1 -0
  20. package/dist/{utils → bindings/utils}/binariesGithubRelease.js +1 -1
  21. package/dist/bindings/utils/binariesGithubRelease.js.map +1 -0
  22. package/dist/bindings/utils/clearAllLocalBuilds.d.ts +1 -0
  23. package/dist/bindings/utils/clearAllLocalBuilds.js +47 -0
  24. package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -0
  25. package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +11 -0
  26. package/dist/bindings/utils/cloneLlamaCppRepo.js +155 -0
  27. package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -0
  28. package/dist/bindings/utils/compileLLamaCpp.d.ts +12 -0
  29. package/dist/bindings/utils/compileLLamaCpp.js +157 -0
  30. package/dist/bindings/utils/compileLLamaCpp.js.map +1 -0
  31. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.d.ts +5 -0
  32. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +85 -0
  33. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -0
  34. package/dist/bindings/utils/getCanUsePrebuiltBinaries.d.ts +1 -0
  35. package/dist/bindings/utils/getCanUsePrebuiltBinaries.js +8 -0
  36. package/dist/bindings/utils/getCanUsePrebuiltBinaries.js.map +1 -0
  37. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.d.ts +2 -0
  38. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js +21 -0
  39. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -0
  40. package/dist/bindings/utils/getPlatform.d.ts +2 -0
  41. package/dist/bindings/utils/getPlatform.js +15 -0
  42. package/dist/bindings/utils/getPlatform.js.map +1 -0
  43. package/dist/bindings/utils/lastBuildInfo.d.ts +6 -0
  44. package/dist/bindings/utils/lastBuildInfo.js +17 -0
  45. package/dist/bindings/utils/lastBuildInfo.js.map +1 -0
  46. package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +2 -0
  47. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +28 -0
  48. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -0
  49. package/dist/bindings/utils/resolveChatWrapperBasedOnWrapperTypeName.d.ts +26 -0
  50. package/dist/bindings/utils/resolveChatWrapperBasedOnWrapperTypeName.js +43 -0
  51. package/dist/bindings/utils/resolveChatWrapperBasedOnWrapperTypeName.js.map +1 -0
  52. package/dist/bindings/utils/resolveCustomCmakeOptions.d.ts +1 -0
  53. package/dist/bindings/utils/resolveCustomCmakeOptions.js +43 -0
  54. package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -0
  55. package/dist/chatWrappers/AlpacaChatWrapper.d.ts +12 -0
  56. package/dist/chatWrappers/AlpacaChatWrapper.js +21 -0
  57. package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -0
  58. package/dist/chatWrappers/ChatMLChatWrapper.d.ts +18 -0
  59. package/dist/chatWrappers/ChatMLChatWrapper.js +83 -0
  60. package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -0
  61. package/dist/chatWrappers/EmptyChatWrapper.d.ts +4 -0
  62. package/dist/chatWrappers/EmptyChatWrapper.js +5 -0
  63. package/dist/chatWrappers/EmptyChatWrapper.js.map +1 -0
  64. package/dist/chatWrappers/FalconChatWrapper.d.ts +21 -0
  65. package/dist/chatWrappers/FalconChatWrapper.js +104 -0
  66. package/dist/chatWrappers/FalconChatWrapper.js.map +1 -0
  67. package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +41 -0
  68. package/dist/chatWrappers/FunctionaryChatWrapper.js +200 -0
  69. package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -0
  70. package/dist/chatWrappers/GeneralChatWrapper.d.ts +21 -0
  71. package/dist/chatWrappers/GeneralChatWrapper.js +112 -0
  72. package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -0
  73. package/dist/chatWrappers/LlamaChatWrapper.d.ts +13 -0
  74. package/dist/chatWrappers/LlamaChatWrapper.js +78 -0
  75. package/dist/chatWrappers/LlamaChatWrapper.js.map +1 -0
  76. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.d.ts +5 -5
  77. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js +28 -17
  78. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js.map +1 -1
  79. package/dist/cli/cli.js +8 -0
  80. package/dist/cli/cli.js.map +1 -1
  81. package/dist/cli/commands/BuildCommand.d.ts +2 -1
  82. package/dist/cli/commands/BuildCommand.js +50 -10
  83. package/dist/cli/commands/BuildCommand.js.map +1 -1
  84. package/dist/cli/commands/ChatCommand.d.ts +11 -4
  85. package/dist/cli/commands/ChatCommand.js +138 -64
  86. package/dist/cli/commands/ChatCommand.js.map +1 -1
  87. package/dist/cli/commands/ClearCommand.js +4 -6
  88. package/dist/cli/commands/ClearCommand.js.map +1 -1
  89. package/dist/cli/commands/CompleteCommand.d.ts +25 -0
  90. package/dist/cli/commands/CompleteCommand.js +278 -0
  91. package/dist/cli/commands/CompleteCommand.js.map +1 -0
  92. package/dist/cli/commands/DebugCommand.d.ts +7 -0
  93. package/dist/cli/commands/DebugCommand.js +59 -0
  94. package/dist/cli/commands/DebugCommand.js.map +1 -0
  95. package/dist/cli/commands/DownloadCommand.d.ts +2 -1
  96. package/dist/cli/commands/DownloadCommand.js +47 -40
  97. package/dist/cli/commands/DownloadCommand.js.map +1 -1
  98. package/dist/cli/commands/InfillCommand.d.ts +27 -0
  99. package/dist/cli/commands/InfillCommand.js +316 -0
  100. package/dist/cli/commands/InfillCommand.js.map +1 -0
  101. package/dist/cli/commands/OnPostInstallCommand.js +7 -10
  102. package/dist/cli/commands/OnPostInstallCommand.js.map +1 -1
  103. package/dist/config.d.ts +10 -3
  104. package/dist/config.js +18 -7
  105. package/dist/config.js.map +1 -1
  106. package/dist/consts.d.ts +1 -0
  107. package/dist/consts.js +2 -0
  108. package/dist/consts.js.map +1 -0
  109. package/dist/evaluator/LlamaChat/LlamaChat.d.ts +154 -0
  110. package/dist/evaluator/LlamaChat/LlamaChat.js +684 -0
  111. package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -0
  112. package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.d.ts +22 -0
  113. package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js +121 -0
  114. package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js.map +1 -0
  115. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.d.ts +16 -0
  116. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +135 -0
  117. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -0
  118. package/dist/{llamaEvaluator → evaluator/LlamaChatSession}/LlamaChatSession.d.ts +59 -25
  119. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +219 -0
  120. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -0
  121. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +7 -0
  122. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +8 -0
  123. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -0
  124. package/dist/evaluator/LlamaCompletion.d.ts +148 -0
  125. package/dist/evaluator/LlamaCompletion.js +402 -0
  126. package/dist/evaluator/LlamaCompletion.js.map +1 -0
  127. package/dist/{llamaEvaluator → evaluator}/LlamaContext/LlamaContext.d.ts +20 -23
  128. package/dist/{llamaEvaluator → evaluator}/LlamaContext/LlamaContext.js +77 -107
  129. package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -0
  130. package/dist/{llamaEvaluator → evaluator}/LlamaContext/types.d.ts +6 -14
  131. package/dist/evaluator/LlamaContext/types.js.map +1 -0
  132. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js.map +1 -0
  133. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js.map +1 -0
  134. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js.map +1 -0
  135. package/dist/evaluator/LlamaEmbeddingContext.d.ts +37 -0
  136. package/dist/evaluator/LlamaEmbeddingContext.js +78 -0
  137. package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -0
  138. package/dist/evaluator/LlamaGrammar.d.ts +30 -0
  139. package/dist/{llamaEvaluator → evaluator}/LlamaGrammar.js +14 -18
  140. package/dist/evaluator/LlamaGrammar.js.map +1 -0
  141. package/dist/{llamaEvaluator → evaluator}/LlamaGrammarEvaluationState.js +4 -4
  142. package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -0
  143. package/dist/{llamaEvaluator → evaluator}/LlamaJsonSchemaGrammar.d.ts +2 -1
  144. package/dist/{llamaEvaluator → evaluator}/LlamaJsonSchemaGrammar.js +4 -2
  145. package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -0
  146. package/dist/{llamaEvaluator → evaluator}/LlamaModel.d.ts +24 -6
  147. package/dist/{llamaEvaluator → evaluator}/LlamaModel.js +51 -12
  148. package/dist/evaluator/LlamaModel.js.map +1 -0
  149. package/dist/index.d.ts +30 -17
  150. package/dist/index.js +29 -15
  151. package/dist/index.js.map +1 -1
  152. package/dist/state.d.ts +2 -0
  153. package/dist/state.js +7 -0
  154. package/dist/state.js.map +1 -1
  155. package/dist/types.d.ts +72 -3
  156. package/dist/types.js +5 -1
  157. package/dist/types.js.map +1 -1
  158. package/dist/utils/LlamaText.d.ts +42 -0
  159. package/dist/utils/LlamaText.js +207 -0
  160. package/dist/utils/LlamaText.js.map +1 -0
  161. package/dist/utils/StopGenerationDetector.d.ts +28 -0
  162. package/dist/utils/StopGenerationDetector.js +205 -0
  163. package/dist/utils/StopGenerationDetector.js.map +1 -0
  164. package/dist/utils/TokenStreamRegulator.d.ts +30 -0
  165. package/dist/utils/TokenStreamRegulator.js +96 -0
  166. package/dist/utils/TokenStreamRegulator.js.map +1 -0
  167. package/dist/utils/UnsupportedError.d.ts +2 -0
  168. package/dist/utils/UnsupportedError.js +7 -0
  169. package/dist/utils/UnsupportedError.js.map +1 -0
  170. package/dist/utils/appendUserMessageToChatHistory.d.ts +2 -0
  171. package/dist/utils/appendUserMessageToChatHistory.js +18 -0
  172. package/dist/utils/appendUserMessageToChatHistory.js.map +1 -0
  173. package/dist/utils/cmake.js +16 -11
  174. package/dist/utils/cmake.js.map +1 -1
  175. package/dist/utils/compareTokens.d.ts +2 -0
  176. package/dist/utils/compareTokens.js +4 -0
  177. package/dist/utils/compareTokens.js.map +1 -0
  178. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +18 -0
  179. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +61 -0
  180. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -0
  181. package/dist/utils/gbnfJson/GbnfGrammarGenerator.d.ts +1 -0
  182. package/dist/utils/gbnfJson/GbnfGrammarGenerator.js +17 -0
  183. package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -1
  184. package/dist/utils/gbnfJson/GbnfTerminal.d.ts +1 -1
  185. package/dist/utils/gbnfJson/GbnfTerminal.js.map +1 -1
  186. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.d.ts +6 -0
  187. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js +21 -0
  188. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -0
  189. package/dist/utils/gbnfJson/types.d.ts +1 -1
  190. package/dist/utils/gbnfJson/types.js.map +1 -1
  191. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.d.ts +1 -0
  192. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -1
  193. package/dist/utils/getConsoleLogPrefix.d.ts +1 -0
  194. package/dist/utils/getConsoleLogPrefix.js +9 -0
  195. package/dist/utils/getConsoleLogPrefix.js.map +1 -0
  196. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js +1 -15
  197. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js.map +1 -1
  198. package/dist/utils/getGrammarsFolder.d.ts +2 -1
  199. package/dist/utils/getGrammarsFolder.js +8 -7
  200. package/dist/utils/getGrammarsFolder.js.map +1 -1
  201. package/dist/utils/getModuleVersion.d.ts +1 -0
  202. package/dist/utils/getModuleVersion.js +13 -0
  203. package/dist/utils/getModuleVersion.js.map +1 -0
  204. package/dist/utils/getQueuedTokensBeforeStopTrigger.d.ts +6 -0
  205. package/dist/utils/getQueuedTokensBeforeStopTrigger.js +22 -0
  206. package/dist/utils/getQueuedTokensBeforeStopTrigger.js.map +1 -0
  207. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.d.ts +2 -0
  208. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +49 -0
  209. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -0
  210. package/dist/utils/gitReleaseBundles.js +6 -5
  211. package/dist/utils/gitReleaseBundles.js.map +1 -1
  212. package/dist/utils/hashString.d.ts +1 -0
  213. package/dist/utils/hashString.js +8 -0
  214. package/dist/utils/hashString.js.map +1 -0
  215. package/dist/utils/isLockfileActive.d.ts +4 -0
  216. package/dist/utils/isLockfileActive.js +12 -0
  217. package/dist/utils/isLockfileActive.js.map +1 -0
  218. package/dist/utils/parseModelTypeDescription.d.ts +1 -1
  219. package/dist/utils/prettyPrintObject.d.ts +1 -0
  220. package/dist/utils/prettyPrintObject.js +40 -0
  221. package/dist/utils/prettyPrintObject.js.map +1 -0
  222. package/dist/utils/removeNullFields.d.ts +1 -0
  223. package/dist/utils/removeNullFields.js +8 -0
  224. package/dist/utils/removeNullFields.js.map +1 -1
  225. package/dist/utils/resolveChatWrapper.d.ts +4 -0
  226. package/dist/utils/resolveChatWrapper.js +16 -0
  227. package/dist/utils/resolveChatWrapper.js.map +1 -0
  228. package/dist/utils/resolveGithubRelease.d.ts +2 -0
  229. package/dist/utils/resolveGithubRelease.js +36 -0
  230. package/dist/utils/resolveGithubRelease.js.map +1 -0
  231. package/dist/utils/spawnCommand.d.ts +1 -1
  232. package/dist/utils/spawnCommand.js +4 -2
  233. package/dist/utils/spawnCommand.js.map +1 -1
  234. package/dist/utils/tokenizeInput.d.ts +3 -0
  235. package/dist/utils/tokenizeInput.js +9 -0
  236. package/dist/utils/tokenizeInput.js.map +1 -0
  237. package/dist/utils/truncateTextAndRoundToWords.d.ts +8 -0
  238. package/dist/utils/truncateTextAndRoundToWords.js +27 -0
  239. package/dist/utils/truncateTextAndRoundToWords.js.map +1 -0
  240. package/dist/utils/waitForLockfileRelease.d.ts +5 -0
  241. package/dist/utils/waitForLockfileRelease.js +20 -0
  242. package/dist/utils/waitForLockfileRelease.js.map +1 -0
  243. package/dist/utils/withLockfile.d.ts +7 -0
  244. package/dist/utils/withLockfile.js +44 -0
  245. package/dist/utils/withLockfile.js.map +1 -0
  246. package/dist/utils/withOra.js +11 -1
  247. package/dist/utils/withOra.js.map +1 -1
  248. package/dist/utils/withStatusLogs.d.ts +2 -1
  249. package/dist/utils/withStatusLogs.js +11 -8
  250. package/dist/utils/withStatusLogs.js.map +1 -1
  251. package/llama/.clang-format +1 -2
  252. package/llama/CMakeLists.txt +87 -2
  253. package/llama/addon.cpp +319 -31
  254. package/llama/binariesGithubRelease.json +1 -1
  255. package/llama/gitRelease.bundle +0 -0
  256. package/llama/gpuInfo/cuda-gpu-info.cu +99 -0
  257. package/llama/gpuInfo/cuda-gpu-info.h +7 -0
  258. package/llama/gpuInfo/metal-gpu-info.h +5 -0
  259. package/llama/gpuInfo/metal-gpu-info.mm +17 -0
  260. package/llama/llama.cpp.info.json +4 -0
  261. package/llamaBins/linux-arm64/.buildMetadata.json +1 -0
  262. package/llamaBins/linux-arm64/llama-addon.node +0 -0
  263. package/llamaBins/linux-armv7l/.buildMetadata.json +1 -0
  264. package/llamaBins/linux-armv7l/llama-addon.node +0 -0
  265. package/llamaBins/linux-x64/.buildMetadata.json +1 -0
  266. package/llamaBins/linux-x64/llama-addon.node +0 -0
  267. package/llamaBins/linux-x64-cuda/.buildMetadata.json +1 -0
  268. package/llamaBins/linux-x64-cuda/llama-addon.node +0 -0
  269. package/llamaBins/mac-arm64-metal/.buildMetadata.json +1 -0
  270. package/llamaBins/mac-arm64-metal/ggml-metal.metal +6491 -0
  271. package/llamaBins/mac-arm64-metal/llama-addon.node +0 -0
  272. package/llamaBins/mac-x64/.buildMetadata.json +1 -0
  273. package/llamaBins/mac-x64/llama-addon.node +0 -0
  274. package/llamaBins/win-x64/.buildMetadata.json +1 -0
  275. package/llamaBins/win-x64/llama-addon.exp +0 -0
  276. package/llamaBins/win-x64/llama-addon.node +0 -0
  277. package/llamaBins/win-x64-cuda/.buildMetadata.json +1 -0
  278. package/llamaBins/win-x64-cuda/llama-addon.exp +0 -0
  279. package/llamaBins/win-x64-cuda/llama-addon.lib +0 -0
  280. package/llamaBins/win-x64-cuda/llama-addon.node +0 -0
  281. package/package.json +37 -15
  282. package/dist/AbortError.d.ts +0 -2
  283. package/dist/AbortError.js +0 -7
  284. package/dist/AbortError.js.map +0 -1
  285. package/dist/ChatPromptWrapper.d.ts +0 -11
  286. package/dist/ChatPromptWrapper.js +0 -20
  287. package/dist/ChatPromptWrapper.js.map +0 -1
  288. package/dist/chatWrappers/ChatMLChatPromptWrapper.d.ts +0 -12
  289. package/dist/chatWrappers/ChatMLChatPromptWrapper.js +0 -22
  290. package/dist/chatWrappers/ChatMLChatPromptWrapper.js.map +0 -1
  291. package/dist/chatWrappers/EmptyChatPromptWrapper.d.ts +0 -4
  292. package/dist/chatWrappers/EmptyChatPromptWrapper.js +0 -5
  293. package/dist/chatWrappers/EmptyChatPromptWrapper.js.map +0 -1
  294. package/dist/chatWrappers/FalconChatPromptWrapper.d.ts +0 -19
  295. package/dist/chatWrappers/FalconChatPromptWrapper.js +0 -33
  296. package/dist/chatWrappers/FalconChatPromptWrapper.js.map +0 -1
  297. package/dist/chatWrappers/GeneralChatPromptWrapper.d.ts +0 -19
  298. package/dist/chatWrappers/GeneralChatPromptWrapper.js +0 -38
  299. package/dist/chatWrappers/GeneralChatPromptWrapper.js.map +0 -1
  300. package/dist/chatWrappers/LlamaChatPromptWrapper.d.ts +0 -12
  301. package/dist/chatWrappers/LlamaChatPromptWrapper.js +0 -23
  302. package/dist/chatWrappers/LlamaChatPromptWrapper.js.map +0 -1
  303. package/dist/chatWrappers/generateContextTextFromConversationHistory.d.ts +0 -15
  304. package/dist/chatWrappers/generateContextTextFromConversationHistory.js +0 -39
  305. package/dist/chatWrappers/generateContextTextFromConversationHistory.js.map +0 -1
  306. package/dist/llamaEvaluator/LlamaBins.d.ts +0 -19
  307. package/dist/llamaEvaluator/LlamaBins.js +0 -5
  308. package/dist/llamaEvaluator/LlamaBins.js.map +0 -1
  309. package/dist/llamaEvaluator/LlamaChatSession.js +0 -290
  310. package/dist/llamaEvaluator/LlamaChatSession.js.map +0 -1
  311. package/dist/llamaEvaluator/LlamaContext/LlamaContext.js.map +0 -1
  312. package/dist/llamaEvaluator/LlamaContext/types.js.map +0 -1
  313. package/dist/llamaEvaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js.map +0 -1
  314. package/dist/llamaEvaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js.map +0 -1
  315. package/dist/llamaEvaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js.map +0 -1
  316. package/dist/llamaEvaluator/LlamaGrammar.d.ts +0 -32
  317. package/dist/llamaEvaluator/LlamaGrammar.js.map +0 -1
  318. package/dist/llamaEvaluator/LlamaGrammarEvaluationState.js.map +0 -1
  319. package/dist/llamaEvaluator/LlamaJsonSchemaGrammar.js.map +0 -1
  320. package/dist/llamaEvaluator/LlamaModel.js.map +0 -1
  321. package/dist/utils/binariesGithubRelease.js.map +0 -1
  322. package/dist/utils/clearLlamaBuild.d.ts +0 -1
  323. package/dist/utils/clearLlamaBuild.js +0 -12
  324. package/dist/utils/clearLlamaBuild.js.map +0 -1
  325. package/dist/utils/cloneLlamaCppRepo.d.ts +0 -2
  326. package/dist/utils/cloneLlamaCppRepo.js +0 -102
  327. package/dist/utils/cloneLlamaCppRepo.js.map +0 -1
  328. package/dist/utils/compileLLamaCpp.d.ts +0 -8
  329. package/dist/utils/compileLLamaCpp.js +0 -127
  330. package/dist/utils/compileLLamaCpp.js.map +0 -1
  331. package/dist/utils/getBin.js +0 -78
  332. package/dist/utils/getBin.js.map +0 -1
  333. package/dist/utils/getReleaseInfo.d.ts +0 -7
  334. package/dist/utils/getReleaseInfo.js +0 -30
  335. package/dist/utils/getReleaseInfo.js.map +0 -1
  336. package/dist/utils/getTextCompletion.d.ts +0 -3
  337. package/dist/utils/getTextCompletion.js +0 -12
  338. package/dist/utils/getTextCompletion.js.map +0 -1
  339. package/dist/utils/usedBinFlag.d.ts +0 -6
  340. package/dist/utils/usedBinFlag.js +0 -15
  341. package/dist/utils/usedBinFlag.js.map +0 -1
  342. package/llama/usedBin.json +0 -3
  343. package/llamaBins/mac-arm64/ggml-metal.metal +0 -2929
  344. package/llamaBins/mac-arm64/llama-addon.node +0 -0
  345. package/llamaBins/mac-x64/ggml-metal.metal +0 -2929
  346. /package/dist/{utils → bindings/utils}/binariesGithubRelease.d.ts +0 -0
  347. /package/dist/{llamaEvaluator → evaluator}/LlamaContext/types.js +0 -0
  348. /package/dist/{llamaEvaluator → evaluator}/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.d.ts +0 -0
  349. /package/dist/{llamaEvaluator → evaluator}/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js +0 -0
  350. /package/dist/{llamaEvaluator → evaluator}/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.d.ts +0 -0
  351. /package/dist/{llamaEvaluator → evaluator}/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js +0 -0
  352. /package/dist/{llamaEvaluator → evaluator}/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.d.ts +0 -0
  353. /package/dist/{llamaEvaluator → evaluator}/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js +0 -0
  354. /package/dist/{llamaEvaluator → evaluator}/LlamaGrammarEvaluationState.d.ts +0 -0
@@ -0,0 +1,219 @@
1
+ import { DisposeAggregator, DisposedError, EventRelay, withLock } from "lifecycle-utils";
2
+ import { defaultChatSystemPrompt } from "../../config.js";
3
+ import { appendUserMessageToChatHistory } from "../../utils/appendUserMessageToChatHistory.js";
4
+ import { LlamaChat } from "../LlamaChat/LlamaChat.js";
5
+ export class LlamaChatSession {
6
+ /** @internal */ _disposeAggregator = new DisposeAggregator();
7
+ /** @internal */ _autoDisposeSequence;
8
+ /** @internal */ _contextShift;
9
+ /** @internal */ _chatHistory;
10
+ /** @internal */ _lastEvaluation;
11
+ /** @internal */ _chat;
12
+ onDispose = new EventRelay();
13
+ /**
14
+ * @param options
15
+ */
16
+ constructor({ contextSequence, chatWrapper = "auto", systemPrompt = defaultChatSystemPrompt, autoDisposeSequence = true, contextShift }) {
17
+ if (contextSequence == null)
18
+ throw new Error("contextSequence cannot be null");
19
+ if (contextSequence.disposed)
20
+ throw new DisposedError();
21
+ this._contextShift = contextShift;
22
+ this._chatHistory = [{
23
+ type: "system",
24
+ text: systemPrompt
25
+ }];
26
+ this._chat = new LlamaChat({
27
+ autoDisposeSequence,
28
+ chatWrapper,
29
+ contextSequence
30
+ });
31
+ this._autoDisposeSequence = autoDisposeSequence;
32
+ this._disposeAggregator.add(this._chat.onDispose.createListener(() => {
33
+ this.dispose();
34
+ }));
35
+ this._disposeAggregator.add(this.onDispose.dispatchEvent);
36
+ }
37
+ dispose({ disposeSequence = this._autoDisposeSequence } = {}) {
38
+ if (this._chat == null)
39
+ return;
40
+ this._chat.dispose({ disposeSequence });
41
+ this._chat = null;
42
+ this._disposeAggregator.dispose();
43
+ }
44
+ /** @hidden */
45
+ [Symbol.dispose]() {
46
+ return this.dispose();
47
+ }
48
+ get disposed() {
49
+ return this._chat == null || this._chat.disposed;
50
+ }
51
+ get chatWrapper() {
52
+ if (this._chat == null)
53
+ throw new DisposedError();
54
+ return this._chat.chatWrapper;
55
+ }
56
+ get sequence() {
57
+ if (this._chat == null)
58
+ throw new DisposedError();
59
+ return this._chat.sequence;
60
+ }
61
+ get context() {
62
+ return this.sequence.context;
63
+ }
64
+ get model() {
65
+ return this.sequence.model;
66
+ }
67
+ /**
68
+ * @param prompt
69
+ * @param [options]
70
+ */
71
+ async prompt(prompt, { functions, documentFunctionParams, onToken, signal, maxTokens, temperature, minP, topK, topP, grammar, trimWhitespaceSuffix = false, repeatPenalty } = {}) {
72
+ const { responseText } = await this.promptWithMeta(prompt, {
73
+ // this is a workaround to allow passing both `functions` and `grammar`
74
+ functions: functions,
75
+ documentFunctionParams: documentFunctionParams,
76
+ onToken, signal, maxTokens, temperature, minP, topK, topP, grammar, trimWhitespaceSuffix, repeatPenalty
77
+ });
78
+ return responseText;
79
+ }
80
+ /**
81
+ * @param prompt
82
+ * @param [options]
83
+ */
84
+ async promptWithMeta(prompt, { functions, documentFunctionParams, onToken, signal, maxTokens, temperature, minP, topK, topP, grammar, trimWhitespaceSuffix = false, repeatPenalty, evaluationPriority } = {}) {
85
+ this._ensureNotDisposed();
86
+ if (grammar != null && grammar._llama !== this.model._llama)
87
+ throw new Error("The LlamaGrammar used by passed to this function was created with a different Llama instance than the one used by this sequence's model. Make sure you use the same Llama instance for both the model and the grammar.");
88
+ return await withLock(this, "prompt", signal, async () => {
89
+ this._ensureNotDisposed();
90
+ if (this._chat == null)
91
+ throw new DisposedError();
92
+ let lastEvaluation = this._lastEvaluation;
93
+ let newChatHistory = appendUserMessageToChatHistory(this._chatHistory, prompt);
94
+ let newContextWindowChatHistory = lastEvaluation?.contextWindow == null
95
+ ? undefined
96
+ : appendUserMessageToChatHistory(lastEvaluation?.contextWindow, prompt);
97
+ newChatHistory.push({
98
+ type: "model",
99
+ response: []
100
+ });
101
+ if (newContextWindowChatHistory != null)
102
+ newContextWindowChatHistory.push({
103
+ type: "model",
104
+ response: []
105
+ });
106
+ // eslint-disable-next-line no-constant-condition
107
+ while (true) {
108
+ const { functionCall, lastEvaluation: currentLastEvaluation, metadata } = await this._chat.generateResponse(newChatHistory, {
109
+ functions,
110
+ documentFunctionParams,
111
+ grammar: grammar,
112
+ onToken,
113
+ signal,
114
+ repeatPenalty,
115
+ minP,
116
+ topK,
117
+ topP,
118
+ maxTokens,
119
+ temperature,
120
+ trimWhitespaceSuffix,
121
+ contextShift: {
122
+ ...this._contextShift,
123
+ lastEvaluationMetadata: lastEvaluation?.contextShiftMetadata
124
+ },
125
+ evaluationPriority,
126
+ lastEvaluationContextWindow: {
127
+ history: newContextWindowChatHistory,
128
+ minimumOverlapPercentageToPreventContextShift: 0.01
129
+ }
130
+ });
131
+ this._ensureNotDisposed();
132
+ lastEvaluation = currentLastEvaluation;
133
+ newChatHistory = lastEvaluation.cleanHistory;
134
+ if (functionCall != null) {
135
+ const functionDefinition = functions?.[functionCall.functionName];
136
+ if (functionDefinition == null)
137
+ throw new Error(`The model tried to call function "${functionCall.functionName}" which is not defined`);
138
+ const functionCallResult = await functionDefinition.handler(functionCall.params);
139
+ this._ensureNotDisposed();
140
+ newChatHistory = addFunctionCallToChatHistory({
141
+ chatHistory: newChatHistory,
142
+ functionName: functionCall.functionName,
143
+ functionDescription: functionDefinition.description,
144
+ callParams: functionCall.params,
145
+ callResult: functionCallResult,
146
+ raw: functionCall.raw + this._chat.chatWrapper.generateFunctionCallResult(functionCall.functionName, functionCall.params, functionCallResult)
147
+ });
148
+ newContextWindowChatHistory = addFunctionCallToChatHistory({
149
+ chatHistory: lastEvaluation.contextWindow,
150
+ functionName: functionCall.functionName,
151
+ functionDescription: functionDefinition.description,
152
+ callParams: functionCall.params,
153
+ callResult: functionCallResult,
154
+ raw: functionCall.raw + this._chat.chatWrapper.generateFunctionCallResult(functionCall.functionName, functionCall.params, functionCallResult)
155
+ });
156
+ lastEvaluation.cleanHistory = newChatHistory;
157
+ lastEvaluation.contextWindow = newContextWindowChatHistory;
158
+ continue;
159
+ }
160
+ this._lastEvaluation = lastEvaluation;
161
+ this._chatHistory = newChatHistory;
162
+ const lastModelResponseItem = getLastModelResponseItem(newChatHistory);
163
+ return {
164
+ response: lastModelResponseItem.response,
165
+ responseText: lastModelResponseItem.response
166
+ .filter((item) => typeof item === "string")
167
+ .join(""),
168
+ stopReason: metadata.stopReason,
169
+ remainingGenerationAfterStop: metadata.remainingGenerationAfterStop
170
+ };
171
+ }
172
+ });
173
+ }
174
+ getChatHistory() {
175
+ return structuredClone(this._chatHistory);
176
+ }
177
+ getLastEvaluationContextWindow() {
178
+ if (this._lastEvaluation == null)
179
+ return null;
180
+ return structuredClone(this._lastEvaluation?.contextWindow);
181
+ }
182
+ setChatHistory(chatHistory) {
183
+ this._chatHistory = structuredClone(chatHistory);
184
+ this._lastEvaluation = undefined;
185
+ }
186
+ /** @internal */
187
+ _ensureNotDisposed() {
188
+ if (this.disposed)
189
+ throw new DisposedError();
190
+ }
191
+ }
192
+ function addFunctionCallToChatHistory({ chatHistory, functionName, functionDescription, callParams, callResult, raw }) {
193
+ const newChatHistory = chatHistory.slice();
194
+ if (newChatHistory.length === 0 || newChatHistory[newChatHistory.length - 1].type !== "model")
195
+ newChatHistory.push({
196
+ type: "model",
197
+ response: []
198
+ });
199
+ const lastModelResponseItem = newChatHistory[newChatHistory.length - 1];
200
+ const newLastModelResponseItem = { ...lastModelResponseItem };
201
+ newChatHistory[newChatHistory.length - 1] = newLastModelResponseItem;
202
+ const modelResponse = newLastModelResponseItem.response.slice();
203
+ newLastModelResponseItem.response = modelResponse;
204
+ modelResponse.push({
205
+ type: "functionCall",
206
+ name: functionName,
207
+ description: functionDescription,
208
+ params: callParams,
209
+ result: callResult,
210
+ raw
211
+ });
212
+ return newChatHistory;
213
+ }
214
+ function getLastModelResponseItem(chatHistory) {
215
+ if (chatHistory.length === 0 || chatHistory[chatHistory.length - 1].type !== "model")
216
+ throw new Error("Expected chat history to end with a model response");
217
+ return chatHistory[chatHistory.length - 1];
218
+ }
219
+ //# sourceMappingURL=LlamaChatSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LlamaChatSession.js","sourceRoot":"","sources":["../../../src/evaluator/LlamaChatSession/LlamaChatSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAC,uBAAuB,EAAC,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAC,8BAA8B,EAAC,MAAM,+CAA+C,CAAC;AAG7F,OAAO,EAAC,SAAS,EAAkD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B,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAChE,wBAAwB,CAAC,QAAQ,GAAG,aAAa,CAAC;IAElD,aAAa,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,YAAY;QAClB,WAAW,EAAE,mBAAmB;QAChC,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,UAAU;QAClB,GAAG;KACN,CAAC,CAAC;IAEH,OAAO,cAAc,CAAC;AAC1B,CAAC;AAED,SAAS,wBAAwB,CAAC,WAA8B;IAC5D,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO;QAChF,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IAE1E,OAAO,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAsB,CAAC;AACpE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { GbnfJsonSchema, GbnfJsonSchemaToType } from "../../../utils/gbnfJson/types.js";
2
+ import { ChatSessionModelFunction } from "../../../types.js";
3
+ export declare function defineChatSessionFunction<const Params extends GbnfJsonSchema | undefined>({ description, params, handler }: {
4
+ description?: string;
5
+ params?: Params;
6
+ handler: (params: GbnfJsonSchemaToType<Params>) => any;
7
+ }): ChatSessionModelFunction<Params>;
@@ -0,0 +1,8 @@
1
+ export function defineChatSessionFunction({ description, params, handler }) {
2
+ return {
3
+ description,
4
+ params,
5
+ handler
6
+ };
7
+ }
8
+ //# sourceMappingURL=defineChatSessionFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineChatSessionFunction.js","sourceRoot":"","sources":["../../../../src/evaluator/LlamaChatSession/utils/defineChatSessionFunction.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,yBAAyB,CAAkD,EACvF,WAAW,EACX,MAAM,EACN,OAAO,EAKV;IACG,OAAO;QACH,WAAW;QACX,MAAM;QACN,OAAO;KACV,CAAC;AACN,CAAC"}
@@ -0,0 +1,148 @@
1
+ /// <reference types="node" />
2
+ import { EventRelay } from "lifecycle-utils";
3
+ import { LLamaContextualRepeatPenalty, Token } from "../types.js";
4
+ import { LlamaText } from "../utils/LlamaText.js";
5
+ import { StopGenerationTrigger } from "../utils/StopGenerationDetector.js";
6
+ import { LlamaGrammar } from "./LlamaGrammar.js";
7
+ import { EvaluationPriority } from "./LlamaContext/types.js";
8
+ import { LlamaContextSequence } from "./LlamaContext/LlamaContext.js";
9
+ export type LlamaCompletionOptions = {
10
+ contextSequence: LlamaContextSequence;
11
+ /** Automatically dispose the sequence when the object is disposed */
12
+ autoDisposeSequence?: boolean;
13
+ };
14
+ export type LlamaCompletionGenerationOptions = {
15
+ onToken?: (tokens: Token[]) => void;
16
+ signal?: AbortSignal;
17
+ maxTokens?: number;
18
+ /**
19
+ * Temperature is a hyperparameter that controls the randomness of the generated text.
20
+ * It affects the probability distribution of the model's output tokens.
21
+ * A higher temperature (e.g., 1.5) makes the output more random and creative,
22
+ * while a lower temperature (e.g., 0.5) makes the output more focused, deterministic, and conservative.
23
+ * The suggested temperature is 0.8, which provides a balance between randomness and determinism.
24
+ * At the extreme, a temperature of 0 will always pick the most likely next token, leading to identical outputs in each run.
25
+ *
26
+ * Set to `0` to disable.
27
+ * Disabled by default (set to `0`).
28
+ */
29
+ temperature?: number;
30
+ /**
31
+ * From the next token candidates, discard the percentage of tokens with the lowest probability.
32
+ * For example, if set to `0.05`, 5% of the lowest probability tokens will be discarded.
33
+ * This is useful for generating more high-quality results when using a high temperature.
34
+ * Set to a value between `0` and `1` to enable.
35
+ *
36
+ * Only relevant when `temperature` is set to a value greater than `0`.
37
+ * Disabled by default.
38
+ */
39
+ minP?: number;
40
+ /**
41
+ * Limits the model to consider only the K most likely next tokens for sampling at each step of sequence generation.
42
+ * An integer number between `1` and the size of the vocabulary.
43
+ * Set to `0` to disable (which uses the full vocabulary).
44
+ *
45
+ * Only relevant when `temperature` is set to a value greater than 0.
46
+ */
47
+ topK?: number;
48
+ /**
49
+ * Dynamically selects the smallest set of tokens whose cumulative probability exceeds the threshold P,
50
+ * and samples the next token only from this set.
51
+ * A float number between `0` and `1`.
52
+ * Set to `1` to disable.
53
+ *
54
+ * Only relevant when `temperature` is set to a value greater than `0`.
55
+ */
56
+ topP?: number;
57
+ /**
58
+ * Trim whitespace from the end of the generated text
59
+ * Disabled by default.
60
+ */
61
+ trimWhitespaceSuffix?: boolean;
62
+ repeatPenalty?: false | LLamaContextualRepeatPenalty;
63
+ /**
64
+ * See the parameter `evaluationPriority` on the `LlamaContextSequence.evaluate()` function for more information.
65
+ */
66
+ evaluationPriority?: EvaluationPriority;
67
+ grammar?: LlamaGrammar;
68
+ /** Consider any of these as EOS for the generated text */
69
+ stopGenerationTriggers?: readonly (StopGenerationTrigger | LlamaText)[];
70
+ /**
71
+ * The number of tokens to delete from the context window to make space for new ones.
72
+ * Defaults to 10% of the context size.
73
+ */
74
+ contextShiftSize?: number | ((sequence: LlamaContextSequence) => number | Promise<number>);
75
+ /**
76
+ * Context shift reconstructs the context with partial relevant data to continue generation when the context fills up.
77
+ * This flag disables this behavior.
78
+ * This flag will cause the generation to stop when the context fills up
79
+ * by setting an appropriate `maxTokens` value or lowering the given `maxTokens` value when needed.
80
+ * This flag will cause the generation to fail if there's no space for generating new tokens at all with the given inputs.
81
+ *
82
+ * Disabled by default. Not recommended unless you know what you're doing.
83
+ */
84
+ disableContextShift?: boolean;
85
+ };
86
+ export type LlamaInfillGenerationOptions = LlamaCompletionGenerationOptions & {
87
+ /**
88
+ * The minimum number of tokens to keep from the prefix input when making a context shift.
89
+ * Defaults to 10% of the context size.
90
+ */
91
+ minPrefixKeepTokens?: number | ((sequence: LlamaContextSequence) => number | Promise<number>);
92
+ };
93
+ export declare class LlamaCompletion {
94
+ readonly onDispose: EventRelay<void>;
95
+ constructor({ contextSequence, autoDisposeSequence }: LlamaCompletionOptions);
96
+ dispose({ disposeSequence }?: {
97
+ disposeSequence?: boolean;
98
+ }): void;
99
+ /** @hidden */
100
+ [Symbol.dispose](): void;
101
+ get disposed(): boolean;
102
+ get infillSupported(): boolean;
103
+ /**
104
+ * Generate a completion for an input.
105
+ */
106
+ generateCompletion(input: Token[] | string | LlamaText, options?: LlamaCompletionGenerationOptions): Promise<string>;
107
+ /**
108
+ * Same as `generateCompletion`, but returns additional metadata about the generation.
109
+ * See `generateCompletion` for more information.
110
+ */
111
+ generateCompletionWithMeta(input: Token[] | string | LlamaText, { onToken, signal, maxTokens, temperature, minP, topK, topP, trimWhitespaceSuffix, repeatPenalty, evaluationPriority, grammar, stopGenerationTriggers, contextShiftSize, disableContextShift }?: LlamaCompletionGenerationOptions): Promise<{
112
+ response: string;
113
+ metadata: {
114
+ remainingGenerationAfterStop: string | Token[];
115
+ stopReason: "eosToken" | "stopGenerationTrigger";
116
+ };
117
+ } | {
118
+ response: string;
119
+ metadata: {
120
+ stopReason: "maxTokens";
121
+ remainingGenerationAfterStop?: undefined;
122
+ };
123
+ }>;
124
+ /**
125
+ * Infill (also known as Fill-In-Middle), generates a completion for an input (`prefixInput`) that
126
+ * should connect to a given continuation (`suffixInput`).
127
+ * For example, for `prefixInput: "123"` and `suffixInput: "789"`, the model is expected to generate `456`
128
+ * to make the final text be `123456789`.
129
+ */
130
+ generateInfillCompletion(prefixInput: Token[] | string | LlamaText, suffixInput: Token[] | string | LlamaText, options?: LlamaInfillGenerationOptions): Promise<string>;
131
+ /**
132
+ * Same as `generateInfillCompletion`, but returns additional metadata about the generation.
133
+ * See `generateInfillCompletion` for more information.
134
+ */
135
+ generateInfillCompletionWithMeta(prefixInput: Token[] | string | LlamaText, suffixInput: Token[] | string | LlamaText, { onToken, signal, maxTokens, temperature, minP, topK, topP, trimWhitespaceSuffix, repeatPenalty, evaluationPriority, grammar, contextShiftSize, stopGenerationTriggers, minPrefixKeepTokens, disableContextShift }?: LlamaInfillGenerationOptions): Promise<{
136
+ response: string;
137
+ metadata: {
138
+ remainingGenerationAfterStop: string | Token[];
139
+ stopReason: "eosToken" | "stopGenerationTrigger";
140
+ };
141
+ } | {
142
+ response: string;
143
+ metadata: {
144
+ stopReason: "maxTokens";
145
+ remainingGenerationAfterStop?: undefined;
146
+ };
147
+ }>;
148
+ }