@futdevpro/nts-dynamo 1.10.77 → 1.11.2

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 (316) hide show
  1. package/build/_collections/atlas-default-db-options.const.d.ts +28 -0
  2. package/build/_collections/atlas-default-db-options.const.d.ts.map +1 -0
  3. package/build/_collections/atlas-default-db-options.const.js +10 -0
  4. package/build/_collections/atlas-default-db-options.const.js.map +1 -0
  5. package/build/_collections/get-environment-settings.util.d.ts +3 -0
  6. package/build/_collections/get-environment-settings.util.d.ts.map +1 -0
  7. package/build/_collections/get-environment-settings.util.js +45 -0
  8. package/build/_collections/get-environment-settings.util.js.map +1 -0
  9. package/build/_collections/global-settings.const.d.ts.map +1 -1
  10. package/build/_collections/global-settings.const.js +9 -4
  11. package/build/_collections/global-settings.const.js.map +1 -1
  12. package/build/_models/control-models/app-params.control-model.d.ts +6 -0
  13. package/build/_models/control-models/app-params.control-model.d.ts.map +1 -1
  14. package/build/_models/control-models/app-params.control-model.js +29 -2
  15. package/build/_models/control-models/app-params.control-model.js.map +1 -1
  16. package/build/_models/control-models/app-params.control-model.spec.js +5 -4
  17. package/build/_models/control-models/app-params.control-model.spec.js.map +1 -1
  18. package/build/_models/control-models/endpoint-params.control-model.js +1 -1
  19. package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
  20. package/build/_models/interfaces/environment-settings.interface.d.ts +35 -0
  21. package/build/_models/interfaces/environment-settings.interface.d.ts.map +1 -0
  22. package/build/_models/interfaces/environment-settings.interface.js +3 -0
  23. package/build/_models/interfaces/environment-settings.interface.js.map +1 -0
  24. package/build/_models/interfaces/global-settings.interface.d.ts +34 -2
  25. package/build/_models/interfaces/global-settings.interface.d.ts.map +1 -1
  26. package/build/_modules/custom-data/index.d.ts.map +1 -1
  27. package/build/_modules/custom-data/index.js +1 -0
  28. package/build/_modules/custom-data/index.js.map +1 -1
  29. package/build/_modules/discord-assistant/_collections/dias-global-settings.const.d.ts +3 -0
  30. package/build/_modules/discord-assistant/_collections/dias-global-settings.const.d.ts.map +1 -0
  31. package/build/_modules/discord-assistant/_collections/dias-global-settings.const.js +17 -0
  32. package/build/_modules/discord-assistant/_collections/dias-global-settings.const.js.map +1 -0
  33. package/build/_modules/discord-assistant/_collections/dias.util.d.ts +6 -0
  34. package/build/_modules/discord-assistant/_collections/dias.util.d.ts.map +1 -0
  35. package/build/_modules/discord-assistant/_collections/dias.util.js +36 -0
  36. package/build/_modules/discord-assistant/_collections/dias.util.js.map +1 -0
  37. package/build/_modules/discord-assistant/_models/dias-global-settings.interface.d.ts +18 -0
  38. package/build/_modules/discord-assistant/_models/dias-global-settings.interface.d.ts.map +1 -0
  39. package/build/_modules/discord-assistant/_models/dias-global-settings.interface.js +3 -0
  40. package/build/_modules/discord-assistant/_models/dias-global-settings.interface.js.map +1 -0
  41. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.d.ts +10 -0
  42. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.d.ts.map +1 -0
  43. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.js +41 -0
  44. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.js.map +1 -0
  45. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts +14 -0
  46. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts.map +1 -0
  47. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +88 -0
  48. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js.map +1 -0
  49. package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts +10 -0
  50. package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts.map +1 -0
  51. package/build/_modules/discord-assistant/_services/dias-io.control-service.js +40 -0
  52. package/build/_modules/discord-assistant/_services/dias-io.control-service.js.map +1 -0
  53. package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts +8 -0
  54. package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts.map +1 -0
  55. package/build/_modules/discord-assistant/_services/dias-main.control-service.js +23 -0
  56. package/build/_modules/discord-assistant/_services/dias-main.control-service.js.map +1 -0
  57. package/build/_modules/discord-assistant/_services/dias.service-base.d.ts +11 -0
  58. package/build/_modules/discord-assistant/_services/dias.service-base.d.ts.map +1 -0
  59. package/build/_modules/discord-assistant/_services/dias.service-base.js +33 -0
  60. package/build/_modules/discord-assistant/_services/dias.service-base.js.map +1 -0
  61. package/build/_modules/discord-assistant/index.d.ts +10 -0
  62. package/build/_modules/discord-assistant/index.d.ts.map +1 -0
  63. package/build/_modules/discord-assistant/index.js +23 -0
  64. package/build/_modules/discord-assistant/index.js.map +1 -0
  65. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.d.ts +4 -0
  66. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.d.ts.map +1 -0
  67. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.js +8 -0
  68. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.js.map +1 -0
  69. package/build/_modules/discord-assistant-voiced/index.d.ts +3 -0
  70. package/build/_modules/discord-assistant-voiced/index.d.ts.map +1 -0
  71. package/build/_modules/discord-assistant-voiced/index.js +26 -0
  72. package/build/_modules/discord-assistant-voiced/index.js.map +1 -0
  73. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.d.ts +3 -0
  74. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.d.ts.map +1 -0
  75. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.js +13 -0
  76. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.js.map +1 -0
  77. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts +3 -0
  78. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts.map +1 -0
  79. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.js +44 -0
  80. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.js.map +1 -0
  81. package/build/_modules/discord-bot/_collections/dibo-operations.util.d.ts +22 -0
  82. package/build/_modules/discord-bot/_collections/dibo-operations.util.d.ts.map +1 -0
  83. package/build/_modules/discord-bot/_collections/dibo-operations.util.js +261 -0
  84. package/build/_modules/discord-bot/_collections/dibo-operations.util.js.map +1 -0
  85. package/build/_modules/discord-bot/_models/dibo-command.interface.d.ts +8 -0
  86. package/build/_modules/discord-bot/_models/dibo-command.interface.d.ts.map +1 -0
  87. package/build/_modules/discord-bot/_models/dibo-command.interface.js +3 -0
  88. package/build/_modules/discord-bot/_models/dibo-command.interface.js.map +1 -0
  89. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.d.ts +7 -0
  90. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.d.ts.map +1 -0
  91. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.js +3 -0
  92. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.js.map +1 -0
  93. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.d.ts +6 -0
  94. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.d.ts.map +1 -0
  95. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.js +3 -0
  96. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.js.map +1 -0
  97. package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.d.ts +88 -0
  98. package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.d.ts.map +1 -0
  99. package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.js +3 -0
  100. package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.js.map +1 -0
  101. package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts +12 -0
  102. package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts.map +1 -0
  103. package/build/_modules/discord-bot/_services/dibo-commands.control-service.js +72 -0
  104. package/build/_modules/discord-bot/_services/dibo-commands.control-service.js.map +1 -0
  105. package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts +19 -0
  106. package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts.map +1 -0
  107. package/build/_modules/discord-bot/_services/dibo-io.control-service.js +176 -0
  108. package/build/_modules/discord-bot/_services/dibo-io.control-service.js.map +1 -0
  109. package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts +85 -0
  110. package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts.map +1 -0
  111. package/build/_modules/discord-bot/_services/dibo-main.control-service.js +228 -0
  112. package/build/_modules/discord-bot/_services/dibo-main.control-service.js.map +1 -0
  113. package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts +13 -0
  114. package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts.map +1 -0
  115. package/build/_modules/discord-bot/_services/dibo-routines.control-service.js +38 -0
  116. package/build/_modules/discord-bot/_services/dibo-routines.control-service.js.map +1 -0
  117. package/build/_modules/discord-bot/index.d.ts +12 -0
  118. package/build/_modules/discord-bot/index.d.ts.map +1 -0
  119. package/build/_modules/discord-bot/index.js +30 -0
  120. package/build/_modules/discord-bot/index.js.map +1 -0
  121. package/build/_modules/oauth2/index.d.ts.map +1 -1
  122. package/build/_modules/oauth2/index.js +7 -0
  123. package/build/_modules/oauth2/index.js.map +1 -1
  124. package/build/_modules/open-ai/_collections/oai-chunking.util.d.ts +74 -0
  125. package/build/_modules/open-ai/_collections/oai-chunking.util.d.ts.map +1 -0
  126. package/build/_modules/open-ai/_collections/oai-chunking.util.js +385 -0
  127. package/build/_modules/open-ai/_collections/oai-chunking.util.js.map +1 -0
  128. package/build/_modules/open-ai/_collections/oai-document.util.d.ts +4 -0
  129. package/build/_modules/open-ai/_collections/oai-document.util.d.ts.map +1 -0
  130. package/build/_modules/open-ai/_collections/oai-document.util.js +12 -0
  131. package/build/_modules/open-ai/_collections/oai-document.util.js.map +1 -0
  132. package/build/_modules/open-ai/_collections/oai-global-settings.const.d.ts +3 -0
  133. package/build/_modules/open-ai/_collections/oai-global-settings.const.d.ts.map +1 -0
  134. package/build/_modules/open-ai/_collections/oai-global-settings.const.js +9 -0
  135. package/build/_modules/open-ai/_collections/oai-global-settings.const.js.map +1 -0
  136. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.d.ts +3 -0
  137. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.d.ts.map +1 -0
  138. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.js +75 -0
  139. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.js.map +1 -0
  140. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.d.ts +3 -0
  141. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.d.ts.map +1 -0
  142. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.js +68 -0
  143. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.js.map +1 -0
  144. package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.d.ts +6 -0
  145. package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.d.ts.map +1 -0
  146. package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.js +10 -0
  147. package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.js.map +1 -0
  148. package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.d.ts +18 -0
  149. package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.d.ts.map +1 -0
  150. package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.js +40 -0
  151. package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.js.map +1 -0
  152. package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.d.ts +7 -0
  153. package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.d.ts.map +1 -0
  154. package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.js +3 -0
  155. package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.js.map +1 -0
  156. package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.d.ts +15 -0
  157. package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.d.ts.map +1 -0
  158. package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.js +3 -0
  159. package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.js.map +1 -0
  160. package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.d.ts +6 -0
  161. package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.d.ts.map +1 -0
  162. package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.js +3 -0
  163. package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.js.map +1 -0
  164. package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.d.ts +6 -0
  165. package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.d.ts.map +1 -0
  166. package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js +3 -0
  167. package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js.map +1 -0
  168. package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.d.ts +52 -0
  169. package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.d.ts.map +1 -0
  170. package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.js +3 -0
  171. package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.js.map +1 -0
  172. package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.d.ts +13 -0
  173. package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.d.ts.map +1 -0
  174. package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.js +3 -0
  175. package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.js.map +1 -0
  176. package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.d.ts +18 -0
  177. package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.d.ts.map +1 -0
  178. package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.js +80 -0
  179. package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.js.map +1 -0
  180. package/build/_modules/open-ai/_services/oai-chunk.service-base.d.ts +13 -0
  181. package/build/_modules/open-ai/_services/oai-chunk.service-base.d.ts.map +1 -0
  182. package/build/_modules/open-ai/_services/oai-chunk.service-base.js +170 -0
  183. package/build/_modules/open-ai/_services/oai-chunk.service-base.js.map +1 -0
  184. package/build/_modules/open-ai/_services/{embedding.control-service.d.ts → oai-embedding.control-service.d.ts} +3 -3
  185. package/build/_modules/open-ai/_services/oai-embedding.control-service.d.ts.map +1 -0
  186. package/build/_modules/open-ai/_services/{embedding.control-service.js → oai-embedding.control-service.js} +5 -5
  187. package/build/_modules/open-ai/_services/oai-embedding.control-service.js.map +1 -0
  188. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +181 -0
  189. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts.map +1 -0
  190. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js +344 -0
  191. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js.map +1 -0
  192. package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts +234 -0
  193. package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts.map +1 -0
  194. package/build/_modules/open-ai/_services/oai-llm.service-base.js +441 -0
  195. package/build/_modules/open-ai/_services/oai-llm.service-base.js.map +1 -0
  196. package/build/_modules/open-ai/_services/{vector-data.service.d.ts → oai-vector-data.service.d.ts} +4 -4
  197. package/build/_modules/open-ai/_services/oai-vector-data.service.d.ts.map +1 -0
  198. package/build/_modules/open-ai/_services/{vector-data.service.js → oai-vector-data.service.js} +27 -7
  199. package/build/_modules/open-ai/_services/oai-vector-data.service.js.map +1 -0
  200. package/build/_modules/open-ai/index.d.ts +19 -4
  201. package/build/_modules/open-ai/index.d.ts.map +1 -1
  202. package/build/_modules/open-ai/index.js +36 -4
  203. package/build/_modules/open-ai/index.js.map +1 -1
  204. package/build/_modules/server/index.d.ts +1 -1
  205. package/build/_modules/server/index.d.ts.map +1 -1
  206. package/build/_modules/server/index.js +16 -2
  207. package/build/_modules/server/index.js.map +1 -1
  208. package/build/_modules/server/server-status/server-status.controller.d.ts.map +1 -1
  209. package/build/_modules/server/server-status/server-status.controller.js +10 -0
  210. package/build/_modules/server/server-status/server-status.controller.js.map +1 -1
  211. package/build/_modules/socket/index.d.ts.map +1 -1
  212. package/build/_modules/socket/index.js +18 -0
  213. package/build/_modules/socket/index.js.map +1 -1
  214. package/build/_modules/test/index.d.ts.map +1 -1
  215. package/build/_modules/test/index.js +5 -0
  216. package/build/_modules/test/index.js.map +1 -1
  217. package/build/_modules/usage/index.d.ts.map +1 -1
  218. package/build/_modules/usage/index.js +5 -0
  219. package/build/_modules/usage/index.js.map +1 -1
  220. package/build/_services/base/data.service.d.ts +6 -0
  221. package/build/_services/base/data.service.d.ts.map +1 -1
  222. package/build/_services/base/data.service.js +6 -0
  223. package/build/_services/base/data.service.js.map +1 -1
  224. package/build/_services/base/db.service.d.ts +10 -0
  225. package/build/_services/base/db.service.d.ts.map +1 -1
  226. package/build/_services/base/db.service.js +10 -0
  227. package/build/_services/base/db.service.js.map +1 -1
  228. package/build/_services/server/app.server.js +1 -2
  229. package/build/_services/server/app.server.js.map +1 -1
  230. package/build/index.d.ts +3 -1
  231. package/build/index.d.ts.map +1 -1
  232. package/build/index.js +26 -1
  233. package/build/index.js.map +1 -1
  234. package/package.json +40 -10
  235. package/src/_collections/atlas-default-db-options.const.ts +10 -0
  236. package/src/_collections/get-environment-settings.util.ts +49 -0
  237. package/src/_collections/global-settings.const.ts +15 -4
  238. package/src/_collections/sample.env +21 -0
  239. package/src/_models/control-models/app-params.control-model.spec.ts +5 -4
  240. package/src/_models/control-models/app-params.control-model.ts +31 -2
  241. package/src/_models/control-models/endpoint-params.control-model.ts +1 -1
  242. package/src/_models/interfaces/environment-settings.interface.ts +59 -0
  243. package/src/_models/interfaces/global-settings.interface.ts +41 -1
  244. package/src/_modules/custom-data/index.ts +3 -0
  245. package/src/_modules/discord-assistant/_collections/dias-global-settings.const.ts +19 -0
  246. package/src/_modules/discord-assistant/_collections/dias.util.ts +43 -0
  247. package/src/_modules/discord-assistant/_models/dias-global-settings.interface.ts +20 -0
  248. package/src/_modules/discord-assistant/_models/dias-knowledge.data-model.ts +46 -0
  249. package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +152 -0
  250. package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +64 -0
  251. package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +28 -0
  252. package/src/_modules/discord-assistant/_services/dias.service-base.ts +49 -0
  253. package/src/_modules/discord-assistant/index.ts +36 -0
  254. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.ts +11 -0
  255. package/src/_modules/discord-assistant-voiced/index.ts +36 -0
  256. package/src/_modules/discord-bot/_collections/dibo-default-commands.const.ts +17 -0
  257. package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +56 -0
  258. package/src/_modules/discord-bot/_collections/dibo-operations.util.ts +372 -0
  259. package/src/_modules/discord-bot/_models/dibo-command.interface.ts +12 -0
  260. package/src/_modules/discord-bot/_models/dibo-last-mention-date.inteface.ts +8 -0
  261. package/src/_modules/discord-bot/_models/dibo-last-message-date.interface.ts +6 -0
  262. package/src/_modules/discord-bot/_models/global-bot-log-settings.interface.ts +98 -0
  263. package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +120 -0
  264. package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +245 -0
  265. package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +304 -0
  266. package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +60 -0
  267. package/src/_modules/discord-bot/index.ts +36 -0
  268. package/src/_modules/oauth2/index.ts +8 -0
  269. package/src/_modules/open-ai/_collections/oai-chunking.util.ts +496 -0
  270. package/src/_modules/open-ai/_collections/oai-document.util.ts +10 -0
  271. package/src/_modules/open-ai/_collections/oai-global-settings.const.ts +9 -0
  272. package/src/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.ts +83 -0
  273. package/src/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.ts +76 -0
  274. package/src/_modules/open-ai/_enums/oai-compare-result-type.enum.ts +7 -0
  275. package/src/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +45 -0
  276. package/src/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.ts +10 -0
  277. package/src/_modules/open-ai/_models/interfaces/oai-document-page.interface.ts +21 -0
  278. package/src/_modules/open-ai/_models/interfaces/oai-global-settings.interface.ts +8 -0
  279. package/src/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +7 -0
  280. package/src/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.ts +57 -0
  281. package/src/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.ts +18 -0
  282. package/src/_modules/open-ai/_models/oai-doc-chunk.data-model.ts +92 -0
  283. package/src/_modules/open-ai/_services/oai-chunk.service-base.ts +214 -0
  284. package/src/_modules/open-ai/_services/{embedding.control-service.ts → oai-embedding.control-service.ts} +2 -2
  285. package/src/_modules/open-ai/_services/oai-llm-chat.service-base.ts +621 -0
  286. package/src/_modules/open-ai/_services/oai-llm.service-base.ts +651 -0
  287. package/src/_modules/open-ai/_services/{vector-data.service.ts → oai-vector-data.service.ts} +32 -5
  288. package/src/_modules/open-ai/index.ts +43 -4
  289. package/src/_modules/server/index.ts +18 -2
  290. package/src/_modules/server/server-status/server-status.controller.ts +13 -0
  291. package/src/_modules/socket/index.ts +23 -0
  292. package/src/_modules/test/index.ts +8 -0
  293. package/src/_modules/usage/index.ts +8 -0
  294. package/src/_services/base/data.service.ts +6 -0
  295. package/src/_services/base/db.service.ts +10 -0
  296. package/src/_services/server/app.server.ts +1 -1
  297. package/src/index.ts +28 -1
  298. package/build/_modules/open-ai/_services/embedding.control-service.d.ts.map +0 -1
  299. package/build/_modules/open-ai/_services/embedding.control-service.js.map +0 -1
  300. package/build/_modules/open-ai/_services/gpt.service-base.d.ts +0 -98
  301. package/build/_modules/open-ai/_services/gpt.service-base.d.ts.map +0 -1
  302. package/build/_modules/open-ai/_services/gpt.service-base.js +0 -284
  303. package/build/_modules/open-ai/_services/gpt.service-base.js.map +0 -1
  304. package/build/_modules/open-ai/_services/open-ai.service-base.d.ts +0 -21
  305. package/build/_modules/open-ai/_services/open-ai.service-base.d.ts.map +0 -1
  306. package/build/_modules/open-ai/_services/open-ai.service-base.js +0 -50
  307. package/build/_modules/open-ai/_services/open-ai.service-base.js.map +0 -1
  308. package/build/_modules/open-ai/_services/vector-data.service.d.ts.map +0 -1
  309. package/build/_modules/open-ai/_services/vector-data.service.js.map +0 -1
  310. package/build/_services/server/env-set.d.ts +0 -2
  311. package/build/_services/server/env-set.d.ts.map +0 -1
  312. package/build/_services/server/env-set.js +0 -20
  313. package/build/_services/server/env-set.js.map +0 -1
  314. package/src/_modules/open-ai/_services/gpt.service-base.ts +0 -438
  315. package/src/_modules/open-ai/_services/open-ai.service-base.ts +0 -69
  316. package/src/_services/server/env-set.ts +0 -21
