@futdevpro/nts-dynamo 1.10.76 → 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.
- package/build/_collections/atlas-default-db-options.const.d.ts +28 -0
- package/build/_collections/atlas-default-db-options.const.d.ts.map +1 -0
- package/build/_collections/atlas-default-db-options.const.js +10 -0
- package/build/_collections/atlas-default-db-options.const.js.map +1 -0
- package/build/_collections/get-environment-settings.util.d.ts +3 -0
- package/build/_collections/get-environment-settings.util.d.ts.map +1 -0
- package/build/_collections/get-environment-settings.util.js +45 -0
- package/build/_collections/get-environment-settings.util.js.map +1 -0
- package/build/_collections/global-settings.const.d.ts.map +1 -1
- package/build/_collections/global-settings.const.js +9 -4
- package/build/_collections/global-settings.const.js.map +1 -1
- package/build/_models/control-models/app-params.control-model.d.ts +6 -0
- package/build/_models/control-models/app-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/app-params.control-model.js +29 -2
- package/build/_models/control-models/app-params.control-model.js.map +1 -1
- package/build/_models/control-models/app-params.control-model.spec.js +5 -4
- package/build/_models/control-models/app-params.control-model.spec.js.map +1 -1
- package/build/_models/control-models/endpoint-params.control-model.js +1 -1
- package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/build/_models/interfaces/environment-settings.interface.d.ts +35 -0
- package/build/_models/interfaces/environment-settings.interface.d.ts.map +1 -0
- package/build/_models/interfaces/environment-settings.interface.js +3 -0
- package/build/_models/interfaces/environment-settings.interface.js.map +1 -0
- package/build/_models/interfaces/global-settings.interface.d.ts +34 -2
- package/build/_models/interfaces/global-settings.interface.d.ts.map +1 -1
- package/build/_modules/custom-data/index.d.ts.map +1 -1
- package/build/_modules/custom-data/index.js +1 -0
- package/build/_modules/custom-data/index.js.map +1 -1
- package/build/_modules/discord-assistant/_collections/dias-global-settings.const.d.ts +3 -0
- package/build/_modules/discord-assistant/_collections/dias-global-settings.const.d.ts.map +1 -0
- package/build/_modules/discord-assistant/_collections/dias-global-settings.const.js +17 -0
- package/build/_modules/discord-assistant/_collections/dias-global-settings.const.js.map +1 -0
- package/build/_modules/discord-assistant/_models/dias-global-settings.interface.d.ts +18 -0
- package/build/_modules/discord-assistant/_models/dias-global-settings.interface.d.ts.map +1 -0
- package/build/_modules/discord-assistant/_models/dias-global-settings.interface.js +3 -0
- package/build/_modules/discord-assistant/_models/dias-global-settings.interface.js.map +1 -0
- package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.d.ts +10 -0
- package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.d.ts.map +1 -0
- package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.js +41 -0
- package/build/_modules/discord-assistant/_models/dias-knowledge.data-model.js.map +1 -0
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts +14 -0
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.d.ts.map +1 -0
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js +88 -0
- package/build/_modules/discord-assistant/_services/dias-chunk.data-service.js.map +1 -0
- package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts +10 -0
- package/build/_modules/discord-assistant/_services/dias-io.control-service.d.ts.map +1 -0
- package/build/_modules/discord-assistant/_services/dias-io.control-service.js +39 -0
- package/build/_modules/discord-assistant/_services/dias-io.control-service.js.map +1 -0
- package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts +8 -0
- package/build/_modules/discord-assistant/_services/dias-main.control-service.d.ts.map +1 -0
- package/build/_modules/discord-assistant/_services/dias-main.control-service.js +23 -0
- package/build/_modules/discord-assistant/_services/dias-main.control-service.js.map +1 -0
- package/build/_modules/discord-assistant/_services/dias.service-base.d.ts +13 -0
- package/build/_modules/discord-assistant/_services/dias.service-base.d.ts.map +1 -0
- package/build/_modules/discord-assistant/_services/dias.service-base.js +61 -0
- package/build/_modules/discord-assistant/_services/dias.service-base.js.map +1 -0
- package/build/_modules/discord-assistant/index.d.ts +10 -0
- package/build/_modules/discord-assistant/index.d.ts.map +1 -0
- package/build/_modules/discord-assistant/index.js +23 -0
- package/build/_modules/discord-assistant/index.js.map +1 -0
- package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.d.ts +4 -0
- package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.d.ts.map +1 -0
- package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.js +8 -0
- package/build/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.js.map +1 -0
- package/build/_modules/discord-assistant-voiced/index.d.ts +3 -0
- package/build/_modules/discord-assistant-voiced/index.d.ts.map +1 -0
- package/build/_modules/discord-assistant-voiced/index.js +26 -0
- package/build/_modules/discord-assistant-voiced/index.js.map +1 -0
- package/build/_modules/discord-bot/_collections/dibo-default-commands.const.d.ts +3 -0
- package/build/_modules/discord-bot/_collections/dibo-default-commands.const.d.ts.map +1 -0
- package/build/_modules/discord-bot/_collections/dibo-default-commands.const.js +13 -0
- package/build/_modules/discord-bot/_collections/dibo-default-commands.const.js.map +1 -0
- package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts +3 -0
- package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.d.ts.map +1 -0
- package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.js +44 -0
- package/build/_modules/discord-bot/_collections/dibo-global-settings.conts.js.map +1 -0
- package/build/_modules/discord-bot/_collections/dibo-operations.util.d.ts +22 -0
- package/build/_modules/discord-bot/_collections/dibo-operations.util.d.ts.map +1 -0
- package/build/_modules/discord-bot/_collections/dibo-operations.util.js +261 -0
- package/build/_modules/discord-bot/_collections/dibo-operations.util.js.map +1 -0
- package/build/_modules/discord-bot/_models/dibo-command.interface.d.ts +8 -0
- package/build/_modules/discord-bot/_models/dibo-command.interface.d.ts.map +1 -0
- package/build/_modules/discord-bot/_models/dibo-command.interface.js +3 -0
- package/build/_modules/discord-bot/_models/dibo-command.interface.js.map +1 -0
- package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.d.ts +7 -0
- package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.d.ts.map +1 -0
- package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.js +3 -0
- package/build/_modules/discord-bot/_models/dibo-last-mention-date.inteface.js.map +1 -0
- package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.d.ts +6 -0
- package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.d.ts.map +1 -0
- package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.js +3 -0
- package/build/_modules/discord-bot/_models/dibo-last-message-date.interface.js.map +1 -0
- package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.d.ts +88 -0
- package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.d.ts.map +1 -0
- package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.js +3 -0
- package/build/_modules/discord-bot/_models/global-bot-log-settings.interface.js.map +1 -0
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts +12 -0
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.d.ts.map +1 -0
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.js +72 -0
- package/build/_modules/discord-bot/_services/dibo-commands.control-service.js.map +1 -0
- package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts +19 -0
- package/build/_modules/discord-bot/_services/dibo-io.control-service.d.ts.map +1 -0
- package/build/_modules/discord-bot/_services/dibo-io.control-service.js +176 -0
- package/build/_modules/discord-bot/_services/dibo-io.control-service.js.map +1 -0
- package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts +85 -0
- package/build/_modules/discord-bot/_services/dibo-main.control-service.d.ts.map +1 -0
- package/build/_modules/discord-bot/_services/dibo-main.control-service.js +228 -0
- package/build/_modules/discord-bot/_services/dibo-main.control-service.js.map +1 -0
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts +13 -0
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.d.ts.map +1 -0
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.js +38 -0
- package/build/_modules/discord-bot/_services/dibo-routines.control-service.js.map +1 -0
- package/build/_modules/discord-bot/index.d.ts +12 -0
- package/build/_modules/discord-bot/index.d.ts.map +1 -0
- package/build/_modules/discord-bot/index.js +30 -0
- package/build/_modules/discord-bot/index.js.map +1 -0
- package/build/_modules/oauth2/index.d.ts.map +1 -1
- package/build/_modules/oauth2/index.js +7 -0
- package/build/_modules/oauth2/index.js.map +1 -1
- package/build/_modules/open-ai/_collections/oai-chunking.util.d.ts +74 -0
- package/build/_modules/open-ai/_collections/oai-chunking.util.d.ts.map +1 -0
- package/build/_modules/open-ai/_collections/oai-chunking.util.js +385 -0
- package/build/_modules/open-ai/_collections/oai-chunking.util.js.map +1 -0
- package/build/_modules/open-ai/_collections/oai-document.util.d.ts +4 -0
- package/build/_modules/open-ai/_collections/oai-document.util.d.ts.map +1 -0
- package/build/_modules/open-ai/_collections/oai-document.util.js +12 -0
- package/build/_modules/open-ai/_collections/oai-document.util.js.map +1 -0
- package/build/_modules/open-ai/_collections/oai-global-settings.const.d.ts +3 -0
- package/build/_modules/open-ai/_collections/oai-global-settings.const.d.ts.map +1 -0
- package/build/_modules/open-ai/_collections/oai-global-settings.const.js +9 -0
- package/build/_modules/open-ai/_collections/oai-global-settings.const.js.map +1 -0
- package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.d.ts +3 -0
- package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.d.ts.map +1 -0
- package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.js +75 -0
- package/build/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.js.map +1 -0
- package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.d.ts +3 -0
- package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.d.ts.map +1 -0
- package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.js +68 -0
- package/build/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.js.map +1 -0
- package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.d.ts +6 -0
- package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.d.ts.map +1 -0
- package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.js +10 -0
- package/build/_modules/open-ai/_enums/oai-compare-result-type.enum.js.map +1 -0
- package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.d.ts +18 -0
- package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.d.ts.map +1 -0
- package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.js +40 -0
- package/build/_modules/open-ai/_enums/oai-gpt-message-role.enum.js.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.d.ts +7 -0
- package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.js +3 -0
- package/build/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.d.ts +14 -0
- package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.js +3 -0
- package/build/_modules/open-ai/_models/interfaces/oai-document-page.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.d.ts +6 -0
- package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.js +3 -0
- package/build/_modules/open-ai/_models/interfaces/oai-global-settings.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.d.ts +6 -0
- package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js +3 -0
- package/build/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.d.ts +52 -0
- package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.js +3 -0
- package/build/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.d.ts +13 -0
- package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.js +3 -0
- package/build/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.js.map +1 -0
- package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.d.ts +18 -0
- package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.d.ts.map +1 -0
- package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.js +80 -0
- package/build/_modules/open-ai/_models/oai-doc-chunk.data-model.js.map +1 -0
- package/build/_modules/open-ai/_services/oai-chunk.service-base.d.ts +13 -0
- package/build/_modules/open-ai/_services/oai-chunk.service-base.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/oai-chunk.service-base.js +170 -0
- package/build/_modules/open-ai/_services/oai-chunk.service-base.js.map +1 -0
- package/build/_modules/open-ai/_services/{embedding.control-service.d.ts → oai-embedding.control-service.d.ts} +3 -3
- package/build/_modules/open-ai/_services/oai-embedding.control-service.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/{embedding.control-service.js → oai-embedding.control-service.js} +5 -5
- package/build/_modules/open-ai/_services/oai-embedding.control-service.js.map +1 -0
- package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts +161 -0
- package/build/_modules/open-ai/_services/oai-llm-chat.service-base.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js +332 -0
- package/build/_modules/open-ai/_services/oai-llm-chat.service-base.js.map +1 -0
- package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts +231 -0
- package/build/_modules/open-ai/_services/oai-llm.service-base.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/oai-llm.service-base.js +438 -0
- package/build/_modules/open-ai/_services/oai-llm.service-base.js.map +1 -0
- package/build/_modules/open-ai/_services/{vector-data.service.d.ts → oai-vector-data.service.d.ts} +4 -4
- package/build/_modules/open-ai/_services/oai-vector-data.service.d.ts.map +1 -0
- package/build/_modules/open-ai/_services/{vector-data.service.js → oai-vector-data.service.js} +27 -7
- package/build/_modules/open-ai/_services/oai-vector-data.service.js.map +1 -0
- package/build/_modules/open-ai/index.d.ts +18 -4
- package/build/_modules/open-ai/index.d.ts.map +1 -1
- package/build/_modules/open-ai/index.js +35 -4
- package/build/_modules/open-ai/index.js.map +1 -1
- package/build/_modules/server/index.d.ts +1 -1
- package/build/_modules/server/index.d.ts.map +1 -1
- package/build/_modules/server/index.js +16 -2
- package/build/_modules/server/index.js.map +1 -1
- package/build/_modules/server/server-status/server-status.controller.d.ts.map +1 -1
- package/build/_modules/server/server-status/server-status.controller.js +10 -0
- package/build/_modules/server/server-status/server-status.controller.js.map +1 -1
- package/build/_modules/socket/index.d.ts.map +1 -1
- package/build/_modules/socket/index.js +18 -0
- package/build/_modules/socket/index.js.map +1 -1
- package/build/_modules/test/index.d.ts.map +1 -1
- package/build/_modules/test/index.js +5 -0
- package/build/_modules/test/index.js.map +1 -1
- package/build/_modules/usage/index.d.ts.map +1 -1
- package/build/_modules/usage/index.js +5 -0
- package/build/_modules/usage/index.js.map +1 -1
- package/build/_services/server/app.server.js +1 -2
- package/build/_services/server/app.server.js.map +1 -1
- package/build/index.d.ts +3 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +26 -1
- package/build/index.js.map +1 -1
- package/package.json +40 -10
- package/src/_collections/atlas-default-db-options.const.ts +10 -0
- package/src/_collections/get-environment-settings.util.ts +49 -0
- package/src/_collections/global-settings.const.ts +15 -4
- package/src/_collections/sample.env +21 -0
- package/src/_models/control-models/app-params.control-model.spec.ts +5 -4
- package/src/_models/control-models/app-params.control-model.ts +31 -2
- package/src/_models/control-models/endpoint-params.control-model.ts +1 -1
- package/src/_models/interfaces/environment-settings.interface.ts +59 -0
- package/src/_models/interfaces/global-settings.interface.ts +41 -1
- package/src/_modules/custom-data/index.ts +3 -0
- package/src/_modules/discord-assistant/_collections/dias-global-settings.const.ts +19 -0
- package/src/_modules/discord-assistant/_models/dias-global-settings.interface.ts +20 -0
- package/src/_modules/discord-assistant/_models/dias-knowledge.data-model.ts +46 -0
- package/src/_modules/discord-assistant/_services/dias-chunk.data-service.ts +152 -0
- package/src/_modules/discord-assistant/_services/dias-io.control-service.ts +59 -0
- package/src/_modules/discord-assistant/_services/dias-main.control-service.ts +28 -0
- package/src/_modules/discord-assistant/_services/dias.service-base.ts +81 -0
- package/src/_modules/discord-assistant/index.ts +36 -0
- package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.ts +11 -0
- package/src/_modules/discord-assistant-voiced/index.ts +36 -0
- package/src/_modules/discord-bot/_collections/dibo-default-commands.const.ts +17 -0
- package/src/_modules/discord-bot/_collections/dibo-global-settings.conts.ts +56 -0
- package/src/_modules/discord-bot/_collections/dibo-operations.util.ts +372 -0
- package/src/_modules/discord-bot/_models/dibo-command.interface.ts +12 -0
- package/src/_modules/discord-bot/_models/dibo-last-mention-date.inteface.ts +8 -0
- package/src/_modules/discord-bot/_models/dibo-last-message-date.interface.ts +6 -0
- package/src/_modules/discord-bot/_models/global-bot-log-settings.interface.ts +98 -0
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.ts +120 -0
- package/src/_modules/discord-bot/_services/dibo-io.control-service.ts +245 -0
- package/src/_modules/discord-bot/_services/dibo-main.control-service.ts +304 -0
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.ts +60 -0
- package/src/_modules/discord-bot/index.ts +36 -0
- package/src/_modules/oauth2/index.ts +8 -0
- package/src/_modules/open-ai/_collections/oai-chunking.util.ts +496 -0
- package/src/_modules/open-ai/_collections/oai-document.util.ts +10 -0
- package/src/_modules/open-ai/_collections/oai-global-settings.const.ts +9 -0
- package/src/_modules/open-ai/_collections/oai-llm-predefined-requests-hu.conts.ts +83 -0
- package/src/_modules/open-ai/_collections/oai-llm-predefined-requests.conts.ts +76 -0
- package/src/_modules/open-ai/_enums/oai-compare-result-type.enum.ts +7 -0
- package/src/_modules/open-ai/_enums/oai-gpt-message-role.enum.ts +45 -0
- package/src/_modules/open-ai/_models/interfaces/oai-chunk-compare-result.interface.ts +10 -0
- package/src/_modules/open-ai/_models/interfaces/oai-document-page.interface.ts +20 -0
- package/src/_modules/open-ai/_models/interfaces/oai-global-settings.interface.ts +8 -0
- package/src/_modules/open-ai/_models/interfaces/oai-gpt-message.interface.ts +7 -0
- package/src/_modules/open-ai/_models/interfaces/oai-llm-predefined-requests.interface.ts +57 -0
- package/src/_modules/open-ai/_models/interfaces/oai-page-compare-result.interface.ts +18 -0
- package/src/_modules/open-ai/_models/oai-doc-chunk.data-model.ts +92 -0
- package/src/_modules/open-ai/_services/oai-chunk.service-base.ts +214 -0
- package/src/_modules/open-ai/_services/{embedding.control-service.ts → oai-embedding.control-service.ts} +2 -2
- package/src/_modules/open-ai/_services/oai-llm-chat.service-base.ts +609 -0
- package/src/_modules/open-ai/_services/oai-llm.service-base.ts +648 -0
- package/src/_modules/open-ai/_services/{vector-data.service.ts → oai-vector-data.service.ts} +32 -5
- package/src/_modules/open-ai/index.ts +42 -4
- package/src/_modules/server/index.ts +18 -2
- package/src/_modules/server/server-status/server-status.controller.ts +13 -0
- package/src/_modules/socket/index.ts +23 -0
- package/src/_modules/test/index.ts +8 -0
- package/src/_modules/usage/index.ts +8 -0
- package/src/_services/server/app.server.ts +1 -1
- package/src/index.ts +28 -1
- package/build/_modules/open-ai/_services/embedding.control-service.d.ts.map +0 -1
- package/build/_modules/open-ai/_services/embedding.control-service.js.map +0 -1
- package/build/_modules/open-ai/_services/gpt.service-base.d.ts +0 -98
- package/build/_modules/open-ai/_services/gpt.service-base.d.ts.map +0 -1
- package/build/_modules/open-ai/_services/gpt.service-base.js +0 -284
- package/build/_modules/open-ai/_services/gpt.service-base.js.map +0 -1
- package/build/_modules/open-ai/_services/open-ai.service-base.d.ts +0 -21
- package/build/_modules/open-ai/_services/open-ai.service-base.d.ts.map +0 -1
- package/build/_modules/open-ai/_services/open-ai.service-base.js +0 -50
- package/build/_modules/open-ai/_services/open-ai.service-base.js.map +0 -1
- package/build/_modules/open-ai/_services/vector-data.service.d.ts.map +0 -1
- package/build/_modules/open-ai/_services/vector-data.service.js.map +0 -1
- package/build/_services/server/env-set.d.ts +0 -2
- package/build/_services/server/env-set.d.ts.map +0 -1
- package/build/_services/server/env-set.js +0 -20
- package/build/_services/server/env-set.js.map +0 -1
- package/src/_modules/open-ai/_services/gpt.service-base.ts +0 -438
- package/src/_modules/open-ai/_services/open-ai.service-base.ts +0 -69
- 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
|
+
}
|