@trymirai/uzu 0.3.1 → 0.4.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 (455) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +253 -245
  3. package/index.d.mts +1 -43
  4. package/index.d.mts.map +1 -1
  5. package/index.d.ts +1 -43
  6. package/index.d.ts.map +1 -1
  7. package/index.js +2 -88
  8. package/index.js.map +1 -1
  9. package/index.mjs +1 -43
  10. package/index.mjs.map +1 -1
  11. package/internal/tslib.js +6 -33
  12. package/napi/index.d.ts +975 -0
  13. package/napi/index.js +626 -0
  14. package/napi/index.mjs +3 -0
  15. package/napi/{uzu.node → uzu.darwin-arm64.node} +0 -0
  16. package/package.json +26 -63
  17. package/src/index.ts +1 -43
  18. package/src/napi/index.d.ts +975 -0
  19. package/src/napi/index.js +626 -0
  20. package/src/napi/index.mjs +3 -0
  21. package/src/napi/{uzu.node → uzu.darwin-arm64.node} +0 -0
  22. package/src/version.ts +1 -1
  23. package/version.d.mts +1 -1
  24. package/version.d.ts +1 -1
  25. package/version.js +1 -1
  26. package/version.mjs +1 -1
  27. package/bridging/asyncBatchSize.d.mts +0 -10
  28. package/bridging/asyncBatchSize.d.mts.map +0 -1
  29. package/bridging/asyncBatchSize.d.ts +0 -10
  30. package/bridging/asyncBatchSize.d.ts.map +0 -1
  31. package/bridging/asyncBatchSize.js +0 -21
  32. package/bridging/asyncBatchSize.js.map +0 -1
  33. package/bridging/asyncBatchSize.mjs +0 -17
  34. package/bridging/asyncBatchSize.mjs.map +0 -1
  35. package/bridging/chatSession.d.mts +0 -11
  36. package/bridging/chatSession.d.mts.map +0 -1
  37. package/bridging/chatSession.d.ts +0 -11
  38. package/bridging/chatSession.d.ts.map +0 -1
  39. package/bridging/chatSession.js +0 -22
  40. package/bridging/chatSession.js.map +0 -1
  41. package/bridging/chatSession.mjs +0 -18
  42. package/bridging/chatSession.mjs.map +0 -1
  43. package/bridging/classificationFeature.d.mts +0 -9
  44. package/bridging/classificationFeature.d.mts.map +0 -1
  45. package/bridging/classificationFeature.d.ts +0 -9
  46. package/bridging/classificationFeature.d.ts.map +0 -1
  47. package/bridging/classificationFeature.js +0 -18
  48. package/bridging/classificationFeature.js.map +0 -1
  49. package/bridging/classificationFeature.mjs +0 -14
  50. package/bridging/classificationFeature.mjs.map +0 -1
  51. package/bridging/classificationLabel.d.mts +0 -12
  52. package/bridging/classificationLabel.d.mts.map +0 -1
  53. package/bridging/classificationLabel.d.ts +0 -12
  54. package/bridging/classificationLabel.d.ts.map +0 -1
  55. package/bridging/classificationLabel.js +0 -26
  56. package/bridging/classificationLabel.js.map +0 -1
  57. package/bridging/classificationLabel.mjs +0 -22
  58. package/bridging/classificationLabel.mjs.map +0 -1
  59. package/bridging/classificationOutput.d.mts +0 -10
  60. package/bridging/classificationOutput.d.mts.map +0 -1
  61. package/bridging/classificationOutput.d.ts +0 -10
  62. package/bridging/classificationOutput.d.ts.map +0 -1
  63. package/bridging/classificationOutput.js +0 -16
  64. package/bridging/classificationOutput.js.map +0 -1
  65. package/bridging/classificationOutput.mjs +0 -12
  66. package/bridging/classificationOutput.mjs.map +0 -1
  67. package/bridging/classificationSession.d.mts +0 -9
  68. package/bridging/classificationSession.d.mts.map +0 -1
  69. package/bridging/classificationSession.d.ts +0 -9
  70. package/bridging/classificationSession.d.ts.map +0 -1
  71. package/bridging/classificationSession.js +0 -16
  72. package/bridging/classificationSession.js.map +0 -1
  73. package/bridging/classificationSession.mjs +0 -12
  74. package/bridging/classificationSession.mjs.map +0 -1
  75. package/bridging/classificationStats.d.mts +0 -14
  76. package/bridging/classificationStats.d.mts.map +0 -1
  77. package/bridging/classificationStats.d.ts +0 -14
  78. package/bridging/classificationStats.d.ts.map +0 -1
  79. package/bridging/classificationStats.js +0 -20
  80. package/bridging/classificationStats.js.map +0 -1
  81. package/bridging/classificationStats.mjs +0 -16
  82. package/bridging/classificationStats.mjs.map +0 -1
  83. package/bridging/config.d.mts +0 -26
  84. package/bridging/config.d.mts.map +0 -1
  85. package/bridging/config.d.ts +0 -26
  86. package/bridging/config.d.ts.map +0 -1
  87. package/bridging/config.js +0 -53
  88. package/bridging/config.js.map +0 -1
  89. package/bridging/config.mjs +0 -49
  90. package/bridging/config.mjs.map +0 -1
  91. package/bridging/contextLength.d.mts +0 -11
  92. package/bridging/contextLength.d.mts.map +0 -1
  93. package/bridging/contextLength.d.ts +0 -11
  94. package/bridging/contextLength.d.ts.map +0 -1
  95. package/bridging/contextLength.js +0 -25
  96. package/bridging/contextLength.js.map +0 -1
  97. package/bridging/contextLength.mjs +0 -21
  98. package/bridging/contextLength.mjs.map +0 -1
  99. package/bridging/contextMode.d.mts +0 -12
  100. package/bridging/contextMode.d.mts.map +0 -1
  101. package/bridging/contextMode.d.ts +0 -12
  102. package/bridging/contextMode.d.ts.map +0 -1
  103. package/bridging/contextMode.js +0 -26
  104. package/bridging/contextMode.js.map +0 -1
  105. package/bridging/contextMode.mjs +0 -22
  106. package/bridging/contextMode.mjs.map +0 -1
  107. package/bridging/downloadHandle.d.mts +0 -14
  108. package/bridging/downloadHandle.d.mts.map +0 -1
  109. package/bridging/downloadHandle.d.ts +0 -14
  110. package/bridging/downloadHandle.d.ts.map +0 -1
  111. package/bridging/downloadHandle.js +0 -36
  112. package/bridging/downloadHandle.js.map +0 -1
  113. package/bridging/downloadHandle.mjs +0 -32
  114. package/bridging/downloadHandle.mjs.map +0 -1
  115. package/bridging/downloadProgressUpdate.d.mts +0 -9
  116. package/bridging/downloadProgressUpdate.d.mts.map +0 -1
  117. package/bridging/downloadProgressUpdate.d.ts +0 -9
  118. package/bridging/downloadProgressUpdate.d.ts.map +0 -1
  119. package/bridging/downloadProgressUpdate.js +0 -15
  120. package/bridging/downloadProgressUpdate.js.map +0 -1
  121. package/bridging/downloadProgressUpdate.mjs +0 -11
  122. package/bridging/downloadProgressUpdate.mjs.map +0 -1
  123. package/bridging/downloadState.d.mts +0 -19
  124. package/bridging/downloadState.d.mts.map +0 -1
  125. package/bridging/downloadState.d.ts +0 -19
  126. package/bridging/downloadState.d.ts.map +0 -1
  127. package/bridging/downloadState.js +0 -45
  128. package/bridging/downloadState.js.map +0 -1
  129. package/bridging/downloadState.mjs +0 -41
  130. package/bridging/downloadState.mjs.map +0 -1
  131. package/bridging/engine.d.mts +0 -29
  132. package/bridging/engine.d.mts.map +0 -1
  133. package/bridging/engine.d.ts +0 -29
  134. package/bridging/engine.d.ts.map +0 -1
  135. package/bridging/engine.js +0 -117
  136. package/bridging/engine.js.map +0 -1
  137. package/bridging/engine.mjs +0 -113
  138. package/bridging/engine.mjs.map +0 -1
  139. package/bridging/finishReason.d.mts +0 -7
  140. package/bridging/finishReason.d.mts.map +0 -1
  141. package/bridging/finishReason.d.ts +0 -7
  142. package/bridging/finishReason.d.ts.map +0 -1
  143. package/bridging/finishReason.js +0 -11
  144. package/bridging/finishReason.js.map +0 -1
  145. package/bridging/finishReason.mjs +0 -8
  146. package/bridging/finishReason.mjs.map +0 -1
  147. package/bridging/grammarConfig.d.mts +0 -13
  148. package/bridging/grammarConfig.d.mts.map +0 -1
  149. package/bridging/grammarConfig.d.ts +0 -13
  150. package/bridging/grammarConfig.d.ts.map +0 -1
  151. package/bridging/grammarConfig.js +0 -36
  152. package/bridging/grammarConfig.js.map +0 -1
  153. package/bridging/grammarConfig.mjs +0 -31
  154. package/bridging/grammarConfig.mjs.map +0 -1
  155. package/bridging/input.d.mts +0 -11
  156. package/bridging/input.d.mts.map +0 -1
  157. package/bridging/input.d.ts +0 -11
  158. package/bridging/input.d.ts.map +0 -1
  159. package/bridging/input.js +0 -25
  160. package/bridging/input.js.map +0 -1
  161. package/bridging/input.mjs +0 -21
  162. package/bridging/input.mjs.map +0 -1
  163. package/bridging/licenseStatus.d.mts +0 -14
  164. package/bridging/licenseStatus.d.mts.map +0 -1
  165. package/bridging/licenseStatus.d.ts +0 -14
  166. package/bridging/licenseStatus.d.ts.map +0 -1
  167. package/bridging/licenseStatus.js +0 -42
  168. package/bridging/licenseStatus.js.map +0 -1
  169. package/bridging/licenseStatus.mjs +0 -38
  170. package/bridging/licenseStatus.mjs.map +0 -1
  171. package/bridging/message.d.mts +0 -15
  172. package/bridging/message.d.mts.map +0 -1
  173. package/bridging/message.d.ts +0 -15
  174. package/bridging/message.d.ts.map +0 -1
  175. package/bridging/message.js +0 -43
  176. package/bridging/message.js.map +0 -1
  177. package/bridging/message.mjs +0 -39
  178. package/bridging/message.mjs.map +0 -1
  179. package/bridging/model.d.mts +0 -19
  180. package/bridging/model.d.mts.map +0 -1
  181. package/bridging/model.d.ts +0 -19
  182. package/bridging/model.d.ts.map +0 -1
  183. package/bridging/model.js +0 -39
  184. package/bridging/model.js.map +0 -1
  185. package/bridging/model.mjs +0 -35
  186. package/bridging/model.mjs.map +0 -1
  187. package/bridging/modelKind.d.mts +0 -8
  188. package/bridging/modelKind.d.mts.map +0 -1
  189. package/bridging/modelKind.d.ts +0 -8
  190. package/bridging/modelKind.d.ts.map +0 -1
  191. package/bridging/modelKind.js +0 -30
  192. package/bridging/modelKind.js.map +0 -1
  193. package/bridging/modelKind.mjs +0 -25
  194. package/bridging/modelKind.mjs.map +0 -1
  195. package/bridging/modelType.d.mts +0 -9
  196. package/bridging/modelType.d.mts.map +0 -1
  197. package/bridging/modelType.d.ts +0 -9
  198. package/bridging/modelType.d.ts.map +0 -1
  199. package/bridging/modelType.js +0 -35
  200. package/bridging/modelType.js.map +0 -1
  201. package/bridging/modelType.mjs +0 -30
  202. package/bridging/modelType.mjs.map +0 -1
  203. package/bridging/napi.d.mts +0 -4
  204. package/bridging/napi.d.mts.map +0 -1
  205. package/bridging/napi.d.ts +0 -4
  206. package/bridging/napi.d.ts.map +0 -1
  207. package/bridging/napi.js +0 -3
  208. package/bridging/napi.js.map +0 -1
  209. package/bridging/napi.mjs +0 -2
  210. package/bridging/napi.mjs.map +0 -1
  211. package/bridging/output.d.mts +0 -13
  212. package/bridging/output.d.mts.map +0 -1
  213. package/bridging/output.d.ts +0 -13
  214. package/bridging/output.d.ts.map +0 -1
  215. package/bridging/output.js +0 -36
  216. package/bridging/output.js.map +0 -1
  217. package/bridging/output.mjs +0 -32
  218. package/bridging/output.mjs.map +0 -1
  219. package/bridging/parsedText.d.mts +0 -10
  220. package/bridging/parsedText.d.mts.map +0 -1
  221. package/bridging/parsedText.d.ts +0 -10
  222. package/bridging/parsedText.d.ts.map +0 -1
  223. package/bridging/parsedText.js +0 -24
  224. package/bridging/parsedText.js.map +0 -1
  225. package/bridging/parsedText.mjs +0 -20
  226. package/bridging/parsedText.mjs.map +0 -1
  227. package/bridging/prefillStepSize.d.mts +0 -11
  228. package/bridging/prefillStepSize.d.mts.map +0 -1
  229. package/bridging/prefillStepSize.d.ts +0 -11
  230. package/bridging/prefillStepSize.d.ts.map +0 -1
  231. package/bridging/prefillStepSize.js +0 -28
  232. package/bridging/prefillStepSize.js.map +0 -1
  233. package/bridging/prefillStepSize.mjs +0 -24
  234. package/bridging/prefillStepSize.mjs.map +0 -1
  235. package/bridging/preset.d.mts +0 -14
  236. package/bridging/preset.d.mts.map +0 -1
  237. package/bridging/preset.d.ts +0 -14
  238. package/bridging/preset.d.ts.map +0 -1
  239. package/bridging/preset.js +0 -41
  240. package/bridging/preset.js.map +0 -1
  241. package/bridging/preset.mjs +0 -37
  242. package/bridging/preset.mjs.map +0 -1
  243. package/bridging/role.d.mts +0 -6
  244. package/bridging/role.d.mts.map +0 -1
  245. package/bridging/role.d.ts +0 -6
  246. package/bridging/role.d.ts.map +0 -1
  247. package/bridging/role.js +0 -10
  248. package/bridging/role.js.map +0 -1
  249. package/bridging/role.mjs +0 -7
  250. package/bridging/role.mjs.map +0 -1
  251. package/bridging/runConfig.d.mts +0 -18
  252. package/bridging/runConfig.d.mts.map +0 -1
  253. package/bridging/runConfig.d.ts +0 -18
  254. package/bridging/runConfig.d.ts.map +0 -1
  255. package/bridging/runConfig.js +0 -42
  256. package/bridging/runConfig.js.map +0 -1
  257. package/bridging/runConfig.mjs +0 -38
  258. package/bridging/runConfig.mjs.map +0 -1
  259. package/bridging/runStats.d.mts +0 -8
  260. package/bridging/runStats.d.mts.map +0 -1
  261. package/bridging/runStats.d.ts +0 -8
  262. package/bridging/runStats.d.ts.map +0 -1
  263. package/bridging/runStats.js +0 -16
  264. package/bridging/runStats.js.map +0 -1
  265. package/bridging/runStats.mjs +0 -12
  266. package/bridging/runStats.mjs.map +0 -1
  267. package/bridging/samplingMethod.d.mts +0 -11
  268. package/bridging/samplingMethod.d.mts.map +0 -1
  269. package/bridging/samplingMethod.d.ts +0 -11
  270. package/bridging/samplingMethod.d.ts.map +0 -1
  271. package/bridging/samplingMethod.js +0 -37
  272. package/bridging/samplingMethod.js.map +0 -1
  273. package/bridging/samplingMethod.mjs +0 -33
  274. package/bridging/samplingMethod.mjs.map +0 -1
  275. package/bridging/samplingPolicy.d.mts +0 -11
  276. package/bridging/samplingPolicy.d.mts.map +0 -1
  277. package/bridging/samplingPolicy.d.ts +0 -11
  278. package/bridging/samplingPolicy.d.ts.map +0 -1
  279. package/bridging/samplingPolicy.js +0 -25
  280. package/bridging/samplingPolicy.js.map +0 -1
  281. package/bridging/samplingPolicy.mjs +0 -21
  282. package/bridging/samplingPolicy.mjs.map +0 -1
  283. package/bridging/samplingProcessingOrder.d.mts +0 -8
  284. package/bridging/samplingProcessingOrder.d.mts.map +0 -1
  285. package/bridging/samplingProcessingOrder.d.ts +0 -8
  286. package/bridging/samplingProcessingOrder.d.ts.map +0 -1
  287. package/bridging/samplingProcessingOrder.js +0 -30
  288. package/bridging/samplingProcessingOrder.js.map +0 -1
  289. package/bridging/samplingProcessingOrder.mjs +0 -25
  290. package/bridging/samplingProcessingOrder.mjs.map +0 -1
  291. package/bridging/samplingSeed.d.mts +0 -10
  292. package/bridging/samplingSeed.d.mts.map +0 -1
  293. package/bridging/samplingSeed.d.ts +0 -10
  294. package/bridging/samplingSeed.d.ts.map +0 -1
  295. package/bridging/samplingSeed.js +0 -21
  296. package/bridging/samplingSeed.js.map +0 -1
  297. package/bridging/samplingSeed.mjs +0 -17
  298. package/bridging/samplingSeed.mjs.map +0 -1
  299. package/bridging/stats.d.mts +0 -11
  300. package/bridging/stats.d.mts.map +0 -1
  301. package/bridging/stats.d.ts +0 -11
  302. package/bridging/stats.d.ts.map +0 -1
  303. package/bridging/stats.js +0 -20
  304. package/bridging/stats.js.map +0 -1
  305. package/bridging/stats.mjs +0 -16
  306. package/bridging/stats.mjs.map +0 -1
  307. package/bridging/stepStats.d.mts +0 -14
  308. package/bridging/stepStats.d.mts.map +0 -1
  309. package/bridging/stepStats.d.ts +0 -14
  310. package/bridging/stepStats.d.ts.map +0 -1
  311. package/bridging/stepStats.js +0 -27
  312. package/bridging/stepStats.js.map +0 -1
  313. package/bridging/stepStats.mjs +0 -23
  314. package/bridging/stepStats.mjs.map +0 -1
  315. package/bridging/text.d.mts +0 -9
  316. package/bridging/text.d.mts.map +0 -1
  317. package/bridging/text.d.ts +0 -9
  318. package/bridging/text.d.ts.map +0 -1
  319. package/bridging/text.js +0 -17
  320. package/bridging/text.js.map +0 -1
  321. package/bridging/text.mjs +0 -13
  322. package/bridging/text.mjs.map +0 -1
  323. package/bridging/textToSpeechSession.d.mts +0 -8
  324. package/bridging/textToSpeechSession.d.mts.map +0 -1
  325. package/bridging/textToSpeechSession.d.ts +0 -8
  326. package/bridging/textToSpeechSession.d.ts.map +0 -1
  327. package/bridging/textToSpeechSession.js +0 -14
  328. package/bridging/textToSpeechSession.js.map +0 -1
  329. package/bridging/textToSpeechSession.mjs +0 -10
  330. package/bridging/textToSpeechSession.mjs.map +0 -1
  331. package/bridging/totalStats.d.mts +0 -9
  332. package/bridging/totalStats.d.mts.map +0 -1
  333. package/bridging/totalStats.d.ts +0 -9
  334. package/bridging/totalStats.d.ts.map +0 -1
  335. package/bridging/totalStats.js +0 -18
  336. package/bridging/totalStats.js.map +0 -1
  337. package/bridging/totalStats.mjs +0 -14
  338. package/bridging/totalStats.mjs.map +0 -1
  339. package/error.d.mts +0 -18
  340. package/error.d.mts.map +0 -1
  341. package/error.d.ts +0 -18
  342. package/error.d.ts.map +0 -1
  343. package/error.js +0 -46
  344. package/error.js.map +0 -1
  345. package/error.mjs +0 -41
  346. package/error.mjs.map +0 -1
  347. package/interactors/chatModelInteractor.d.mts +0 -34
  348. package/interactors/chatModelInteractor.d.mts.map +0 -1
  349. package/interactors/chatModelInteractor.d.ts +0 -34
  350. package/interactors/chatModelInteractor.d.ts.map +0 -1
  351. package/interactors/chatModelInteractor.js +0 -93
  352. package/interactors/chatModelInteractor.js.map +0 -1
  353. package/interactors/chatModelInteractor.mjs +0 -89
  354. package/interactors/chatModelInteractor.mjs.map +0 -1
  355. package/interactors/chatModelsInteractor.d.mts +0 -12
  356. package/interactors/chatModelsInteractor.d.mts.map +0 -1
  357. package/interactors/chatModelsInteractor.d.ts +0 -12
  358. package/interactors/chatModelsInteractor.d.ts.map +0 -1
  359. package/interactors/chatModelsInteractor.js +0 -25
  360. package/interactors/chatModelsInteractor.js.map +0 -1
  361. package/interactors/chatModelsInteractor.mjs +0 -21
  362. package/interactors/chatModelsInteractor.mjs.map +0 -1
  363. package/interactors/chatSessionInteractor.d.mts +0 -26
  364. package/interactors/chatSessionInteractor.d.mts.map +0 -1
  365. package/interactors/chatSessionInteractor.d.ts +0 -26
  366. package/interactors/chatSessionInteractor.d.ts.map +0 -1
  367. package/interactors/chatSessionInteractor.js +0 -54
  368. package/interactors/chatSessionInteractor.js.map +0 -1
  369. package/interactors/chatSessionInteractor.mjs +0 -50
  370. package/interactors/chatSessionInteractor.mjs.map +0 -1
  371. package/interactors/downloadInteractor.d.mts +0 -16
  372. package/interactors/downloadInteractor.d.mts.map +0 -1
  373. package/interactors/downloadInteractor.d.ts +0 -16
  374. package/interactors/downloadInteractor.d.ts.map +0 -1
  375. package/interactors/downloadInteractor.js +0 -38
  376. package/interactors/downloadInteractor.js.map +0 -1
  377. package/interactors/downloadInteractor.mjs +0 -34
  378. package/interactors/downloadInteractor.mjs.map +0 -1
  379. package/interactors/engineInteractor.d.mts +0 -15
  380. package/interactors/engineInteractor.d.mts.map +0 -1
  381. package/interactors/engineInteractor.d.ts +0 -15
  382. package/interactors/engineInteractor.d.ts.map +0 -1
  383. package/interactors/engineInteractor.js +0 -30
  384. package/interactors/engineInteractor.js.map +0 -1
  385. package/interactors/engineInteractor.mjs +0 -26
  386. package/interactors/engineInteractor.mjs.map +0 -1
  387. package/interactors/interactor.d.mts +0 -6
  388. package/interactors/interactor.d.mts.map +0 -1
  389. package/interactors/interactor.d.ts +0 -6
  390. package/interactors/interactor.d.ts.map +0 -1
  391. package/interactors/interactor.js +0 -3
  392. package/interactors/interactor.js.map +0 -1
  393. package/interactors/interactor.mjs +0 -2
  394. package/interactors/interactor.mjs.map +0 -1
  395. package/napi/uzu.d.ts +0 -325
  396. package/napi/uzu.js +0 -121
  397. package/napi/uzu.mjs +0 -74
  398. package/src/bridging/asyncBatchSize.ts +0 -24
  399. package/src/bridging/chatSession.ts +0 -28
  400. package/src/bridging/classificationFeature.ts +0 -20
  401. package/src/bridging/classificationLabel.ts +0 -43
  402. package/src/bridging/classificationOutput.ts +0 -22
  403. package/src/bridging/classificationSession.ts +0 -17
  404. package/src/bridging/classificationStats.ts +0 -45
  405. package/src/bridging/config.ts +0 -122
  406. package/src/bridging/contextLength.ts +0 -29
  407. package/src/bridging/contextMode.ts +0 -31
  408. package/src/bridging/downloadHandle.ts +0 -41
  409. package/src/bridging/downloadProgressUpdate.ts +0 -21
  410. package/src/bridging/downloadState.ts +0 -62
  411. package/src/bridging/engine.ts +0 -141
  412. package/src/bridging/finishReason.ts +0 -6
  413. package/src/bridging/grammarConfig.ts +0 -40
  414. package/src/bridging/input.ts +0 -29
  415. package/src/bridging/licenseStatus.ts +0 -39
  416. package/src/bridging/message.ts +0 -50
  417. package/src/bridging/model.ts +0 -68
  418. package/src/bridging/modelKind.ts +0 -27
  419. package/src/bridging/modelType.ts +0 -32
  420. package/src/bridging/napi.ts +0 -3
  421. package/src/bridging/output.ts +0 -40
  422. package/src/bridging/parsedText.ts +0 -27
  423. package/src/bridging/prefillStepSize.ts +0 -32
  424. package/src/bridging/preset.ts +0 -48
  425. package/src/bridging/role.ts +0 -5
  426. package/src/bridging/runConfig.ts +0 -57
  427. package/src/bridging/runStats.ts +0 -17
  428. package/src/bridging/samplingMethod.ts +0 -49
  429. package/src/bridging/samplingPolicy.ts +0 -29
  430. package/src/bridging/samplingProcessingOrder.ts +0 -31
  431. package/src/bridging/samplingSeed.ts +0 -24
  432. package/src/bridging/stats.ts +0 -22
  433. package/src/bridging/stepStats.ts +0 -49
  434. package/src/bridging/text.ts +0 -18
  435. package/src/bridging/textToSpeechSession.ts +0 -15
  436. package/src/bridging/totalStats.ts +0 -20
  437. package/src/error.ts +0 -42
  438. package/src/interactors/chatModelInteractor.ts +0 -126
  439. package/src/interactors/chatModelsInteractor.ts +0 -29
  440. package/src/interactors/chatSessionInteractor.ts +0 -80
  441. package/src/interactors/downloadInteractor.ts +0 -47
  442. package/src/interactors/engineInteractor.ts +0 -38
  443. package/src/interactors/interactor.ts +0 -7
  444. package/src/napi/uzu.d.ts +0 -325
  445. package/src/napi/uzu.js +0 -121
  446. package/src/napi/uzu.mjs +0 -74
  447. package/src/utilities/env.ts +0 -9
  448. package/utilities/env.d.mts +0 -2
  449. package/utilities/env.d.mts.map +0 -1
  450. package/utilities/env.d.ts +0 -2
  451. package/utilities/env.d.ts.map +0 -1
  452. package/utilities/env.js +0 -14
  453. package/utilities/env.js.map +0 -1
  454. package/utilities/env.mjs +0 -10
  455. package/utilities/env.mjs.map +0 -1
