@futdevpro/nts-dynamo 1.10.77 → 1.11.1

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 (301) 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/_models/dias-global-settings.interface.d.ts +18 -0
  34. package/build/_modules/discord-assistant/_models/dias-global-settings.interface.d.ts.map +1 -0
  35. package/build/_modules/discord-assistant/_models/dias-global-settings.interface.js +3 -0
  36. package/build/_modules/discord-assistant/_models/dias-global-settings.interface.js.map +1 -0
  37. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.d.ts +10 -0
  38. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.d.ts.map +1 -0
  39. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.js +41 -0
  40. package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.js.map +1 -0
  41. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts +14 -0
  42. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts.map +1 -0
  43. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +88 -0
  44. package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js.map +1 -0
  45. package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts +10 -0
  46. package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts.map +1 -0
  47. package/build/_modules/discord-assistant/_services/dias-io.control-service.js +39 -0
  48. package/build/_modules/discord-assistant/_services/dias-io.control-service.js.map +1 -0
  49. package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts +8 -0
  50. package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts.map +1 -0
  51. package/build/_modules/discord-assistant/_services/dias-main.control-service.js +23 -0
  52. package/build/_modules/discord-assistant/_services/dias-main.control-service.js.map +1 -0
  53. package/build/_modules/discord-assistant/_services/dias.service-base.d.ts +13 -0
  54. package/build/_modules/discord-assistant/_services/dias.service-base.d.ts.map +1 -0
  55. package/build/_modules/discord-assistant/_services/dias.service-base.js +61 -0
  56. package/build/_modules/discord-assistant/_services/dias.service-base.js.map +1 -0
  57. package/build/_modules/discord-assistant/index.d.ts +10 -0
  58. package/build/_modules/discord-assistant/index.d.ts.map +1 -0
  59. package/build/_modules/discord-assistant/index.js +23 -0
  60. package/build/_modules/discord-assistant/index.js.map +1 -0
  61. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.d.ts +4 -0
  62. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.d.ts.map +1 -0
  63. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.js +8 -0
  64. package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.js.map +1 -0
  65. package/build/_modules/discord-assistant-voiced/index.d.ts +3 -0
  66. package/build/_modules/discord-assistant-voiced/index.d.ts.map +1 -0
  67. package/build/_modules/discord-assistant-voiced/index.js +26 -0
  68. package/build/_modules/discord-assistant-voiced/index.js.map +1 -0
  69. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.d.ts +3 -0
  70. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.d.ts.map +1 -0
  71. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.js +13 -0
  72. package/build/_modules/discord-bot/_collections/dibo-default-commands.const.js.map +1 -0
  73. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts +3 -0
  74. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts.map +1 -0
  75. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.js +44 -0
  76. package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.js.map +1 -0
  77. package/build/_modules/discord-bot/_collections/dibo-operations.util.d.ts +22 -0
  78. package/build/_modules/discord-bot/_collections/dibo-operations.util.d.ts.map +1 -0
  79. package/build/_modules/discord-bot/_collections/dibo-operations.util.js +261 -0
  80. package/build/_modules/discord-bot/_collections/dibo-operations.util.js.map +1 -0
  81. package/build/_modules/discord-bot/_models/dibo-command.interface.d.ts +8 -0
  82. package/build/_modules/discord-bot/_models/dibo-command.interface.d.ts.map +1 -0
  83. package/build/_modules/discord-bot/_models/dibo-command.interface.js +3 -0
  84. package/build/_modules/discord-bot/_models/dibo-command.interface.js.map +1 -0
  85. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.d.ts +7 -0
  86. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.d.ts.map +1 -0
  87. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.js +3 -0
  88. package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.js.map +1 -0
  89. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.d.ts +6 -0
  90. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.d.ts.map +1 -0
  91. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.js +3 -0
  92. package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.js.map +1 -0
  93. package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.d.ts +88 -0
  94. package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.d.ts.map +1 -0
  95. package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.js +3 -0
  96. package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.js.map +1 -0
  97. package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts +12 -0
  98. package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts.map +1 -0
  99. package/build/_modules/discord-bot/_services/dibo-commands.control-service.js +72 -0
  100. package/build/_modules/discord-bot/_services/dibo-commands.control-service.js.map +1 -0
  101. package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts +19 -0
  102. package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts.map +1 -0
  103. package/build/_modules/discord-bot/_services/dibo-io.control-service.js +176 -0
  104. package/build/_modules/discord-bot/_services/dibo-io.control-service.js.map +1 -0
  105. package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts +85 -0
  106. package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts.map +1 -0
  107. package/build/_modules/discord-bot/_services/dibo-main.control-service.js +228 -0
  108. package/build/_modules/discord-bot/_services/dibo-main.control-service.js.map +1 -0
  109. package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts +13 -0
  110. package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts.map +1 -0
  111. package/build/_modules/discord-bot/_services/dibo-routines.control-service.js +38 -0
  112. package/build/_modules/discord-bot/_services/dibo-routines.control-service.js.map +1 -0
  113. package/build/_modules/discord-bot/index.d.ts +12 -0
  114. package/build/_modules/discord-bot/index.d.ts.map +1 -0
  115. package/build/_modules/discord-bot/index.js +30 -0
  116. package/build/_modules/discord-bot/index.js.map +1 -0
  117. package/build/_modules/oauth2/index.d.ts.map +1 -1
  118. package/build/_modules/oauth2/index.js +7 -0
  119. package/build/_modules/oauth2/index.js.map +1 -1
  120. package/build/_modules/open-ai/_collections/oai-chunking.util.d.ts +74 -0
  121. package/build/_modules/open-ai/_collections/oai-chunking.util.d.ts.map +1 -0
  122. package/build/_modules/open-ai/_collections/oai-chunking.util.js +385 -0
  123. package/build/_modules/open-ai/_collections/oai-chunking.util.js.map +1 -0
  124. package/build/_modules/open-ai/_collections/oai-document.util.d.ts +4 -0
  125. package/build/_modules/open-ai/_collections/oai-document.util.d.ts.map +1 -0
  126. package/build/_modules/open-ai/_collections/oai-document.util.js +12 -0
  127. package/build/_modules/open-ai/_collections/oai-document.util.js.map +1 -0
  128. package/build/_modules/open-ai/_collections/oai-global-settings.const.d.ts +3 -0
  129. package/build/_modules/open-ai/_collections/oai-global-settings.const.d.ts.map +1 -0
  130. package/build/_modules/open-ai/_collections/oai-global-settings.const.js +9 -0
  131. package/build/_modules/open-ai/_collections/oai-global-settings.const.js.map +1 -0
  132. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.d.ts +3 -0
  133. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.d.ts.map +1 -0
  134. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.js +75 -0
  135. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.js.map +1 -0
  136. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.d.ts +3 -0
  137. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.d.ts.map +1 -0
  138. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.js +68 -0
  139. package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.js.map +1 -0
  140. package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.d.ts +6 -0
  141. package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.d.ts.map +1 -0
  142. package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.js +10 -0
  143. package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.js.map +1 -0
  144. package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.d.ts +18 -0
  145. package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.d.ts.map +1 -0
  146. package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.js +40 -0
  147. package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.js.map +1 -0
  148. package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.d.ts +7 -0
  149. package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.d.ts.map +1 -0
  150. package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.js +3 -0
  151. package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.js.map +1 -0
  152. package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.d.ts +14 -0
  153. package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.d.ts.map +1 -0
  154. package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.js +3 -0
  155. package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.js.map +1 -0
  156. package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.d.ts +6 -0
  157. package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.d.ts.map +1 -0
  158. package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.js +3 -0
  159. package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.js.map +1 -0
  160. package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.d.ts +6 -0
  161. package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.d.ts.map +1 -0
  162. package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js +3 -0
  163. package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js.map +1 -0
  164. package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.d.ts +52 -0
  165. package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.d.ts.map +1 -0
  166. package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.js +3 -0
  167. package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.js.map +1 -0
  168. package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.d.ts +13 -0
  169. package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.d.ts.map +1 -0
  170. package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.js +3 -0
  171. package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.js.map +1 -0
  172. package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.d.ts +18 -0
  173. package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.d.ts.map +1 -0
  174. package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.js +80 -0
  175. package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.js.map +1 -0
  176. package/build/_modules/open-ai/_services/oai-chunk.service-base.d.ts +13 -0
  177. package/build/_modules/open-ai/_services/oai-chunk.service-base.d.ts.map +1 -0
  178. package/build/_modules/open-ai/_services/oai-chunk.service-base.js +170 -0
  179. package/build/_modules/open-ai/_services/oai-chunk.service-base.js.map +1 -0
  180. package/build/_modules/open-ai/_services/{embedding.control-service.d.ts → oai-embedding.control-service.d.ts} +3 -3
  181. package/build/_modules/open-ai/_services/oai-embedding.control-service.d.ts.map +1 -0
  182. package/build/_modules/open-ai/_services/{embedding.control-service.js → oai-embedding.control-service.js} +5 -5
  183. package/build/_modules/open-ai/_services/oai-embedding.control-service.js.map +1 -0
  184. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +161 -0
  185. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts.map +1 -0
  186. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js +332 -0
  187. package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js.map +1 -0
  188. package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts +231 -0
  189. package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts.map +1 -0
  190. package/build/_modules/open-ai/_services/oai-llm.service-base.js +438 -0
  191. package/build/_modules/open-ai/_services/oai-llm.service-base.js.map +1 -0
  192. package/build/_modules/open-ai/_services/{vector-data.service.d.ts → oai-vector-data.service.d.ts} +4 -4
  193. package/build/_modules/open-ai/_services/oai-vector-data.service.d.ts.map +1 -0
  194. package/build/_modules/open-ai/_services/{vector-data.service.js → oai-vector-data.service.js} +27 -7
  195. package/build/_modules/open-ai/_services/oai-vector-data.service.js.map +1 -0
  196. package/build/_modules/open-ai/index.d.ts +18 -4
  197. package/build/_modules/open-ai/index.d.ts.map +1 -1
  198. package/build/_modules/open-ai/index.js +35 -4
  199. package/build/_modules/open-ai/index.js.map +1 -1
  200. package/build/_modules/server/index.d.ts +1 -1
  201. package/build/_modules/server/index.d.ts.map +1 -1
  202. package/build/_modules/server/index.js +16 -2
  203. package/build/_modules/server/index.js.map +1 -1
  204. package/build/_modules/server/server-status/server-status.controller.d.ts.map +1 -1
  205. package/build/_modules/server/server-status/server-status.controller.js +10 -0
  206. package/build/_modules/server/server-status/server-status.controller.js.map +1 -1
  207. package/build/_modules/socket/index.d.ts.map +1 -1
  208. package/build/_modules/socket/index.js +18 -0
  209. package/build/_modules/socket/index.js.map +1 -1
  210. package/build/_modules/test/index.d.ts.map +1 -1
  211. package/build/_modules/test/index.js +5 -0
  212. package/build/_modules/test/index.js.map +1 -1
  213. package/build/_modules/usage/index.d.ts.map +1 -1
  214. package/build/_modules/usage/index.js +5 -0
  215. package/build/_modules/usage/index.js.map +1 -1
  216. package/build/_services/server/app.server.js +1 -2
  217. package/build/_services/server/app.server.js.map +1 -1
  218. package/build/index.d.ts +3 -1
  219. package/build/index.d.ts.map +1 -1
  220. package/build/index.js +26 -1
  221. package/build/index.js.map +1 -1
  222. package/package.json +40 -10
  223. package/src/_collections/atlas-default-db-options.const.ts +10 -0
  224. package/src/_collections/get-environment-settings.util.ts +49 -0
  225. package/src/_collections/global-settings.const.ts +15 -4
  226. package/src/_collections/sample.env +21 -0
  227. package/src/_models/control-models/app-params.control-model.spec.ts +5 -4
  228. package/src/_models/control-models/app-params.control-model.ts +31 -2
  229. package/src/_models/control-models/endpoint-params.control-model.ts +1 -1
  230. package/src/_models/interfaces/environment-settings.interface.ts +59 -0
  231. package/src/_models/interfaces/global-settings.interface.ts +41 -1
  232. package/src/_modules/custom-data/index.ts +3 -0
  233. package/src/_modules/discord-assistant/_collections/dias-global-settings.const.ts +19 -0
  234. package/src/_modules/discord-assistant/_models/dias-global-settings.interface.ts +20 -0
  235. package/src/_modules/discord-assistant/_models/dias-knowledge.data-model.ts +46 -0
  236. package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +152 -0
  237. package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +59 -0
  238. package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +28 -0
  239. package/src/_modules/discord-assistant/_services/dias.service-base.ts +81 -0
  240. package/src/_modules/discord-assistant/index.ts +36 -0
  241. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.ts +11 -0
  242. package/src/_modules/discord-assistant-voiced/index.ts +36 -0
  243. package/src/_modules/discord-bot/_collections/dibo-default-commands.const.ts +17 -0
  244. package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +56 -0
  245. package/src/_modules/discord-bot/_collections/dibo-operations.util.ts +372 -0
  246. package/src/_modules/discord-bot/_models/dibo-command.interface.ts +12 -0
  247. package/src/_modules/discord-bot/_models/dibo-last-mention-date.inteface.ts +8 -0
  248. package/src/_modules/discord-bot/_models/dibo-last-message-date.interface.ts +6 -0
  249. package/src/_modules/discord-bot/_models/global-bot-log-settings.interface.ts +98 -0
  250. package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +120 -0
  251. package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +245 -0
  252. package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +304 -0
  253. package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +60 -0
  254. package/src/_modules/discord-bot/index.ts +36 -0
  255. package/src/_modules/oauth2/index.ts +8 -0
  256. package/src/_modules/open-ai/_collections/oai-chunking.util.ts +496 -0
  257. package/src/_modules/open-ai/_collections/oai-document.util.ts +10 -0
  258. package/src/_modules/open-ai/_collections/oai-global-settings.const.ts +9 -0
  259. package/src/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.ts +83 -0
  260. package/src/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.ts +76 -0
  261. package/src/_modules/open-ai/_enums/oai-compare-result-type.enum.ts +7 -0
  262. package/src/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +45 -0
  263. package/src/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.ts +10 -0
  264. package/src/_modules/open-ai/_models/interfaces/oai-document-page.interface.ts +20 -0
  265. package/src/_modules/open-ai/_models/interfaces/oai-global-settings.interface.ts +8 -0
  266. package/src/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +7 -0
  267. package/src/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.ts +57 -0
  268. package/src/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.ts +18 -0
  269. package/src/_modules/open-ai/_models/oai-doc-chunk.data-model.ts +92 -0
  270. package/src/_modules/open-ai/_services/oai-chunk.service-base.ts +214 -0
  271. package/src/_modules/open-ai/_services/{embedding.control-service.ts → oai-embedding.control-service.ts} +2 -2
  272. package/src/_modules/open-ai/_services/oai-llm-chat.service-base.ts +609 -0
  273. package/src/_modules/open-ai/_services/oai-llm.service-base.ts +648 -0
  274. package/src/_modules/open-ai/_services/{vector-data.service.ts → oai-vector-data.service.ts} +32 -5
  275. package/src/_modules/open-ai/index.ts +42 -4
  276. package/src/_modules/server/index.ts +18 -2
  277. package/src/_modules/server/server-status/server-status.controller.ts +13 -0
  278. package/src/_modules/socket/index.ts +23 -0
  279. package/src/_modules/test/index.ts +8 -0
  280. package/src/_modules/usage/index.ts +8 -0
  281. package/src/_services/server/app.server.ts +1 -1
  282. package/src/index.ts +28 -1
  283. package/build/_modules/open-ai/_services/embedding.control-service.d.ts.map +0 -1
  284. package/build/_modules/open-ai/_services/embedding.control-service.js.map +0 -1
  285. package/build/_modules/open-ai/_services/gpt.service-base.d.ts +0 -98
  286. package/build/_modules/open-ai/_services/gpt.service-base.d.ts.map +0 -1
  287. package/build/_modules/open-ai/_services/gpt.service-base.js +0 -284
  288. package/build/_modules/open-ai/_services/gpt.service-base.js.map +0 -1
  289. package/build/_modules/open-ai/_services/open-ai.service-base.d.ts +0 -21
  290. package/build/_modules/open-ai/_services/open-ai.service-base.d.ts.map +0 -1
  291. package/build/_modules/open-ai/_services/open-ai.service-base.js +0 -50
  292. package/build/_modules/open-ai/_services/open-ai.service-base.js.map +0 -1
  293. package/build/_modules/open-ai/_services/vector-data.service.d.ts.map +0 -1
  294. package/build/_modules/open-ai/_services/vector-data.service.js.map +0 -1
  295. package/build/_services/server/env-set.d.ts +0 -2
  296. package/build/_services/server/env-set.d.ts.map +0 -1
  297. package/build/_services/server/env-set.js +0 -20
  298. package/build/_services/server/env-set.js.map +0 -1
  299. package/src/_modules/open-ai/_services/gpt.service-base.ts +0 -438
  300. package/src/_modules/open-ai/_services/open-ai.service-base.ts +0 -69
  301. package/src/_services/server/env-set.ts +0 -21
