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