@@ -0,0 +1,621 @@
1
+ import { OpenAI } from 'openai';
2
+
3
+ import { DyFM_OpenAI_Settings, DyFM_OpenAIModel, DyFM_GPTCall_Settings } from '@futdevpro/fsm-dynamo/open-ai';
4
+ import { DyFM_AnyError, DyFM_clone, DyFM_Error, DyFM_Error_Settings, DyFM_Log, DyFM_notNull } from '@futdevpro/fsm-dynamo';
5
+
6
+ import { DyNTS_global_settings } from '../../../_collections/global-settings.const';
7
+ import { DyNTS_OAI_GPT_Message } from '../_models/interfaces/oai-gpt-message.interface';
8
+ import { ChatCompletion } from 'openai/resources';
9
+ import { ChatCompletionCreateParamsBase, ChatCompletionMessageParam } from 'openai/resources/chat/completions';
10
+ import { DyNTS_OAI_GPT_Message_Role } from '../_enums/oai-gpt-message-role.enum';
11
+ import { DyNTS_OAI_LLM_Predefined_Requests } from '../_models/interfaces/oai-llm-predefined-requests.interface';
12
+ import { DyFM_safeParseJSON, DyFM_safeParseList, DyNTS_OAI_LLM_ServiceBase } from './oai-llm.service-base';
13
+ import { DyNTS_OAI_global_settings } from '../_collections/oai-global-settings.const';
14
+
15
+
16
+ /**
17
+ * {
18
+ * organization: 'org-XY',
19
+ * apiKey: 'sk-XY',
20
+ * project: 'proj_XY',
21
+ * }
22
+ */
23
+
24
+ // Di Dictionary DiModel DiEz DiAz
25
+
26
+ export class DyNTS_OAI_LLMChat_ServiceBase extends DyNTS_OAI_LLM_ServiceBase {
27
+
28
+ /**
29
+ * Asks the AI to answer a yes/no question
30
+ *
31
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.request} to ask the question,
32
+ * and the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.upperCaseYes} to check the answer
33
+ */
34
+ async yesNoQuestionInConversation(
35
+ conversation: DyNTS_OAI_GPT_Message[],
36
+ question: string,
37
+ issuer: string,
38
+ debugLog?: boolean,
39
+ settings?: DyFM_GPTCall_Settings,
40
+ /** this is used to readably replace too long contents to eg '...' in logs */
41
+ replaceThisInLog?: string
42
+ ): Promise<boolean> {
43
+ question += this.predefinedRequests.yesNo.request;
44
+
45
+ this.logQuestion(question, replaceThisInLog, debugLog);
46
+
47
+ const answer = await this.getAnswerInConversation(
48
+ conversation,
49
+ question,
50
+ issuer,
51
+ settings,
52
+ debugLog,
53
+ replaceThisInLog
54
+ );
55
+
56
+ return answer.toUpperCase().includes(this.predefinedRequests.yesNo.upperCaseYes);
57
+ }
58
+ askYesNoQuestionInConversation = this.yesNoQuestionInConversation;
59
+
60
+ /**
61
+ * Asks the AI to answer a simple question
62
+ *
63
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.simpleQuestion} to ask the question
64
+ */
65
+ async simpleQuestionInConversation(
66
+ conversation: DyNTS_OAI_GPT_Message[],
67
+ question: string,
68
+ issuer: string,
69
+ settings?: DyFM_GPTCall_Settings,
70
+ debugLog?: boolean,
71
+ /** this is used to readably replace too long contents to eg '...' in logs */
72
+ replaceThisInLog?: string
73
+ ): Promise<string> {
74
+ this.logQuestion(question, replaceThisInLog, debugLog);
75
+
76
+ return await this.getAnswerInConversation(
77
+ conversation,
78
+ question,
79
+ issuer,
80
+ settings,
81
+ debugLog,
82
+ replaceThisInLog
83
+ );
84
+ }
85
+ askSimpleQuestionInConversation = this.simpleQuestionInConversation;
86
+
87
+ /**
88
+ * Asks the AI to answer a percentage question
89
+ *
90
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.percentageOnly} to ask the question
91
+ */
92
+ async percentageQuestionInConversation(
93
+ conversation: DyNTS_OAI_GPT_Message[],
94
+ question: string,
95
+ issuer: string,
96
+ settings?: DyFM_GPTCall_Settings,
97
+ debugLog?: boolean,
98
+ /** this is used to readably replace too long contents to eg '...' in logs */
99
+ replaceThisInLog?: string
100
+ ): Promise<number> {
101
+ question += this.predefinedRequests.percentageOnly;
102
+
103
+ this.logQuestion(question, replaceThisInLog, debugLog);
104
+
105
+ const answer = await this.getAnswerInConversation(
106
+ conversation,
107
+ question,
108
+ issuer,
109
+ settings,
110
+ debugLog,
111
+ replaceThisInLog
112
+ );
113
+
114
+ if (isNaN(+answer)) {
115
+ DyFM_Log.error('GPT_ServiceBase', 'asykPercentageQuestion', 'Invalid answer', {
116
+ question,
117
+ answer,
118
+ });
119
+
120
+ return null;
121
+ }
122
+
123
+ return +answer;
124
+ }
125
+ askPercentageQuestionInConversation = this.percentageQuestionInConversation;
126
+
127
+
128
+ /**
129
+ * Asks the AI to select one of the options from the list
130
+ *
131
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
132
+ */
133
+ async selectQuestionInConversation(
134
+ conversation: DyNTS_OAI_GPT_Message[],
135
+ question: string,
136
+ selectFrom: string[],
137
+ issuer: string,
138
+ settings?: DyFM_GPTCall_Settings,
139
+ debugLog?: boolean,
140
+ /** this is used to readably replace too long contents to eg '...' in logs */
141
+ replaceThisInLog?: string
142
+ ): Promise<string> {
143
+ // replace the {{DyNTS_selectOptions}} with the list of options
144
+ const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
145
+ '{{DyNTS_selectOptions}}',
146
+ this.getTextListAsText(selectFrom)
147
+ );
148
+ question += selectQuestionAddition;
149
+
150
+ this.logQuestion(question, replaceThisInLog, debugLog);
151
+
152
+ let answer = await this.getAnswerInConversation(
153
+ conversation,
154
+ question,
155
+ issuer,
156
+ settings,
157
+ debugLog,
158
+ replaceThisInLog
159
+ );
160
+
161
+ answer = answer.toLocaleUpperCase();
162
+
163
+ for (const item of selectFrom) {
164
+ if (answer.includes(item.toLocaleUpperCase())) return item;
165
+ }
166
+
167
+ return null;
168
+ }
169
+ askSelectQuestionInConversation = this.selectQuestionInConversation;
170
+
171
+ /**
172
+ * Asks the AI to select one of the options from the list
173
+ * Similar to {@link askSelectQuestion},
174
+ * but with a more generic approach that can be used for objects
175
+ *
176
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
177
+ */
178
+ async requestSelectInConversation<T>(
179
+ conversation: DyNTS_OAI_GPT_Message[],
180
+ question: string,
181
+ selectFrom: T[],
182
+ issuer: string,
183
+ settings?: DyFM_GPTCall_Settings,
184
+ debugLog?: boolean,
185
+ /** this is used to readably replace too long contents to eg '...' in logs */
186
+ replaceThisInLog?: string,
187
+ ): Promise<T | { unparsableResult: string }> {
188
+ const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
189
+ '{{DyNTS_selectOptions}}',
190
+ this.getTextListAsText(selectFrom.map(item => `"${JSON.stringify(item)}"`))
191
+ );
192
+ question += selectQuestionAddition;
193
+
194
+ this.logQuestion(question, null, debugLog);
195
+
196
+ const answer = await this.getAnswerInConversation(
197
+ conversation,
198
+ question,
199
+ issuer,
200
+ settings,
201
+ debugLog,
202
+ replaceThisInLog
203
+ );
204
+
205
+ return DyFM_safeParseJSON<T>(answer);
206
+ }
207
+ askRequestSelectInConversation = this.requestSelectInConversation;
208
+
209
+ /**
210
+ * Asks the AI to select one or more of the options from the list
211
+ *
212
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
213
+ */
214
+ async multipleSelectQuestionWithOptionsInConversation(
215
+ conversation: DyNTS_OAI_GPT_Message[],
216
+ question: string,
217
+ options: string[],
218
+ issuer: string,
219
+ settings?: DyFM_GPTCall_Settings,
220
+ debugLog?: boolean,
221
+ /** this is used to readably replace too long contents to eg '...' in logs */
222
+ replaceThisInLog?: string
223
+ ): Promise<string[]> {
224
+ const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
225
+ '{{DyNTS_selectOptions}}',
226
+ this.getTextListAsText(options)
227
+ );
228
+ question += selectQuestionAddition;
229
+
230
+ let answer = await this.getAnswerInConversation(
231
+ conversation,
232
+ question,
233
+ issuer,
234
+ settings,
235
+ debugLog,
236
+ replaceThisInLog
237
+ );
238
+
239
+ answer = answer.toLocaleUpperCase();
240
+
241
+ const result: string[] = [];
242
+
243
+ for (const item of options) {
244
+ if (answer.includes(item.toLocaleUpperCase())) {
245
+ result.push(item);
246
+ }
247
+ }
248
+
249
+ return result;
250
+ }
251
+ askMultipleSelectQuestionWithOptionsInConversation = this.multipleSelectQuestionWithOptionsInConversation;
252
+
253
+ /**
254
+ * Asks the AI to select one or more of the options from the list
255
+ * Similar to {@link askMultipleSelectQuestionWithOptions},
256
+ * but with a more generic approach that can be used for objects
257
+ *
258
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
259
+ */
260
+ async requestMultipleSelectInConversation<T>(
261
+ conversation: DyNTS_OAI_GPT_Message[],
262
+ question: string,
263
+ options: T[],
264
+ issuer: string,
265
+ settings?: DyFM_GPTCall_Settings,
266
+ debugLog?: boolean,
267
+ /** this is used to readably replace too long contents to eg '...' in logs */
268
+ replaceThisInLog?: string,
269
+ ): Promise<T[]> {
270
+ const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
271
+ '{{DyNTS_selectOptions}}',
272
+ this.getTextListAsText(options.map(item => `"${JSON.stringify(item)}"`))
273
+ );
274
+ question += selectQuestionAddition;
275
+
276
+ this.logQuestion(question, null, debugLog);
277
+
278
+ const answer = await this.getAnswerInConversation(
279
+ conversation,
280
+ question,
281
+ issuer,
282
+ settings,
283
+ debugLog,
284
+ replaceThisInLog
285
+ );
286
+
287
+ return DyFM_safeParseList<T[]>(answer);
288
+ }
289
+ askRequestMultipleSelectInConversation = this.requestMultipleSelectInConversation;
290
+
291
+ /**
292
+ * Asks the AI to answer a question that must result a JSON object
293
+ *
294
+ * If the answer is not a valid JSON object, it will return { unparsableResult: answer }
295
+ *
296
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.jsonRequest} to ask the question
297
+ *
298
+ * (uses {@link DyFM_safeParseJSON})
299
+ */
300
+ async jsonQuestionInConversation<T = any>(
301
+ conversation: DyNTS_OAI_GPT_Message[],
302
+ question: string,
303
+ issuer: string,
304
+ settings?: DyFM_GPTCall_Settings,
305
+ debugLog?: boolean,
306
+ /** this is used to readably replace too long contents to eg '...' in logs */
307
+ replaceThisInLog?: string
308
+ ): Promise<T | { unparsableResult: string }> {
309
+ question += this.predefinedRequests.jsonRequest;
310
+
311
+ this.logQuestion(question, replaceThisInLog, debugLog);
312
+
313
+ const answer = await this.getAnswerInConversation(
314
+ conversation,
315
+ question,
316
+ issuer,
317
+ settings,
318
+ debugLog,
319
+ replaceThisInLog
320
+ );
321
+
322
+ return DyFM_safeParseJSON<T>(answer);
323
+ }
324
+ askJsonQuestionInConversation = this.jsonQuestionInConversation;
325
+
326
+ /**
327
+ * Asks the AI to answer a question that must result a JSON object with specific key descriptions
328
+ *
329
+ * If the answer is not a valid JSON object, it will return { unparsableResult: answer }
330
+ *
331
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.jsonRequestWithKeysDescription} to ask the question
332
+ *
333
+ * (uses {@link DyFM_safeParseJSON})
334
+ */
335
+ async jsonQuestionWithKeysDescriptionInConversation<T = any>(
336
+ conversation: DyNTS_OAI_GPT_Message[],
337
+ question: string,
338
+ keysDescription: string,
339
+ issuer: string,
340
+ settings?: DyFM_GPTCall_Settings,
341
+ debugLog?: boolean,
342
+ /** this is used to readably replace too long contents to eg '...' in logs */
343
+ replaceThisInLog?: string
344
+ ): Promise<T | { unparsableResult: string }> {
345
+ const jsonRequestWithKeysDescription = this.predefinedRequests.jsonRequestWithKeysDescription.replace(
346
+ '{{DyNTS_jsonKeysDescription}}',
347
+ keysDescription
348
+ );
349
+ question += jsonRequestWithKeysDescription;
350
+
351
+ this.logQuestion(question, replaceThisInLog, debugLog);
352
+
353
+ const answer = await this.getAnswerInConversation(
354
+ conversation,
355
+ question,
356
+ issuer,
357
+ settings,
358
+ debugLog,
359
+ replaceThisInLog
360
+ );
361
+
362
+ return DyFM_safeParseJSON<T>(answer);
363
+ }
364
+ askJsonQuestionWithKeysDescriptionInConversation = this.jsonQuestionWithKeysDescriptionInConversation;
365
+
366
+ /**
367
+ * Asks the AI to answer a question that must result a JSON object with specific keys
368
+ *
369
+ * If the answer is not a valid JSON object, it will return { unparsableResult: answer }
370
+ *
371
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.jsonRequestWithExactKeys} to ask the question
372
+ *
373
+ * (uses {@link DyFM_safeParseJSON})
374
+ */
375
+ async jsonQuestionWithExactKeysInConversation<T = any>(
376
+ conversation: DyNTS_OAI_GPT_Message[],
377
+ question: string,
378
+ keys: string[],
379
+ issuer: string,
380
+ settings?: DyFM_GPTCall_Settings,
381
+ debugLog?: boolean,
382
+ /** this is used to readably replace too long contents to eg '...' in logs */
383
+ replaceThisInLog?: string
384
+ ): Promise<T | { unparsableResult: string }> {
385
+ const jsonRequestWithExactKeys = this.predefinedRequests.jsonRequestWithExactKeys.replace(
386
+ '{{DyNTS_jsonKeys}}',
387
+ this.getTextListAsText(keys)
388
+ );
389
+ question += jsonRequestWithExactKeys;
390
+
391
+ this.logQuestion(question, replaceThisInLog, debugLog);
392
+
393
+ const answer = await this.getAnswerInConversation(
394
+ conversation,
395
+ question,
396
+ issuer,
397
+ settings,
398
+ debugLog,
399
+ replaceThisInLog
400
+ );
401
+
402
+ return DyFM_safeParseJSON<T>(answer);
403
+ }
404
+ askJsonQuestionWithExactKeysInConversation = this.jsonQuestionWithExactKeysInConversation;
405
+
406
+ /**
407
+ * Asks the AI to answer a question that must result a list of strings
408
+ *
409
+ * If the answer is not a valid JSON list, it will return the answer as a single item in an array
410
+ *
411
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.listRequest} to ask the question
412
+ *
413
+ * (uses {@link DyFM_safeParseList})
414
+ */
415
+ async listQuestionInConversation(
416
+ conversation: DyNTS_OAI_GPT_Message[],
417
+ question: string,
418
+ issuer: string,
419
+ settings?: DyFM_GPTCall_Settings,
420
+ debugLog?: boolean,
421
+ /** this is used to readably replace too long contents to eg '...' in logs */
422
+ replaceThisInLog?: string,
423
+ ): Promise<string[]> {
424
+ question += this.predefinedRequests.listRequest;
425
+
426
+ this.logQuestion(question, replaceThisInLog, debugLog);
427
+
428
+ const answer = await this.getAnswerInConversation(
429
+ conversation,
430
+ question,
431
+ issuer,
432
+ settings,
433
+ debugLog,
434
+ replaceThisInLog
435
+ );
436
+
437
+ return DyFM_safeParseList(answer);
438
+ }
439
+ askListQuestionInConversation = this.listQuestionInConversation;
440
+
441
+ /**
442
+ * Asks the AI to answer a question
443
+ *
444
+ * Uses the {@link resolveSimpleUserMessage}
445
+ */
446
+ /* async getQuestionAnswerInConversation(
447
+ conversation: DyNTS_OAI_GPT_Message[],
448
+ question: string,
449
+ issuer: string,
450
+ debugLog?: boolean,
451
+ messageSettings: DyFM_GPTCall_Settings = this.defaultSettings
452
+ ): Promise<string> {
453
+ const answer = await this.resolveSimpleUserMessageInConversation(
454
+ conversation,
455
+ question,
456
+ issuer,
457
+ messageSettings,
458
+ ) as Promise<string>;
459
+
460
+ if (debugLog) {
461
+ console.log(' - ', answer);
462
+ }
463
+
464
+ return answer;
465
+ } */
466
+
467
+ /**
468
+ * Asks the AI to answer a question using the whole conversation
469
+ * (If you want to use only the conversation, without adding a new message,
470
+ * use directly the {@link resolveConversation})
471
+ *
472
+ * Uses the {@link resolveConversation}
473
+ */
474
+ async getAnswerInConversation(
475
+ conversation: DyNTS_OAI_GPT_Message[],
476
+ newMessage: string,
477
+ issuer: string,
478
+ settings?: DyFM_GPTCall_Settings,
479
+ debugLog?: boolean,
480
+ /** this is used to readably replace too long contents to eg '...' in logs */
481
+ replaceThisInLog?: string,
482
+ ): Promise<string> {
483
+ conversation.push({
484
+ role: DyNTS_OAI_GPT_Message_Role.user,
485
+ content: newMessage,
486
+ });
487
+
488
+ const answer: string = (await this.resolveConversation(
489
+ conversation,
490
+ issuer,
491
+ settings,
492
+ false,
493
+ debugLog,
494
+ replaceThisInLog,
495
+ )) as string;
496
+
497
+ if (debugLog || this.debugLog) {
498
+ console.log(' - answer: ', answer);
499
+ }
500
+
501
+ return answer;
502
+ }
503
+ getQuestionAnswerInConversation = this.getAnswerInConversation;
504
+ getQuestionInConversation = this.getAnswerInConversation;
505
+ askQuestionInConversation = this.getAnswerInConversation;
506
+
507
+ /**
508
+ * Resolves a conversation
509
+ *
510
+ * Uses the {@link getMessageCreateInput}
511
+ */
512
+ async resolveConversation(
513
+ conversation: DyNTS_OAI_GPT_Message[],
514
+ issuer: string,
515
+ settings?: DyFM_GPTCall_Settings,
516
+ getFullResponse?: boolean,
517
+ debugLog?: boolean,
518
+ /** this is used to readably replace too long contents to eg '...' in logs */
519
+ replaceThisInLog?: string,
520
+ ): Promise<string | ChatCompletion> {
521
+ try {
522
+ conversation.unshift(this.getDefaultSystemMessage(settings));
523
+
524
+ // conversation shortening
525
+ const shortenedConversation = this.shortenConversation(conversation, issuer, debugLog);
526
+
527
+ this.logConversation(shortenedConversation, debugLog, replaceThisInLog);
528
+
529
+ const result: ChatCompletion = await this.openai.chat.completions.create(
530
+ this.getMessageCreateInput(shortenedConversation, issuer, settings)
531
+ ) as ChatCompletion;
532
+
533
+ if (getFullResponse) {
534
+ return result;
535
+ }
536
+
537
+ return result.choices[0].message.content;
538
+ } catch (error) {
539
+ throw new DyFM_Error({
540
+ ...this.getDefaultErrorSettings('resolveConversation', error, issuer),
541
+
542
+ errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-OAB-RC0`,
543
+ });
544
+ }
545
+ }
546
+ resolveSimpleUserMessageInConversation = this.resolveConversation;
547
+
548
+ protected shortenConversation(
549
+ conversation: DyNTS_OAI_GPT_Message[],
550
+ issuer: string,
551
+ debugLog?: boolean,
552
+ ): DyNTS_OAI_GPT_Message[] {
553
+ try {
554
+ const clonedConversation = DyFM_clone(conversation);
555
+ const systemMessages = clonedConversation.filter(
556
+ message => message.role === DyNTS_OAI_GPT_Message_Role.system
557
+ );
558
+ const systemMessagesStringLength = JSON.stringify(systemMessages).length;
559
+ const msgs: string[] = clonedConversation.filter(
560
+ message => message.role !== DyNTS_OAI_GPT_Message_Role.system
561
+ ).map(message => message.content);
562
+ let stringifiedMessages = JSON.stringify(msgs);
563
+
564
+ if (this.debugLog || debugLog) {
565
+ console.log('stringifiedMessagesCount before removing', stringifiedMessages.length);
566
+ }
567
+
568
+ let removedMessagesCount = 0;
569
+ let lastStringifiedMessagesLength = stringifiedMessages.length;
570
+
571
+ while (
572
+ (stringifiedMessages.length + systemMessagesStringLength) > DyNTS_OAI_global_settings.maxMessagesStringLength &&
573
+ clonedConversation.length > 1
574
+ ) {
575
+ clonedConversation.splice(0, 1);
576
+ msgs.splice(0, 1);
577
+ removedMessagesCount++;
578
+ stringifiedMessages = JSON.stringify(msgs);
579
+ lastStringifiedMessagesLength = stringifiedMessages.length;
580
+ }
581
+
582
+ if (this.debugLog || debugLog) {
583
+ console.log('removedMessagesCount', removedMessagesCount);
584
+ console.log('lastStringifiedMessagesLength', lastStringifiedMessagesLength);
585
+ }
586
+
587
+ if (!clonedConversation.length) {
588
+ DyFM_Log.error('No conversation messages (left)', {
589
+ /* conversation: DyFM_clone(conversation), */
590
+ conversationLength: conversation.length,
591
+ clonedConversation: DyFM_clone(clonedConversation),
592
+ });
593
+ throw new Error('No conversation messages (left)');
594
+ }
595
+
596
+ return [ ...systemMessages, ...clonedConversation ];
597
+ } catch (error) {
598
+ console.error('❌❌ Error shortening conversation:', error);
599
+ throw new DyFM_Error({
600
+ ...this.getDefaultErrorSettings('shortenConversation', error, issuer),
601
+
602
+ errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-OAB-SC0`,
603
+ });
604
+ }
605
+ }
606
+
607
+ protected logConversation(
608
+ conversation: DyNTS_OAI_GPT_Message[],
609
+ debugLog?: boolean,
610
+ /** this is used to readably replace too long contents to eg '...' in logs */
611
+ replaceThisInLog?: string,
612
+ ) {
613
+ if (debugLog || this.debugLog) {
614
+ conversation.forEach(message => {
615
+ console.log(
616
+ ` - ${message.role}: ${message.content.replace(replaceThisInLog, this.defaultLogReplacer)}`
617
+ );
618
+ });
619
+ }
620
+ }
621
+ }