@@ -0,0 +1,648 @@
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_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 { DyNTS_OAI_global_settings } from '../_collections/oai-global-settings.const';
13
+ import { DyNTS_OAI_LLMDefaultPredefined_Requests } from '../_collections/oai-llm-predefined-requests.conts';
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_LLM_ServiceBase {
27
+
28
+ readonly defaultErrorUserMsg: string =
29
+ `We encountered an unhandled Control Service Error, ` +
30
+ `\nplease contact the responsible development team.`;
31
+
32
+ readonly openai: OpenAI;
33
+
34
+ /* readonly defaultSystemPrompt: string;
35
+ readonly defaultModel: DyFM_OpenAIModel | string; */
36
+ readonly defaultSettings: DyFM_GPTCall_Settings;
37
+
38
+ get debugLog(): boolean {
39
+ return this.defaultSettings.debugLog;
40
+ }
41
+
42
+ get defaultSystemPrompt(): string {
43
+ return this.defaultSettings.systemPrompt;
44
+ }
45
+
46
+ get defaultModel(): DyFM_OpenAIModel | string {
47
+ return this.defaultSettings.useModel;
48
+ }
49
+
50
+ readonly predefinedRequests: DyNTS_OAI_LLM_Predefined_Requests =
51
+ DyNTS_OAI_LLMDefaultPredefined_Requests;
52
+
53
+ constructor(
54
+ set?: DyFM_OpenAI_Settings
55
+ ) {
56
+ DyNTS_global_settings.openAi_settings ??= DyNTS_OAI_global_settings;
57
+
58
+ this.openai = new OpenAI(
59
+ set?.openAIConfig ??
60
+ {
61
+ organization: DyNTS_global_settings.env_settings.openAi.organization,
62
+ apiKey: DyNTS_global_settings.env_settings.openAi.apiKey,
63
+ project: DyNTS_global_settings.env_settings.openAi.project,
64
+ }
65
+ );
66
+
67
+ this.defaultSettings = set?.defaultSettings ??
68
+ DyNTS_OAI_global_settings.defaultSettings ??
69
+ new DyFM_GPTCall_Settings();
70
+ }
71
+
72
+ readonly defaultLogReplacer: string = '...';
73
+
74
+ //#region Ask Questions
75
+
76
+ /**
77
+ * Asks the AI to answer a yes/no question
78
+ *
79
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.request} to ask the question,
80
+ * and the {@link DyNTS_OAI_LLM_Predefined_Requests.yesNo.upperCaseYes} to check the answer
81
+ */
82
+ async askYesNoQuestion(
83
+ question: string,
84
+ issuer: string,
85
+ settings?: DyFM_GPTCall_Settings,
86
+ debugLog?: boolean,
87
+ /** this is used to readably replace too long contents to eg '...' in logs */
88
+ replaceThisInLog?: string
89
+ ): Promise<boolean> {
90
+ question += this.predefinedRequests.yesNo.request;
91
+
92
+ const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
93
+
94
+ return answer.toUpperCase().includes(this.predefinedRequests.yesNo.upperCaseYes);
95
+ }
96
+ /** the exact same as {@link askYesNoQuestion} */
97
+ yesNoQuestion = this.askYesNoQuestion;
98
+
99
+ /**
100
+ * Asks the AI to answer a percentage question
101
+ *
102
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.percentageOnly} to ask the question
103
+ */
104
+ async askPercentageQuestion(
105
+ question: string,
106
+ issuer: string,
107
+ settings?: DyFM_GPTCall_Settings,
108
+ debugLog?: boolean,
109
+ /** this is used to readably replace too long contents to eg '...' in logs */
110
+ replaceThisInLog?: string
111
+ ): Promise<number> {
112
+ question += this.predefinedRequests.percentageOnly;
113
+
114
+ const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
115
+
116
+ if (isNaN(+answer)) {
117
+ DyFM_Log.error('GPT_ServiceBase', 'asykPercentageQuestion', 'Invalid answer', {
118
+ question,
119
+ answer,
120
+ });
121
+
122
+ return null;
123
+ }
124
+
125
+ return +answer;
126
+ }
127
+ /** the exact same as {@link askPercentageQuestion} */
128
+ percentageQuestion = this.askPercentageQuestion;
129
+
130
+ /**
131
+ * Asks the AI to select one of the options from the list
132
+ *
133
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
134
+ */
135
+ async askSelectQuestion(
136
+ question: string,
137
+ selectFrom: string[],
138
+ issuer: string,
139
+ settings?: DyFM_GPTCall_Settings,
140
+ debugLog?: boolean,
141
+ /** this is used to readably replace too long contents to eg '...' in logs */
142
+ replaceThisInLog?: string
143
+ ): Promise<string> {
144
+ // replace the {{DyNTS_selectOptions}} with the list of options
145
+ const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
146
+ '{{DyNTS_selectOptions}}',
147
+ this.getTextListAsText(selectFrom)
148
+ );
149
+ question += selectQuestionAddition;
150
+
151
+ let answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
152
+
153
+ answer = answer.toLocaleUpperCase();
154
+
155
+ for (const item of selectFrom) {
156
+ if (answer.includes(item.toLocaleUpperCase())) return item;
157
+ }
158
+
159
+ return null;
160
+ }
161
+ /** the exact same as {@link askSelectQuestion} */
162
+ selectQuestion = this.askSelectQuestion;
163
+
164
+ /**
165
+ * Asks the AI to select one of the options from the list
166
+ * Similar to {@link askSelectQuestion},
167
+ * but with a more generic approach that can be used for objects
168
+ *
169
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.selectRequest} to ask the question
170
+ */
171
+ async requestSelect<T>(
172
+ question: string,
173
+ selectFrom: T[],
174
+ issuer: string,
175
+ settings?: DyFM_GPTCall_Settings,
176
+ debugLog?: boolean,
177
+ /** this is used to readably replace too long contents to eg '...' in logs */
178
+ replaceThisInLog?: string,
179
+ ): Promise<T | { unparsableResult: string }> {
180
+ const selectQuestionAddition = this.predefinedRequests.selectRequest.replace(
181
+ '{{DyNTS_selectOptions}}',
182
+ this.getTextListAsText(selectFrom.map(item => `"${JSON.stringify(item)}"`))
183
+ );
184
+ question += selectQuestionAddition;
185
+
186
+ const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
187
+
188
+ return DyFM_safeParseJSON<T>(answer);
189
+ }
190
+ /** the exact same as {@link requestSelect} */
191
+ selectRequest = this.requestSelect;
192
+
193
+ /**
194
+ * Asks the AI to select one or more of the options from the list
195
+ *
196
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
197
+ */
198
+ async askMultipleSelectQuestionWithOptions(
199
+ question: string,
200
+ options: string[],
201
+ issuer: string,
202
+ settings?: DyFM_GPTCall_Settings,
203
+ debugLog?: boolean,
204
+ /** this is used to readably replace too long contents to eg '...' in logs */
205
+ replaceThisInLog?: string
206
+ ): Promise<string[]> {
207
+ const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
208
+ '{{DyNTS_selectOptions}}',
209
+ this.getTextListAsText(options)
210
+ );
211
+ question += selectQuestionAddition;
212
+
213
+ let answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
214
+
215
+ answer = answer.toLocaleUpperCase();
216
+
217
+ const result: string[] = [];
218
+
219
+ for (const item of options) {
220
+ if (answer.includes(item.toLocaleUpperCase())) {
221
+ result.push(item);
222
+ }
223
+ }
224
+
225
+ return result;
226
+ }
227
+ /** the exact same as {@link askMultipleSelectQuestionWithOptions} */
228
+ multipleSelectQuestion = this.askMultipleSelectQuestionWithOptions;
229
+
230
+ /**
231
+ * Asks the AI to select one or more of the options from the list
232
+ * Similar to {@link askMultipleSelectQuestionWithOptions},
233
+ * but with a more generic approach that can be used for objects
234
+ *
235
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.multiselect} to ask the question
236
+ */
237
+ async requestMultipleSelect<T>(
238
+ question: string,
239
+ options: T[],
240
+ issuer: string,
241
+ settings?: DyFM_GPTCall_Settings,
242
+ debugLog?: boolean,
243
+ /** this is used to readably replace too long contents to eg '...' in logs */
244
+ replaceThisInLog?: string,
245
+ ): Promise<T[]> {
246
+ const selectQuestionAddition = this.predefinedRequests.multiselect.replace(
247
+ '{{DyNTS_selectOptions}}',
248
+ this.getTextListAsText(options.map(item => `"${JSON.stringify(item)}"`))
249
+ );
250
+ question += selectQuestionAddition;
251
+
252
+ const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
253
+
254
+ return DyFM_safeParseList<T[]>(answer);
255
+ }
256
+ /** the exact same as {@link requestMultipleSelect} */
257
+ multipleSelectRequest = this.requestMultipleSelect;
258
+
259
+ /**
260
+ * Asks the AI to answer a question that must result a JSON object
261
+ *
262
+ * If the answer is not a valid JSON object, it will return { unparsableResult: answer }
263
+ *
264
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.jsonRequest} to ask the question
265
+ *
266
+ * (uses {@link DyFM_safeParseJSON})
267
+ */
268
+ async askJSONQuestion<T = any>(
269
+ question: string,
270
+ issuer: string,
271
+ settings?: DyFM_GPTCall_Settings,
272
+ debugLog?: boolean,
273
+ /** this is used to readably replace too long contents to eg '...' in logs */
274
+ replaceThisInLog?: string
275
+ ): Promise<T | { unparsableResult: string }> {
276
+ question += this.predefinedRequests.jsonRequest;
277
+
278
+ const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
279
+
280
+ return DyFM_safeParseJSON<T>(answer);
281
+ }
282
+ /** the exact same as {@link askJSONQuestion} */
283
+ jsonQuestion = this.askJSONQuestion;
284
+
285
+ /**
286
+ * Asks the AI to answer a question that must result a JSON object with specific key descriptions
287
+ *
288
+ * If the answer is not a valid JSON object, it will return { unparsableResult: answer }
289
+ *
290
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.jsonRequestWithKeysDescription} to ask the question
291
+ *
292
+ * (uses {@link DyFM_safeParseJSON})
293
+ */
294
+ async askJSONQuestionWithKeysDescription<T = any>(
295
+ question: string,
296
+ keysDescription: string,
297
+ issuer: string,
298
+ settings?: DyFM_GPTCall_Settings,
299
+ debugLog?: boolean,
300
+ /** this is used to readably replace too long contents to eg '...' in logs */
301
+ replaceThisInLog?: string
302
+ ): Promise<T | { unparsableResult: string }> {
303
+ const jsonRequestWithKeysDescription = this.predefinedRequests.jsonRequestWithKeysDescription.replace(
304
+ '{{DyNTS_jsonKeysDescription}}',
305
+ keysDescription
306
+ );
307
+ question += jsonRequestWithKeysDescription;
308
+
309
+ const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
310
+
311
+ return DyFM_safeParseJSON<T>(answer);
312
+ }
313
+ /** the exact same as {@link askJSONQuestionWithKeysDescription} */
314
+ jsonQuestionWithKeysDescription = this.askJSONQuestionWithKeysDescription;
315
+
316
+ /**
317
+ * Asks the AI to answer a question that must result a JSON object with specific keys
318
+ *
319
+ * If the answer is not a valid JSON object, it will return { unparsableResult: answer }
320
+ *
321
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.jsonRequestWithExactKeys} to ask the question
322
+ *
323
+ * (uses {@link DyFM_safeParseJSON})
324
+ */
325
+ async askJSONQuestionWithExactKeys<T = any>(
326
+ question: string,
327
+ keys: string[],
328
+ issuer: string,
329
+ settings?: DyFM_GPTCall_Settings,
330
+ debugLog?: boolean,
331
+ /** this is used to readably replace too long contents to eg '...' in logs */
332
+ replaceThisInLog?: string
333
+ ): Promise<T | { unparsableResult: string }> {
334
+ const jsonRequestWithExactKeys = this.predefinedRequests.jsonRequestWithExactKeys.replace(
335
+ '{{DyNTS_jsonKeys}}',
336
+ this.getTextListAsText(keys)
337
+ );
338
+ question += jsonRequestWithExactKeys;
339
+
340
+ const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
341
+
342
+ return DyFM_safeParseJSON<T>(answer);
343
+ }
344
+ /** the exact same as {@link askJSONQuestionWithExactKeys} */
345
+ jsonQuestionWithExactKeys = this.askJSONQuestionWithExactKeys;
346
+
347
+ /**
348
+ * Asks the AI to answer a question that must result a list of strings
349
+ *
350
+ * If the answer is not a valid JSON list, it will return the answer as a single item in an array
351
+ *
352
+ * Uses the {@link DyNTS_OAI_LLM_Predefined_Requests.listRequest} to ask the question
353
+ *
354
+ * (uses {@link DyFM_safeParseList})
355
+ */
356
+ async askListQuestion(
357
+ question: string,
358
+ issuer: string,
359
+ settings?: DyFM_GPTCall_Settings,
360
+ debugLog?: boolean,
361
+ /** this is used to readably replace too long contents to eg '...' in logs */
362
+ replaceThisInLog?: string,
363
+ ): Promise<string[]> {
364
+ question += this.predefinedRequests.listRequest;
365
+
366
+ const answer = await this.askQuestion(question, issuer, settings, debugLog, replaceThisInLog);
367
+
368
+ return DyFM_safeParseList(answer);
369
+ }
370
+ /** the exact same as {@link askListQuestion} */
371
+ listQuestion = this.askListQuestion;
372
+ /** the exact same as {@link askListQuestion} */
373
+ listRequest = this.askListQuestion;
374
+
375
+ /**
376
+ * Asks the AI to answer a question
377
+ *
378
+ * Uses the {@link resolveSimpleUserMessage}
379
+ */
380
+ async askQuestion(
381
+ question: string,
382
+ issuer: string,
383
+ settings?: DyFM_GPTCall_Settings,
384
+ debugLog?: boolean,
385
+ /** this is used to readably replace too long contents to eg '...' in logs */
386
+ replaceThisInLog?: string,
387
+ ): Promise<string> {
388
+ this.logQuestion(question, replaceThisInLog, debugLog);
389
+
390
+ const answer = await this.resolveSimpleUserMessage(question, issuer, settings);
391
+
392
+ if (this.debugLog) {
393
+ console.log(' - ', answer);
394
+ }
395
+
396
+ return answer;
397
+ }
398
+ /** the exact same as {@link askQuestion} */
399
+ answer = this.askQuestion;
400
+ /** the exact same as {@link askQuestion} */
401
+ getQuestionAnswer = this.askQuestion;
402
+ /** the exact same as {@link askQuestion} */
403
+ simpleQuestion = this.askQuestion;
404
+ /** the exact same as {@link askQuestion} */
405
+ askSimpleQuestion = this.askQuestion;
406
+
407
+ /**
408
+ * Resolves a simple user message and returns the answer as string
409
+ *
410
+ * Uses the {@link resolveMessage}
411
+ */
412
+ async resolveSimpleUserMessage(
413
+ message: string,
414
+ issuer: string,
415
+ settings?: DyFM_GPTCall_Settings
416
+ ): Promise<string> {
417
+ return this.resolveMessage(
418
+ [{ role: DyNTS_OAI_GPT_Message_Role.user, content: message }],
419
+ issuer,
420
+ settings,
421
+ false
422
+ ) as Promise<string>;
423
+ }
424
+ /** the exact same as {@link resolveSimpleUserMessage} */
425
+ simpleUserMessage = this.resolveSimpleUserMessage;
426
+
427
+ //#endregion
428
+
429
+ /**
430
+ * Resolves a conversation
431
+ *
432
+ * Uses the {@link getMessageCreateInput}
433
+ */
434
+ async resolveMessage(
435
+ conversation: DyNTS_OAI_GPT_Message[],
436
+ issuer: string,
437
+ settings?: DyFM_GPTCall_Settings,
438
+ getFullResponse?: boolean
439
+ ): Promise<string | ChatCompletion> {
440
+ try {
441
+ conversation.unshift(this.getDefaultSystemMessage(settings));
442
+
443
+ const result: ChatCompletion = await this.openai.chat.completions.create(
444
+ this.getMessageCreateInput(conversation, issuer, settings)
445
+ ) as ChatCompletion;
446
+
447
+ if (getFullResponse) {
448
+ return result;
449
+ }
450
+
451
+ return result.choices[0].message.content;
452
+ } catch (error) {
453
+ throw new DyFM_Error({
454
+ ...this.getDefaultErrorSettings('resolveConversation', error, issuer),
455
+
456
+ errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-OAB-RC0`,
457
+ });
458
+ }
459
+ }
460
+
461
+ //#region Tools
462
+
463
+ /**
464
+ * Logs the question if the debugLog is true
465
+ */
466
+ protected logQuestion(question: string, replaceThisInLog?: string, debugLog?: boolean): void {
467
+ if (debugLog ?? this.debugLog) {
468
+ if (replaceThisInLog) {
469
+ question = question.replace(replaceThisInLog, this.defaultLogReplacer);
470
+ }
471
+
472
+ console.log('\n - ', question);
473
+ }
474
+ }
475
+
476
+ /**
477
+ * olvasható mondatszerű-listaszerű formába teszi a listaelemeket
478
+ * pl.: ['a', 'b', 'c'] -> '"a", "b" or "c"'
479
+ */
480
+ getTextListAsText(list: string[]): string {
481
+ list = list.filter(item => item?.trim()).map(item => `"${item}"`);
482
+
483
+ /* list = list.map(item => item.toLocaleLowerCase()); */
484
+
485
+ list.push(list.pop() + ' or ' + list.pop());
486
+
487
+ return list.join(', ');
488
+ }
489
+
490
+ /**
491
+ * Creates a message create input
492
+ *
493
+ * Uses the {@link getDefaultSystemMessage}
494
+ */
495
+ protected getMessageCreateInput(
496
+ messages: DyNTS_OAI_GPT_Message[],
497
+ issuer: string,
498
+ settings: DyFM_GPTCall_Settings = this.defaultSettings
499
+ ): ChatCompletionCreateParamsBase {
500
+ try {
501
+ const result: ChatCompletionCreateParamsBase = {
502
+ model: settings.useModel ?? this.defaultModel,
503
+ messages: messages as ChatCompletionMessageParam[],
504
+ };
505
+
506
+ if (DyFM_notNull(settings.temperature)) {
507
+ result.temperature = settings.temperature;
508
+ }
509
+
510
+ if (DyFM_notNull(settings.maxTokens)) {
511
+ result.max_tokens = settings.maxTokens;
512
+ }
513
+
514
+ if (DyFM_notNull(settings.topP)) {
515
+ result.top_p = settings.topP;
516
+ }
517
+
518
+ if (DyFM_notNull(settings.frequencyPenalty)) {
519
+ result.frequency_penalty = settings.frequencyPenalty;
520
+ }
521
+
522
+ if (DyFM_notNull(settings.presencePenalty)) {
523
+ result.presence_penalty = settings.presencePenalty;
524
+ }
525
+
526
+ return result;
527
+ } catch (error) {
528
+ throw new DyFM_Error({
529
+ ...this.getDefaultErrorSettings('getMessageCreateSettings', error, issuer),
530
+
531
+ errorCode: `${DyNTS_global_settings.systemShortCodeName}|DyNTS-OAB-RC0`,
532
+ });
533
+ }
534
+ }
535
+
536
+ protected getDefaultSystemMessage(settings: DyFM_GPTCall_Settings): DyNTS_OAI_GPT_Message {
537
+ return {
538
+ role: DyNTS_OAI_GPT_Message_Role.system,
539
+ content: settings.systemPrompt || this.defaultSystemPrompt,
540
+ };
541
+ }
542
+
543
+ protected getDefaultErrorSettings(
544
+ fnName: string,
545
+ error: DyFM_AnyError,
546
+ issuer: string
547
+ ): DyFM_Error_Settings {
548
+ return {
549
+ status: (error as DyFM_Error)?.___status ?? 500,
550
+ message: (error as Error)?.message ??
551
+ (error as DyFM_Error)?._message ??
552
+ `${fnName} was UNSUCCESSFUL (${DyNTS_global_settings.systemShortCodeName})`,
553
+ addECToUserMsg: !(error as DyFM_Error)?.__userMessage,
554
+ userMessage: (error as DyFM_Error)?.__userMessage ?? this.defaultErrorUserMsg,
555
+ issuer: issuer,
556
+ issuerService: this.constructor?.name,
557
+ error: error,
558
+ };
559
+ }
560
+
561
+ //#endregion
562
+ }
563
+
564
+ /**
565
+ * parses the JSON list, if it fails, it returns the answer as a single item in an array
566
+ *
567
+ * (uses {@link DyFM_safeParseJSON})
568
+ */
569
+ export function DyFM_safeParseList<T extends Array<any>>(
570
+ textedJSON: string,
571
+ disableErrorLog?: boolean
572
+ ): T {
573
+ const parsed = DyFM_safeParseJSON<T>(textedJSON, true);
574
+
575
+ if (Array.isArray(parsed)) {
576
+ return parsed;
577
+ } else if (typeof parsed === 'object') {
578
+ if (!disableErrorLog) {
579
+ DyFM_Log.warn(
580
+ 'DyFM_safeParseList result is an object, returning its values',
581
+ {
582
+ parsed: parsed,
583
+ }
584
+ );
585
+ }
586
+
587
+ return Object.values(parsed) as T;
588
+ } else {
589
+
590
+ if (!disableErrorLog) {
591
+ DyFM_Log.warn(
592
+ 'DyFM_safeParseList result is not an array or object, returning it as a single item',
593
+ {
594
+ parsed: parsed,
595
+ }
596
+ );
597
+ }
598
+
599
+ return [ parsed ] as string[] as T;
600
+ }
601
+ }
602
+
603
+ /**
604
+ * parses the JSON, if it fails, it returns { unparsableResult: textedJSON }
605
+ *
606
+ * (uses {@link DyFM_failableSafeParseJSON})
607
+ */
608
+ export function DyFM_safeParseJSON<T = any>(
609
+ textedJSON: string,
610
+ disableErrorLog?: boolean
611
+ ): T | { unparsableResult: string } {
612
+ try {
613
+ return DyFM_failableSafeParseJSON(textedJSON);
614
+ } catch (error) {
615
+ if (!disableErrorLog) {
616
+ DyFM_Log.error(
617
+ 'Unable to parse JSON answer:',
618
+ {
619
+ unparsedJSON: textedJSON,
620
+ error: error,
621
+ }
622
+ );
623
+ }
624
+
625
+ return { unparsableResult: textedJSON };
626
+ }
627
+ }
628
+
629
+ /**
630
+ * parses the JSON, if it fails, it throws an error
631
+ * (also will extract the JSON from "```json ... ```" wrapper)
632
+ */
633
+ export function DyFM_failableSafeParseJSON<T = any>(textedJSON: string): T {
634
+ if (!textedJSON) {
635
+ throw new Error(`No content provided to JSON parse ("${textedJSON}")`);
636
+ }
637
+
638
+ const match = textedJSON.match(/```json(.*)```/s);
639
+ textedJSON = textedJSON.replaceAll('\n', '');
640
+
641
+ if (match) {
642
+ return JSON.parse(match[1].replaceAll('\n', ''));
643
+ } else {
644
+ return JSON.parse(
645
+ textedJSON.replaceAll('```json', '').replaceAll('```', '')
646
+ );
647
+ }
648
+ }