package/LICENSE CHANGED
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/README.md CHANGED
@@ -4,81 +4,60 @@
4
4
  </picture>
5
5
  </p>
6
6
 
7
- <a href="https://discord.com/invite/trymirai"><img src="https://img.shields.io/discord/1377764166764462120?label=Discord" alt="Discord"></a>
8
- <a href="mailto:contact@getmirai.co?subject=Interested%20in%20Mirai"><img src="https://img.shields.io/badge/Send-Email-green" alt="Contact us"></a>
9
- <a href="https://docs.trymirai.com/app-integration/overview"><img src="https://img.shields.io/badge/Read-Docs-blue" alt="Read docs"></a>
10
- [![npm (scoped)](https://img.shields.io/npm/v/%40trymirai%2Fuzu)](https://www.npmjs.com/package/@trymirai/uzu)
11
- [![License](https://img.shields.io/badge/License-MIT-blue)](LICENSE)
7
+ <a href="https://discord.com/invite/trymirai"><img src="https://img.shields.io/discord/1377764166764462120?label=Discord&color=brightgreen" alt="Discord"></a> <a href="mailto:contact@getmirai.co?subject=Interested%20in%20Mirai"><img src="https://img.shields.io/badge/Send-Email-brightgreen" alt="Contact us"></a> <a href="https://docs.trymirai.com"><img src="https://img.shields.io/badge/Read-Docs-brightgreen" alt="Read docs"></a> [![License](https://img.shields.io/badge/License-MIT-brightgreen)](LICENSE) [![Build](https://github.com/trymirai/uzu/actions/workflows/tests.yml/badge.svg)](https://github.com/trymirai/uzu/actions) [![TypeScript](https://img.shields.io/badge/TypeScript-yellow)](bindings/typescript) [![Package](https://img.shields.io/npm/v/@trymirai/uzu?color=yellow&label=Package)](https://www.npmjs.com/package/@trymirai/uzu) [![Downloads](https://img.shields.io/npm/dm/@trymirai/uzu?color=yellow&label=Downloads)](https://www.npmjs.com/package/@trymirai/uzu)
12
8
 
13
- # uzu-ts
9
+ # uzu
14
10
 
15
- Node package for [uzu](https://github.com/trymirai/uzu), a **high-performance** inference engine for AI models on Apple Silicon. It allows you to deploy AI directly in your app with **zero latency**, **full data privacy**, and **no inference costs**. You don’t need an ML team or weeks of setup - one developer can handle everything in minutes. Key features:
11
+ A high-performance inference engine for AI models. It allows you to deploy AI directly in your app with **zero latency**, **full data privacy**, and **no inference costs**. Key features:
16
12
 
17
13
  - Simple, high-level API
18
- - Specialized configurations with significant performance boosts for common use cases like classification and summarization
14
+ - Unified model configurations, making it easy to add support for new models
15
+ - Traceable computations to ensure correctness against the source-of-truth implementation
16
+ - Utilizes unified memory on Apple devices
19
17
  - [Broad model support](https://trymirai.com/models)
20
18
 
21
19
  ## Quick Start
22
20
 
23
- Add the `uzu` dependency to your project's `package.json`:
24
21
 
25
- ```json
26
- "dependencies": {
27
- "@trymirai/uzu": "0.3.1"
28
- }
29
- ```
30
22
 
31
- Set up your project through [Platform](https://platform.trymirai.com) and obtain an `API_KEY`. Then, choose the model you want from the [library](https://platform.trymirai.com/models) and run it with the following snippet using the corresponding identifier:
23
+ Add the dependency:
32
24
 
33
- ```ts
34
- const output = await Engine
35
- .create('API_KEY')
36
- .chatModel('Qwen/Qwen3-0.6B')
37
- .reply('Tell me a short, funny story about a robot');
25
+ ```bash
26
+ pnpm add @trymirai/uzu@0.4.0
38
27
  ```
39
28
 
40
- Everything from model downloading to inference configuration is handled automatically. Refer to the [documentation](https://docs.trymirai.com) for details on how to customize each step of the process.
29
+ Run the code below:
41
30
 
42
- ## Examples
31
+ ```ts
32
+ import { ChatConfig, ChatMessage, ChatReplyConfig, Engine, EngineConfig } from '@trymirai/uzu';
43
33
 
44
- Place the `API_KEY` you obtained earlier in the corresponding example file, and then run it using one of the following commands:
34
+ async function main() {
35
+ let engineConfig = EngineConfig.create();
36
+ let engine = await Engine.create(engineConfig);
45
37
 
46
- ```bash
47
- pnpm run tsn examples/chat.ts
48
- pnpm run tsn examples/chatWithSpeculator.ts
49
- pnpm run tsn examples/chatDynamicContext.ts
50
- pnpm run tsn examples/chatStaticContext.ts
51
- pnpm run tsn examples/summarization.ts
52
- pnpm run tsn examples/classification.ts
53
- pnpm run tsn examples/cloud.ts
54
- pnpm run tsn examples/structuredOutput.ts
55
- pnpm run tsn examples/classifier.ts
56
- pnpm run tsn examples/textToSpeech.ts
57
- ```
38
+ let model = await engine.model('Qwen/Qwen3-0.6B');
39
+ if (!model) {
40
+ throw new Error('Model not found');
41
+ }
58
42
 
59
- ### Chat
43
+ for await (const update of await engine.download(model)) {
44
+ console.log('Download progress:', update.progress);
45
+ }
60
46
 
61
- In this example, we will download a model and get a reply to a specific list of messages:
47
+ let session = await engine.chat(model, ChatConfig.create());
62
48
 
63
- ```ts
64
- import Engine, { Message } from '@trymirai/uzu';
49
+ let messages = [
50
+ ChatMessage.system().withText('You are a helpful assistant'),
51
+ ChatMessage.user().withText('Tell me a short, funny story about a robot')
52
+ ];
65
53
 
66
- async function main() {
67
- const output = await Engine.create('API_KEY')
68
- .chatModel('Qwen/Qwen3-0.6B')
69
- .download((update) => {
70
- console.log('Progress:', update.progress);
71
- })
72
- .replyToMessages(
73
- [
74
- Message.system('You are a helpful assistant'),
75
- Message.user('Tell me a short, funny story about a robot')
76
- ],
77
- (partialOutput) => {
78
- return true;
79
- },
80
- );
81
- console.log(output.text.original);
54
+ let reply = await session.reply(messages, ChatReplyConfig.create());
55
+ let message = reply[0]?.message;
56
+
57
+ if (message) {
58
+ console.log('Reasoning: ', message.reasoning);
59
+ console.log('Text: ', message.text);
60
+ }
82
61
  }
83
62
 
84
63
  main().catch((error) => {
@@ -86,44 +65,51 @@ main().catch((error) => {
86
65
  });
87
66
  ```
88
67
 
89
- ### Speedup with speculative decoding
90
68
 
91
- Speculative decoding allows a significant increase in generation speed. For each model, we train a small n-gram model (under 50 MB) tailored to a specific domain or use case. In general chat scenarios, you can use the `Chat` preset, which will automatically use the corresponding speculator:
69
+ <br>
70
+
71
+ Everything from model downloading to inference configuration is handled automatically. Refer to the [documentation](https://docs.trymirai.com) for details on how to customize each step of the process.
72
+
73
+ ## Examples
74
+
75
+ You can run any example via `cargo tools example` \<**typescript**\> \<**chat** | **chat-cloud** | **chat-speculation-classification** | **chat-speculation-summarization** | **chat-structured-output** | **classification** | **quick-start** | **text-to-speech**\>:
76
+
77
+ ### Chat
78
+
79
+ In this example, we will download a model and get a reply to a specific list of messages:
92
80
 
93
81
  ```ts
94
- import Engine, { Message, Preset } from '@trymirai/uzu';
82
+ import { ChatConfig, ChatMessage, ChatReplyConfig, ChatSessionStreamChunkError, ChatSessionStreamChunkReplies, Engine, EngineConfig } from '@trymirai/uzu';
95
83
 
96
84
  async function main() {
97
- const engine = Engine.create('API_KEY');
98
- const model = engine
99
- .chatModel('Qwen/Qwen3-0.6B')
100
- .download((update) => {
101
- console.log('Progress:', update.progress);
102
- });
103
-
104
- const messages = [
105
- Message.system('You are a helpful assistant'),
106
- Message.user('Tell me a short, funny story about a robot')
107
- ];
85
+ let engineConfig = EngineConfig.create();
86
+ let engine = await Engine.create(engineConfig);
87
+
88
+ let model = await engine.model('Qwen/Qwen3-0.6B');
89
+ if (!model) {
90
+ throw new Error('Model not found');
91
+ }
92
+ for await (const update of await engine.download(model)) {
93
+ console.log('Download progress:', update.progress);
94
+ }
108
95
 
109
- const outputGeneral = await model
110
- .replyToMessages(
111
- messages,
112
- (partialOutput) => {
113
- return true;
114
- },
115
- );
116
- console.log('Generation speed t/s (general):', outputGeneral.stats.generateStats?.tokensPerSecond ?? 0);
117
-
118
- const outputWithSpeculator = await model
119
- .preset(Preset.chat())
120
- .replyToMessages(
121
- messages,
122
- (partialOutput) => {
123
- return true;
124
- },
125
- );
126
- console.log('Generation speed t/s (with chat speculator):', outputWithSpeculator.stats.generateStats?.tokensPerSecond ?? 0);
96
+ let messages = [
97
+ ChatMessage.system().withText('You are a helpful assistant'),
98
+ ChatMessage.user().withText('Tell me a short, funny story about a robot')
99
+ ];
100
+ let session = await engine.chat(model, ChatConfig.create());
101
+ let stream = await session.replyWithStream(messages, ChatReplyConfig.create());
102
+ let message: ChatMessage | undefined;
103
+ for await (const chunk of stream) {
104
+ if (chunk instanceof ChatSessionStreamChunkReplies) {
105
+ message = chunk.replies[0]?.message;
106
+ console.log('Generated tokens: ', chunk.replies[0]?.stats.tokensCountOutput);
107
+ } else if (chunk instanceof ChatSessionStreamChunkError) {
108
+ console.error('Error: ', chunk.error);
109
+ }
110
+ }
111
+ console.log('Reasoning: ', message?.reasoning);
112
+ console.log('Text: ', message?.text);
127
113
  }
128
114
 
129
115
  main().catch((error) => {
@@ -131,44 +117,35 @@ main().catch((error) => {
131
117
  });
132
118
  ```
133
119
 
134
- ### Chat with dynamic context
120
+ <br>Once loaded, the same `ChatSession` can be reused for multiple requests until you drop it. Each model may consume a significant amount of RAM, so it's important to keep only one session loaded at a time. For iOS apps, we recommend adding the [Increased Memory Capability](https://developer.apple.com/documentation/bundleresources/entitlements/com.apple.developer.kernel.increased-memory-limit) entitlement to ensure your app can allocate the required memory.
135
121
 
136
- In this example, we will use the dynamic `ContextMode`, which automatically maintains a continuous conversation history instead of resetting the context with each new input. Every new message is added to the ongoing chat, allowing the model to remember what has already been said and respond with full context.
122
+ ### Chat with the cloud model
123
+
124
+ In this example, we will get a reply to a specific list of messages from a cloud model:
137
125
 
138
126
  ```ts
139
- import Engine, { Config, ContextMode, Input, RunConfig } from '@trymirai/uzu';
127
+ import { ChatConfig, ChatMessage, ChatReplyConfig, Engine, EngineConfig, ReasoningEffort } from '@trymirai/uzu';
140
128
 
141
129
  async function main() {
142
- const engine = await Engine.load('API_KEY');
143
-
144
- const model = await engine.chatModel('Qwen/Qwen3-0.6B');
145
- await engine.downloadModel(model, (update) => {
146
- console.log('Progress:', update.progress);
147
- });
148
-
149
- const config = Config
150
- .default()
151
- .withContextMode(ContextMode.dynamic());
152
- const session = engine.chatSession(model, config);
153
-
154
- const requests = [
155
- 'Tell about London',
156
- 'Compare with New York',
157
- 'Compare the population of the two',
130
+ let engineConfig = EngineConfig.create().withOpenaiApiKey('OPENAI_API_KEY');
131
+ let engine = await Engine.create(engineConfig);
132
+
133
+ let model = await engine.model('gpt-5');
134
+ if (!model) {
135
+ throw new Error('Model not found');
136
+ }
137
+
138
+ let messages = [
139
+ ChatMessage.system().withReasoningEffort("Low" as ReasoningEffort),
140
+ ChatMessage.user().withText('How LLMs work')
158
141
  ];
159
- const runConfig = RunConfig
160
- .default()
161
- .withTokensLimit(1024)
162
- .withEnableThinking(false);
163
-
164
- for (const request of requests) {
165
- const output = session.run(Input.text(request), runConfig, (partialOutput) => {
166
- return true;
167
- });
168
-
169
- console.log('Request:', request);
170
- console.log('Response:', output.text.original.trim());
171
- console.log('-------------------------');
142
+
143
+ let session = await engine.chat(model, ChatConfig.create());
144
+ let reply = await session.reply(messages, ChatReplyConfig.create());
145
+ let message = reply[0]?.message;
146
+ if (message) {
147
+ console.log('Reasoning: ', message.reasoning);
148
+ console.log('Text: ', message.text);
172
149
  }
173
150
  }
174
151
 
@@ -177,49 +154,52 @@ main().catch((error) => {
177
154
  });
178
155
  ```
179
156
 
180
- ### Chat with static context
157
+ ### Chat using speculation preset for classification
181
158
 
182
- In this example, we will use the static `ContextMode`, which begins with an initial list of messages defining the base context of the conversation, such as predefined instructions. Unlike dynamic mode, this context is fixed and does not evolve with new messages. Each inference request is processed independently, using only the initial context and the latest input, without retaining any previous conversation history.
159
+ In this example, we will use the `classification` speculation preset to determine the sentiment of the user's input:
183
160
 
184
161
  ```ts
185
- import Engine, { Config, ContextMode, Input, Message, RunConfig } from '@trymirai/uzu';
186
-
187
- function listToString(list: string[]): string {
188
- return "[" + list.map((item) => `"${item}"`).join(", ") + "]";
189
- }
162
+ import { ChatConfig, ChatMessage, ChatReplyConfig, ChatSpeculationPresetClassification, Engine, EngineConfig, Feature, ReasoningEffort, SamplingMethodGreedy } from '@trymirai/uzu';
190
163
 
191
164
  async function main() {
192
- const engine = await Engine.load('API_KEY');
193
-
194
- const model = await engine.chatModel('Qwen/Qwen3-0.6B');
195
- await engine.downloadModel(model, (update) => {
196
- console.log('Progress:', update.progress);
197
- });
198
-
199
- const instructions =
200
- `Your task is to name countries for each city in the given list.
201
- For example for ${listToString(["Helsenki", "Stockholm", "Barcelona"])} the answer should be ${listToString(["Finland", "Sweden", "Spain"])}.`;
202
- const config = Config
203
- .default()
204
- .withContextMode(ContextMode.static(Input.messages([Message.system(instructions)])));
205
- const session = engine.chatSession(model, config);
206
-
207
- const requests = [
208
- listToString(["New York", "London", "Lisbon", "Paris", "Berlin"]),
209
- listToString(["Bangkok", "Tokyo", "Seoul", "Beijing", "Delhi"]),
165
+ let engineConfig = EngineConfig.create();
166
+ let engine = await Engine.create(engineConfig);
167
+
168
+ let model = await engine.model('Qwen/Qwen3-0.6B');
169
+ if (!model) {
170
+ throw new Error('Model not found');
171
+ }
172
+ for await (const update of await engine.download(model)) {
173
+ console.log('Download progress:', update.progress);
174
+ }
175
+
176
+ const feature = new Feature('sentiment', [
177
+ 'Happy',
178
+ 'Sad',
179
+ 'Angry',
180
+ 'Fearful',
181
+ 'Surprised',
182
+ 'Disgusted',
183
+ ]);
184
+ let chatConfig = ChatConfig.create().withSpeculationPreset(new ChatSpeculationPresetClassification(feature));
185
+ let session = await engine.chat(model, chatConfig);
186
+
187
+ const textToDetectFeature =
188
+ "Today's been awesome! Everything just feels right, and I can't stop smiling.";
189
+ const prompt =
190
+ `Text is: "${textToDetectFeature}". Choose ${feature.name} from the list: ${feature.values.join(', ')}. ` +
191
+ "Answer with one word. Don't add a dot at the end.";
192
+ let messages = [
193
+ ChatMessage.system().withReasoningEffort("Disabled" as ReasoningEffort),
194
+ ChatMessage.user().withText(prompt)
210
195
  ];
211
- const runConfig = RunConfig
212
- .default()
213
- .withEnableThinking(false);
214
-
215
- for (const request of requests) {
216
- const output = session.run(Input.text(request), runConfig, (partialOutput) => {
217
- return true;
218
- });
219
-
220
- console.log('Request:', request);
221
- console.log('Response:', output.text.original.trim());
222
- console.log('-------------------------');
196
+
197
+ let chatReplyConfig = ChatReplyConfig.create().withTokenLimit(32).withSamplingMethod(new SamplingMethodGreedy());
198
+ let reply = (await session.reply(messages, chatReplyConfig))[0];
199
+
200
+ if (reply) {
201
+ console.log('Prediction: ', reply.message.text);
202
+ console.log('Generated tokens: ', reply.stats.tokensCountOutput);
223
203
  }
224
204
  }
225
205
 
@@ -228,36 +208,45 @@ main().catch((error) => {
228
208
  });
229
209
  ```
230
210
 
231
- ### Summarization
211
+ <br>You can view the stats to see that the answer will be ready immediately after the prefill step, and actual generation won’t even start due to speculative decoding, which significantly improves generation speed.
232
212
 
233
- In this example, we will use the `summarization` preset to generate a summary of the input text:
213
+ ### Chat using speculation preset for summarization
214
+
215
+ In this example, we will use the `summarization` speculation preset to generate a summary of the input text:
234
216
 
235
217
  ```ts
236
- import Engine, { Preset, SamplingMethod } from '@trymirai/uzu';
218
+ import { ChatConfig, ChatMessage, ChatReplyConfig, ChatSpeculationPresetSummarization, Engine, EngineConfig, ReasoningEffort, SamplingMethodGreedy } from '@trymirai/uzu';
237
219
 
238
220
  async function main() {
221
+ let engineConfig = EngineConfig.create();
222
+ let engine = await Engine.create(engineConfig);
223
+
224
+ let model = await engine.model('Qwen/Qwen3-0.6B');
225
+ if (!model) {
226
+ throw new Error('Model not found');
227
+ }
228
+ for await (const update of await engine.download(model)) {
229
+ console.log('Download progress:', update.progress);
230
+ }
231
+
239
232
  const textToSummarize =
240
233
  "A Large Language Model (LLM) is a type of artificial intelligence that processes and generates human-like text. It is trained on vast datasets containing books, articles, and web content, allowing it to understand and predict language patterns. LLMs use deep learning, particularly transformer-based architectures, to analyze text, recognize context, and generate coherent responses. These models have a wide range of applications, including chatbots, content creation, translation, and code generation. One of the key strengths of LLMs is their ability to generate contextually relevant text based on prompts. They utilize self-attention mechanisms to weigh the importance of words within a sentence, improving accuracy and fluency. Examples of popular LLMs include OpenAI's GPT series, Google's BERT, and Meta's LLaMA. As these models grow in size and sophistication, they continue to enhance human-computer interactions, making AI-powered communication more natural and effective.";
241
234
  const prompt = `Text is: "${textToSummarize}". Write only summary itself.`;
235
+ let messages = [
236
+ ChatMessage.system().withReasoningEffort("Disabled" as ReasoningEffort),
237
+ ChatMessage.user().withText(prompt)
238
+ ];
239
+
240
+ let chatConfig = ChatConfig.create().withSpeculationPreset(new ChatSpeculationPresetSummarization);
241
+ let session = await engine.chat(model, chatConfig);
242
+
243
+ let chatReplyConfig = ChatReplyConfig.create().withTokenLimit(256).withSamplingMethod(new SamplingMethodGreedy());
244
+ let reply = (await session.reply(messages, chatReplyConfig))[0];
242
245
 
243
- const output = await Engine.create('API_KEY')
244
- .chatModel('Qwen/Qwen3-0.6B')
245
- .download((update) => {
246
- console.log('Progress:', update.progress);
247
- })
248
- .preset(Preset.summarization())
249
- .session()
250
- .tokensLimit(256)
251
- .enableThinking(false)
252
- .samplingMethod(SamplingMethod.greedy())
253
- .reply(prompt);
254
-
255
- console.log('Summary:', output.text.original);
256
- console.log(
257
- 'Model runs:',
258
- output.stats.prefillStats.modelRun.count + (output.stats.generateStats?.modelRun.count ?? 0),
259
- );
260
- console.log('Tokens count:', output.stats.totalStats.tokensCountOutput);
246
+ if (reply) {
247
+ console.log('Summary: ', reply.message.text);
248
+ console.log('Generation t\\s: ', reply.stats.generateTokensPerSecond);
249
+ }
261
250
  }
262
251
 
263
252
  main().catch((error) => {
@@ -265,44 +254,55 @@ main().catch((error) => {
265
254
  });
266
255
  ```
267
256
 
268
- You will notice that the model’s run count is lower than the actual number of generated tokens due to speculative decoding, which significantly improves generation speed.
257
+ <br>You will notice that the model’s run count is lower than the actual number of generated tokens due to speculative decoding, which significantly improves generation speed.
269
258
 
270
- ### Classification
259
+ ### Chat with structured output
271
260
 
272
- In this example, we will use the `classification` preset to determine the sentiment of the user's input:
261
+ Sometimes you want the generated output to be valid JSON with predefined fields. You can use `Grammar` to manually specify a JSON schema for the response you want to receive:
273
262
 
274
263
  ```ts
275
- import Engine, { ClassificationFeature, Preset, SamplingMethod } from '@trymirai/uzu';
264
+ import { ChatConfig, ChatMessage, ChatReplyConfig, Engine, EngineConfig, GrammarJsonSchema, ReasoningEffort } from '@trymirai/uzu';
265
+ import * as z from "zod";
266
+
267
+ const CountryType = z.object({
268
+ name: z.string(),
269
+ capital: z.string(),
270
+ });
271
+ const CountryListType = z.array(CountryType);
272
+
273
+ function structuredResponse<T extends z.ZodType>(response: string | null | undefined, type: T): z.infer<T> | undefined {
274
+ if (!response) {
275
+ return undefined;
276
+ }
277
+ const data = JSON.parse(response);
278
+ const result = type.parse(data);
279
+ return result;
280
+ }
276
281
 
277
282
  async function main() {
278
- const feature = new ClassificationFeature('sentiment', [
279
- 'Happy',
280
- 'Sad',
281
- 'Angry',
282
- 'Fearful',
283
- 'Surprised',
284
- 'Disgusted',
285
- ]);
286
- const textToDetectFeature =
287
- "Today's been awesome! Everything just feels right, and I can't stop smiling.";
288
- const prompt =
289
- `Text is: "${textToDetectFeature}". Choose ${feature.name} from the list: ${feature.values.join(', ')}. ` +
290
- "Answer with one word. Don't add a dot at the end.";
283
+ let engineConfig = EngineConfig.create();
284
+ let engine = await Engine.create(engineConfig);
285
+
286
+ let model = await engine.model('Qwen/Qwen3-0.6B');
287
+ if (!model) {
288
+ throw new Error('Model not found');
289
+ }
290
+ for await (const update of await engine.download(model)) {
291
+ console.log('Download progress:', update.progress);
292
+ }
293
+
294
+ let schema = z.toJSONSchema(CountryListType);
295
+ let schemaString = JSON.stringify(schema);
296
+ let messages = [
297
+ ChatMessage.system().withReasoningEffort("Disabled" as ReasoningEffort),
298
+ ChatMessage.user().withText('Give me a JSON object containing a list of 3 countries, where each country has name and capital fields')
299
+ ];
291
300
 
292
- const output = await Engine.create('API_KEY')
293
- .chatModel('Qwen/Qwen3-0.6B')
294
- .download((update) => {
295
- console.log('Progress:', update.progress);
296
- })
297
- .preset(Preset.classification(feature))
298
- .session()
299
- .tokensLimit(32)
300
- .enableThinking(false)
301
- .samplingMethod(SamplingMethod.greedy())
302
- .reply(prompt);
303
-
304
- console.log('Prediction:', output.text.original);
305
- console.log('Stats:', output.stats);
301
+ let session = await engine.chat(model, ChatConfig.create());
302
+ let reply = await session.reply(messages, ChatReplyConfig.create().withGrammar(new GrammarJsonSchema(schemaString)));
303
+ let message = reply[0]?.message;
304
+ let countries = structuredResponse(message?.text, CountryListType);
305
+ console.log(countries);
306
306
  }
307
307
 
308
308
  main().catch((error) => {
@@ -310,21 +310,32 @@ main().catch((error) => {
310
310
  });
311
311
  ```
312
312
 
313
- You can view the stats to see that the answer will be ready immediately after the prefill step, and actual generation won’t even start due to speculative decoding, which significantly improves generation speed.
314
-
315
- ### Cloud
313
+ ### Classification
316
314
 
317
- Sometimes you want to create a complex pipeline where some requests are processed on-device and the more complex ones are handled in the cloud using a larger model. With `uzu`, you can do this easily: just choose the cloud model you want to use and perform all requests through the same API:
315
+ In this example, we will use a classification model to determine whether the user's input is safe from a moderation perspective:
318
316
 
319
317
  ```ts
320
- import Engine from '@trymirai/uzu';
318
+ import { ClassificationMessage, Engine, EngineConfig } from '@trymirai/uzu';
321
319
 
322
320
  async function main() {
323
- const output = await Engine
324
- .create('API_KEY')
325
- .chatModel('openai/gpt-oss-120b')
326
- .reply('How LLMs work');
327
- console.log(output.text.original);
321
+ let engineConfig = EngineConfig.create();
322
+ let engine = await Engine.create(engineConfig);
323
+
324
+ let model = await engine.model('trymirai/chat-moderation-router');
325
+ if (!model) {
326
+ throw new Error('Model not found');
327
+ }
328
+ for await (const update of await engine.download(model)) {
329
+ console.log('Download progress:', update.progress);
330
+ }
331
+
332
+ let messages = [
333
+ ClassificationMessage.user('Hi')
334
+ ];
335
+
336
+ let session = await engine.classification(model);
337
+ let output = await session.classify(messages);
338
+ console.log('Output: ', output.probabilities.values);
328
339
  }
329
340
 
330
341
  main().catch((error) => {
@@ -332,38 +343,33 @@ main().catch((error) => {
332
343
  });
333
344
  ```
334
345
 
335
- ### Structured Output
346
+ ### Text to Speech
336
347
 
337
- Sometimes you want the generated output to be valid JSON with predefined fields. You can use `GrammarConfig` to manually specify a JSON schema, or define the schema using [Zod](https://github.com/colinhacks/zod).
348
+ In this example, we will generate audio from text:
338
349
 
339
350
  ```ts
340
- import Engine, { GrammarConfig } from '@trymirai/uzu';
341
- import * as z from "zod";
342
-
343
- const CountryType = z.object({
344
- name: z.string(),
345
- capital: z.string(),
346
- });
347
- const CountryListType = z.array(CountryType);
351
+ import { Engine, EngineConfig } from '@trymirai/uzu';
352
+ import { homedir } from "os";
353
+ import { join } from "path";
348
354
 
349
355
  async function main() {
350
- const output = await Engine.create('API_KEY')
351
- .chatModel('Qwen/Qwen3-0.6B')
352
- .download((update) => {
353
- console.log('Progress:', update.progress);
354
- })
355
- .session()
356
- .enableThinking(false)
357
- .grammarConfig(GrammarConfig.fromType(CountryListType))
358
- .reply(
359
- "Give me a JSON object containing a list of 3 countries, where each country has name and capital fields",
360
- (partialOutput) => {
361
- return true;
362
- },
363
- );
364
-
365
- const countries = output.text.parsed.structuredResponse(CountryListType);
366
- console.log(countries);
356
+ let engineConfig = EngineConfig.create();
357
+ let engine = await Engine.create(engineConfig);
358
+
359
+ let model = await engine.model('fishaudio/s1-mini');
360
+ if (!model) {
361
+ throw new Error('Model not found');
362
+ }
363
+ for await (const update of await engine.download(model)) {
364
+ console.log('Download progress:', update.progress);
365
+ }
366
+
367
+ const text = "London is the capital of United Kingdom and one of the world’s most influential cities, known for its rich history, cultural diversity, and global significance in finance, politics, and the arts. Situated along the River Thames, the city blends historic landmarks like Tower of London and Buckingham Palace with modern architecture such as The Shard. London is also home to renowned institutions including the British Museum and vibrant areas like Covent Garden, offering a mix of history, entertainment, and innovation that attracts millions of visitors each year.";
368
+ const outputPath = join(homedir(), "Desktop", "output.wav");
369
+ let session = await engine.textToSpeech(model);
370
+ let pcmBatch = await session.synthesize(text);
371
+ pcmBatch.saveAsWav(outputPath);
372
+ console.log('Output saved to: ', outputPath);
367
373
  }
368
374
 
369
375
  main().catch((error) => {
@@ -371,6 +377,8 @@ main().catch((error) => {
371
377
  });
372
378
  ```
373
379
 
380
+
381
+
374
382
  ## Troubleshooting
375
383
 
376
384
  If you experience any problems, please contact us via [Discord](https://discord.com/invite/trymirai) or [email](mailto:contact@getmirai.co).