@yrpri/api 9.0.103 → 9.0.104
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/package.json +1 -1
- package/dist/active-citizen/controllers/activities.cjs +0 -174
- package/dist/active-citizen/controllers/news_feeds.cjs +0 -96
- package/dist/active-citizen/controllers/notifications.cjs +0 -243
- package/dist/active-citizen/controllers/recommendations.cjs +0 -280
- package/dist/active-citizen/engine/allOurIdeas/aiHelper.js +0 -204
- package/dist/active-citizen/engine/allOurIdeas/explainAnswersAssistant.js +0 -66
- package/dist/active-citizen/engine/allOurIdeas/iconGenerator.js +0 -38
- package/dist/active-citizen/engine/analytics/export_anon_community_activities.js +0 -334
- package/dist/active-citizen/engine/analytics/importer.js +0 -308
- package/dist/active-citizen/engine/analytics/manager.cjs +0 -377
- package/dist/active-citizen/engine/analytics/plausible/manager.cjs +0 -500
- package/dist/active-citizen/engine/analytics/statsCalc.cjs +0 -194
- package/dist/active-citizen/engine/analytics/utils.cjs +0 -369
- package/dist/active-citizen/engine/marketing/campaign.cjs +0 -90
- package/dist/active-citizen/engine/moderation/fraud/CreateFraudAuditReport.cjs +0 -313
- package/dist/active-citizen/engine/moderation/fraud/FraudBase.cjs +0 -239
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteBase.cjs +0 -211
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteEndorsements.cjs +0 -120
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePointQualities.cjs +0 -114
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePoints.cjs +0 -101
- package/dist/active-citizen/engine/moderation/fraud/FraudDeletePosts.cjs +0 -84
- package/dist/active-citizen/engine/moderation/fraud/FraudDeleteRatings.cjs +0 -15
- package/dist/active-citizen/engine/moderation/fraud/FraudGetBase.cjs +0 -133
- package/dist/active-citizen/engine/moderation/fraud/FraudGetEndorsements.cjs +0 -185
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPointQualities.cjs +0 -184
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPoints.cjs +0 -170
- package/dist/active-citizen/engine/moderation/fraud/FraudGetPosts.cjs +0 -109
- package/dist/active-citizen/engine/moderation/fraud/FraudGetRatings.cjs +0 -140
- package/dist/active-citizen/engine/moderation/fraud/FraudScannerNotifier.cjs +0 -279
- package/dist/active-citizen/engine/moderation/get_moderation_items.cjs +0 -386
- package/dist/active-citizen/engine/moderation/image_labeling/CommunityLabeling.cjs +0 -49
- package/dist/active-citizen/engine/moderation/image_labeling/GroupLabeling.cjs +0 -68
- package/dist/active-citizen/engine/moderation/image_labeling/ImageLabelingBase.cjs +0 -288
- package/dist/active-citizen/engine/moderation/image_labeling/PointLabeling.cjs +0 -33
- package/dist/active-citizen/engine/moderation/image_labeling/PostLabeling.cjs +0 -56
- package/dist/active-citizen/engine/moderation/perspective_api_client.cjs +0 -106
- package/dist/active-citizen/engine/moderation/process_moderation_items.cjs +0 -344
- package/dist/active-citizen/engine/moderation/toxicity_analysis.cjs +0 -810
- package/dist/active-citizen/engine/news_feeds/activity_and_item_index_definitions.cjs +0 -15
- package/dist/active-citizen/engine/news_feeds/generate_dynamically.cjs +0 -362
- package/dist/active-citizen/engine/news_feeds/generate_from_notifications.cjs +0 -268
- package/dist/active-citizen/engine/news_feeds/news_feeds_utils.cjs +0 -439
- package/dist/active-citizen/engine/notifications/emails_utils.cjs +0 -569
- package/dist/active-citizen/engine/notifications/generate_point_notifications.cjs +0 -233
- package/dist/active-citizen/engine/notifications/generate_post_notifications.cjs +0 -118
- package/dist/active-citizen/engine/notifications/generate_post_status_change_notifications.cjs +0 -41
- package/dist/active-citizen/engine/notifications/notifications_utils.cjs +0 -148
- package/dist/active-citizen/engine/notifications/point_delivery.cjs +0 -54
- package/dist/active-citizen/engine/notifications/post_delivery.cjs +0 -31
- package/dist/active-citizen/engine/notifications/process_delayed_notifications.cjs +0 -471
- package/dist/active-citizen/engine/notifications/process_general_notifications.cjs +0 -212
- package/dist/active-citizen/engine/old/exporters/categories_dataset.js +0 -153
- package/dist/active-citizen/engine/old/exporters/dataset_tools.js +0 -80
- package/dist/active-citizen/engine/old/exporters/sentiment_dataset.js +0 -157
- package/dist/active-citizen/engine/recommendations/events_importer.cjs +0 -139
- package/dist/active-citizen/engine/recommendations/events_manager.cjs +0 -212
- package/dist/active-citizen/engine/reports/add_points_to_sheet.cjs +0 -83
- package/dist/active-citizen/engine/reports/commonUtils.js +0 -75
- package/dist/active-citizen/engine/reports/common_utils.cjs +0 -740
- package/dist/active-citizen/engine/reports/docx_group_report.cjs +0 -596
- package/dist/active-citizen/engine/reports/xlsAllOurIdeasExport.js +0 -232
- package/dist/active-citizen/engine/reports/xls_community_users_report.cjs +0 -277
- package/dist/active-citizen/engine/reports/xls_group_report.cjs +0 -718
- package/dist/active-citizen/llms/baseChatBot.js +0 -183
- package/dist/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +0 -56
- package/dist/active-citizen/llms/imageGeneration/collectionImageGenerator.js +0 -109
- package/dist/active-citizen/llms/imageGeneration/dalleImageGenerator.js +0 -84
- package/dist/active-citizen/llms/imageGeneration/fluxImageGenerator.js +0 -49
- package/dist/active-citizen/llms/imageGeneration/iImageGenerator.js +0 -1
- package/dist/active-citizen/llms/imageGeneration/imageProcessorService.js +0 -64
- package/dist/active-citizen/llms/imageGeneration/imagenImageGenerator.js +0 -107
- package/dist/active-citizen/llms/imageGeneration/s3Service.js +0 -110
- package/dist/active-citizen/llms/llmTranslation.js +0 -472
- package/dist/active-citizen/models/ac_activity.cjs +0 -216
- package/dist/active-citizen/models/ac_background_job.cjs +0 -109
- package/dist/active-citizen/models/ac_campaign.cjs +0 -97
- package/dist/active-citizen/models/ac_client_activity.cjs +0 -23
- package/dist/active-citizen/models/ac_delayed_notification.cjs +0 -43
- package/dist/active-citizen/models/ac_following.cjs +0 -43
- package/dist/active-citizen/models/ac_list.cjs +0 -68
- package/dist/active-citizen/models/ac_list_users.cjs +0 -19
- package/dist/active-citizen/models/ac_mute.cjs +0 -27
- package/dist/active-citizen/models/ac_news_feed_item.cjs +0 -57
- package/dist/active-citizen/models/ac_news_feed_processed_range.cjs +0 -59
- package/dist/active-citizen/models/ac_notification.cjs +0 -292
- package/dist/active-citizen/models/ac_translation_cache.cjs +0 -750
- package/dist/active-citizen/models/ac_watching.cjs +0 -31
- package/dist/active-citizen/scripts/analytics/setup_all_plausible_goals.cjs +0 -13
- package/dist/active-citizen/scripts/fix_old_delayed_notifications.js +0 -63
- package/dist/active-citizen/scripts/kue_status.js +0 -31
- package/dist/active-citizen/scripts/kue_watch_stuck_jobs.js +0 -24
- package/dist/active-citizen/scripts/translation_clear_language.js +0 -117
- package/dist/active-citizen/scripts/translation_delete.js +0 -27
- package/dist/active-citizen/scripts/translation_replace_text_from_url.js +0 -180
- package/dist/active-citizen/scripts/translation_update.js +0 -28
- package/dist/active-citizen/scripts/translations_list.js +0 -27
- package/dist/active-citizen/utils/airbrake.cjs +0 -17
- package/dist/active-citizen/utils/get_anonymous_system_user.cjs +0 -21
- package/dist/active-citizen/utils/i18n.cjs +0 -3
- package/dist/active-citizen/utils/logger.cjs +0 -25
- package/dist/active-citizen/utils/redisConnection.cjs +0 -29
- package/dist/active-citizen/utils/to_json.cjs +0 -9
- package/dist/active-citizen/utils/translation_cloning.cjs +0 -171
- package/dist/active-citizen/utils/translation_helpers.cjs +0 -534
- package/dist/active-citizen/utils/truncate_text.cjs +0 -21
- package/dist/active-citizen/utils/updateAllLocalesFromEn.js +0 -253
- package/dist/active-citizen/utils/updateLocaleFolders.js +0 -34
- package/dist/active-citizen/workers/activity.cjs +0 -189
- package/dist/active-citizen/workers/anonymizations.cjs +0 -734
- package/dist/active-citizen/workers/bulk_status_update.cjs +0 -458
- package/dist/active-citizen/workers/delayed_jobs.cjs +0 -244
- package/dist/active-citizen/workers/deletions.cjs +0 -1911
- package/dist/active-citizen/workers/email.cjs +0 -9
- package/dist/active-citizen/workers/fraud_management.cjs +0 -109
- package/dist/active-citizen/workers/generativeAi.js +0 -56
- package/dist/active-citizen/workers/main.cjs +0 -89
- package/dist/active-citizen/workers/marketing.cjs +0 -25
- package/dist/active-citizen/workers/moderation.cjs +0 -73
- package/dist/active-citizen/workers/notification_delivery.cjs +0 -368
- package/dist/active-citizen/workers/notification_news_feed.cjs +0 -142
- package/dist/active-citizen/workers/queue.cjs +0 -99
- package/dist/active-citizen/workers/recount.cjs +0 -74
- package/dist/active-citizen/workers/reports.cjs +0 -42
- package/dist/active-citizen/workers/similarities.cjs +0 -21
- package/dist/active-citizen/workers/speech_to_text.cjs +0 -482
- package/dist/agents/assistants/agentAssistant.js +0 -88
- package/dist/agents/assistants/baseAssistant.js +0 -888
- package/dist/agents/assistants/baseAssistantWithVoice.js +0 -150
- package/dist/agents/assistants/modes/agentDirectConnection.js +0 -84
- package/dist/agents/assistants/modes/agentSelectionMode.js +0 -44
- package/dist/agents/assistants/modes/baseAssistantMode.js +0 -54
- package/dist/agents/assistants/modes/tools/agentTools.js +0 -447
- package/dist/agents/assistants/modes/tools/baseTools.js +0 -58
- package/dist/agents/assistants/modes/tools/loginTools.js +0 -156
- package/dist/agents/assistants/modes/tools/models/agents.js +0 -146
- package/dist/agents/assistants/modes/tools/models/subscriptions.js +0 -332
- package/dist/agents/assistants/modes/tools/models/users.js +0 -11
- package/dist/agents/assistants/modes/tools/navigationTools.js +0 -166
- package/dist/agents/assistants/modes/tools/subscriptionTools.js +0 -323
- package/dist/agents/assistants/modes/tools/workflowConverstationTools.js +0 -112
- package/dist/agents/assistants/voiceAssistant.js +0 -619
- package/dist/agents/controllers/agentProductController.js +0 -103
- package/dist/agents/controllers/agentSubscriptionController.js +0 -261
- package/dist/agents/controllers/assistantsController.js +0 -511
- package/dist/agents/controllers/policySynthAgents.js +0 -395
- package/dist/agents/managers/agentProductManager.js +0 -91
- package/dist/agents/managers/emailInvitesManager.js +0 -55
- package/dist/agents/managers/emailTemplateRenderer.js +0 -362
- package/dist/agents/managers/newAiModelSetup.js +0 -650
- package/dist/agents/managers/notificationAgentQueueManager.js +0 -510
- package/dist/agents/managers/subscriptionManager.js +0 -535
- package/dist/agents/managers/workflowConversationManager.js +0 -79
- package/dist/agents/models/agentProduct.js +0 -116
- package/dist/agents/models/agentProductBoosterPurchase.js +0 -58
- package/dist/agents/models/agentProductBundle.js +0 -68
- package/dist/agents/models/agentProductRun.js +0 -52
- package/dist/agents/models/discount.js +0 -88
- package/dist/agents/models/subscription.js +0 -79
- package/dist/agents/models/subscriptionPlan.js +0 -46
- package/dist/agents/models/subscriptionUser.js +0 -27
- package/dist/agents/models/testData/createEvolyAgentProduct.js +0 -477
- package/dist/agents/models/testData/old/updateAgentWorkflowConfiguration.js +0 -230
- package/dist/agents/models/testData/setupEvolyAgentProductConfig.js +0 -233
- package/dist/agents/models/testData/updateAgentWorkflowConfiguration.js +0 -230
- package/dist/agents/models/workflowConversation.js +0 -53
- package/dist/agents/tools/setTemplateWorkflowCommunityId.js +0 -46
- package/dist/app.js +0 -943
- package/dist/authorization.cjs +0 -1860
- package/dist/bot_control.js +0 -1930
- package/dist/config/config.cjs +0 -14
- package/dist/config/config.js +0 -14
- package/dist/controllers/allOurIdeas.js +0 -696
- package/dist/controllers/audios.cjs +0 -100
- package/dist/controllers/bulkStatusUpdates.cjs +0 -202
- package/dist/controllers/categories.cjs +0 -199
- package/dist/controllers/communities.cjs +0 -2996
- package/dist/controllers/domains.cjs +0 -1341
- package/dist/controllers/externalIds.cjs +0 -223
- package/dist/controllers/groups.cjs +0 -4309
- package/dist/controllers/images.cjs +0 -499
- package/dist/controllers/index.cjs +0 -449
- package/dist/controllers/legacyPages.cjs +0 -35
- package/dist/controllers/legacyPosts.cjs +0 -56
- package/dist/controllers/legacyUsers.cjs +0 -36
- package/dist/controllers/nonSpa.cjs +0 -574
- package/dist/controllers/organizations.cjs +0 -250
- package/dist/controllers/points.cjs +0 -1137
- package/dist/controllers/posts.cjs +0 -2036
- package/dist/controllers/ratings.cjs +0 -234
- package/dist/controllers/users.cjs +0 -2255
- package/dist/controllers/videos.cjs +0 -226
- package/dist/deleteUnwantedDeclerations.cjs +0 -55
- package/dist/migrations/agentAuditLogs.cjs +0 -46
- package/dist/migrations/agentClasses.cjs +0 -60
- package/dist/migrations/agentConnectorClasses.cjs +0 -61
- package/dist/migrations/agentConnectors.cjs +0 -50
- package/dist/migrations/agentEvals.cjs +0 -45
- package/dist/migrations/agentRegistries.cjs +0 -40
- package/dist/migrations/agents.cjs +0 -54
- package/dist/migrations/aiModels.cjs +0 -49
- package/dist/migrations/apiUsage.cjs +0 -47
- package/dist/migrations/apis.cjs +0 -49
- package/dist/migrations/groupPrivateData.cjs +0 -30
- package/dist/migrations/modelUsage.cjs +0 -60
- package/dist/migrations/oldMigrations/2019/20181030020612-AddActivitiesIndex.js +0 -23
- package/dist/migrations/oldMigrations/2019/20181102210612-AddFirstVideoFeatures.js +0 -360
- package/dist/migrations/oldMigrations/2019/20181212210612-ModerationFeatures.js +0 -29
- package/dist/migrations/oldMigrations/2019/2019010610612-CommunityFolders.js +0 -43
- package/dist/migrations/oldMigrations/2019/20190117020612-AddMissingIndexes.js +0 -24
- package/dist/migrations/oldMigrations/2019/20190117020612-RemoveUnusedIndexes.js +0 -29
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartThree.js +0 -22
- package/dist/migrations/oldMigrations/2019/20190127020612-RemoveUnusedIndexesPartTwo.js +0 -23
- package/dist/migrations/oldMigrations/2019/20190223020612-AddPrivateProfileDataToUsers.js +0 -18
- package/dist/migrations/oldMigrations/2019/20190706210612-AddCustomRatings.js +0 -43
- package/dist/migrations/oldMigrations/2019/20190829210612-AddGeneralStore.js +0 -36
- package/dist/migrations/oldMigrations/2019/20192811210612-AddAcClientActivities.js +0 -41
- package/dist/migrations/oldMigrations/2020/20190527020612-WorkOnIndexes.js +0 -88
- package/dist/migrations/oldMigrations/2020/20200409020612-AddBackgroundJob.js +0 -33
- package/dist/migrations/oldMigrations/2020/20200716210612-AddDataToCollections.js +0 -38
- package/dist/migrations/oldMigrations/2022/20220215100612-AddDataToEndorsements.js +0 -19
- package/dist/migrations/oldMigrations/2022/20220220100612-AddDataForFraudDetection.js +0 -19
- package/dist/migrations/oldMigrations/2022/20220903100612-AddPromotionFeatures.js +0 -127
- package/dist/migrations/oldMigrations/2022/onHold/20200527020612-AddCampaigns.js +0 -68
- package/dist/migrations/oldMigrations/2024/20241304175112-AddMediaSupportForHtmlGroups.cjs +0 -63
- package/dist/migrations/oldMigrations/older/20160511172514-AddNotificationFeatures.js +0 -14
- package/dist/migrations/oldMigrations/older/20161030020612-AddBulkStatusUpdate.js +0 -71
- package/dist/migrations/oldMigrations/older/20170514035258-add-metadata-to-invites.js +0 -12
- package/dist/migrations/oldMigrations/older/20180216020612-AddTranslationCaches.js +0 -46
- package/dist/migrations/oldMigrations/older/20180218210612-AddTranslationAndLanguages.js +0 -46
- package/dist/migrations/privateAccessStore.cjs +0 -55
- package/dist/migrations/zzz_associations.cjs +0 -154
- package/dist/migrations/zzzz_createUsersAndAdminsForClasses.cjs +0 -100
- package/dist/migrations/zzzzz_create_agent_runs.cjs +0 -606
- package/dist/migrations/zzzzzz_create_agent_runs_fix.cjs +0 -11
- package/dist/migrations/zzzzzzz_create_trees.cjs +0 -81
- package/dist/models/audio.cjs +0 -430
- package/dist/models/bulk_status_update.cjs +0 -58
- package/dist/models/campaign.cjs +0 -78
- package/dist/models/category.cjs +0 -94
- package/dist/models/community.cjs +0 -337
- package/dist/models/domain.cjs +0 -486
- package/dist/models/endorsement.cjs +0 -39
- package/dist/models/general_data_store.cjs +0 -20
- package/dist/models/group.cjs +0 -728
- package/dist/models/image.cjs +0 -579
- package/dist/models/index.cjs +0 -186
- package/dist/models/invite.cjs +0 -48
- package/dist/models/iso_country.cjs +0 -16
- package/dist/models/organization.cjs +0 -122
- package/dist/models/page.cjs +0 -273
- package/dist/models/point.cjs +0 -622
- package/dist/models/point_quality.cjs +0 -39
- package/dist/models/point_revision.cjs +0 -47
- package/dist/models/post.cjs +0 -680
- package/dist/models/post_revision.cjs +0 -38
- package/dist/models/post_status_change.cjs +0 -35
- package/dist/models/promotion.cjs +0 -34
- package/dist/models/rating.cjs +0 -51
- package/dist/models/relationship.cjs +0 -19
- package/dist/models/request_to_join.cjs +0 -20
- package/dist/models/user.cjs +0 -604
- package/dist/models/user_legacy_password.cjs +0 -13
- package/dist/models/video.cjs +0 -1137
- package/dist/publish.js +0 -40
- package/dist/repack.js +0 -53
- package/dist/scripts/addRatingUsersToGroup.js +0 -51
- package/dist/scripts/addUserToOrganization.js +0 -71
- package/dist/scripts/analyseRatingsForCommunity.js +0 -150
- package/dist/scripts/analyzeAndFixBrokenPointUsers.js +0 -28
- package/dist/scripts/analyzeEndorsementsByCountry.js +0 -70
- package/dist/scripts/analyzePostsForCommunity.js +0 -185
- package/dist/scripts/bulkStatusUpdates/listUpdates.js +0 -14
- package/dist/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.js +0 -110
- package/dist/scripts/bulkStatusUpdates/performUpdate.js +0 -116
- package/dist/scripts/bulkStatusUpdates/performUpdateForGroup.cjs +0 -124
- package/dist/scripts/bulkStatusUpdates/performUpdateForStatus.js +0 -141
- package/dist/scripts/change/changeVideoAspectTo.js +0 -34
- package/dist/scripts/change/setUseNewVersion.cjs +0 -22
- package/dist/scripts/changeCommunityGroupcount.js +0 -30
- package/dist/scripts/changeCommunityPostCount.js +0 -30
- package/dist/scripts/changeGroupPostCount.js +0 -30
- package/dist/scripts/changeLanguage.js +0 -50
- package/dist/scripts/changeOfficalStatus.js +0 -30
- package/dist/scripts/cleanups/deleteAnonNotifications.cjs +0 -91
- package/dist/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.js +0 -62
- package/dist/scripts/cleanups/deleteYearOldNotifications.cjs +0 -72
- package/dist/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.js +0 -43
- package/dist/scripts/clearAllEndorsementInGroup.js +0 -50
- package/dist/scripts/cloning/clearUsersForCommunitiesFromUrl.js +0 -129
- package/dist/scripts/cloning/cloneFromUrlScript.js +0 -65
- package/dist/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.js +0 -140
- package/dist/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.js +0 -140
- package/dist/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.js +0 -131
- package/dist/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.js +0 -173
- package/dist/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.js +0 -18
- package/dist/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.js +0 -17
- package/dist/scripts/cloning/copyCommunityToDomainWithEverything.js +0 -17
- package/dist/scripts/cloning/copyCommunityToDomainWithOnlyGroups.js +0 -26
- package/dist/scripts/cloning/copyGroupConfigAndTranslationsFromURL.js +0 -205
- package/dist/scripts/cloning/copyPostToGroupOld.js +0 -397
- package/dist/scripts/cloning/copyPostVideosFromURL.js +0 -236
- package/dist/scripts/cloning/copyPostWithOutAnyVotingOrActivities.js +0 -17
- package/dist/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.js +0 -131
- package/dist/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.js +0 -139
- package/dist/scripts/cloning/setAdminsFromURL.js +0 -161
- package/dist/scripts/cloning/setExternalIdsFromURL.js +0 -129
- package/dist/scripts/countCommunity.js +0 -291
- package/dist/scripts/countCommunityUsers.js +0 -152
- package/dist/scripts/countDelayedNotifications.js +0 -18
- package/dist/scripts/countGroup.js +0 -246
- package/dist/scripts/countStuff.js +0 -67
- package/dist/scripts/countUniqueVotersInAGroup.js +0 -48
- package/dist/scripts/createInvitesAndShow.js +0 -75
- package/dist/scripts/database/sync_database.js +0 -14
- package/dist/scripts/database/sync_dev_database.js +0 -17
- package/dist/scripts/debugNotifications.js +0 -58
- package/dist/scripts/deleteAllNewsFeeds.js +0 -10
- package/dist/scripts/deleteCategory.js +0 -13
- package/dist/scripts/deleteOldAppActivities.js +0 -40
- package/dist/scripts/deletePostContactDataForCommunity.js +0 -53
- package/dist/scripts/destroy/destroy_all_but_one_domain.js +0 -1026
- package/dist/scripts/displayAuthorForPost.js +0 -16
- package/dist/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.js +0 -183
- package/dist/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.js +0 -208
- package/dist/scripts/exportAllStatusChanges.js +0 -36
- package/dist/scripts/exportClientAcitivity.js +0 -36
- package/dist/scripts/exportEndorsementsForCommunity.js +0 -79
- package/dist/scripts/exportPointQualitiesForCommunity.js +0 -84
- package/dist/scripts/exportPostsAndPointsForCommunity.js +0 -147
- package/dist/scripts/exportPostsDataSetForDomain.js +0 -244
- package/dist/scripts/exportPostsForGroup.js +0 -173
- package/dist/scripts/exportRatingsForPost.js +0 -15
- package/dist/scripts/exportUserEndorsementsWithUserAnalysis.js +0 -123
- package/dist/scripts/exportUsersForCommunity.js +0 -24
- package/dist/scripts/exportUsersForDomain.js +0 -24
- package/dist/scripts/exportUsersForGroup.js +0 -24
- package/dist/scripts/exports/ratingDistribution.js +0 -71
- package/dist/scripts/exports/whoEndorsedWhatByCommunity.js +0 -56
- package/dist/scripts/findUnusedClientImports.js +0 -56
- package/dist/scripts/fixAllPostPointCounts.js +0 -22
- package/dist/scripts/fixAnonNotificationsSettings.js +0 -48
- package/dist/scripts/fixCountKopavogur.js +0 -9
- package/dist/scripts/fixEndorsementsAfterCopyPostToGroup.js +0 -190
- package/dist/scripts/fixExternalUserId.js +0 -24
- package/dist/scripts/fixGroupAccess.js +0 -16
- package/dist/scripts/fixGroupIdeasAndPointsCount.js +0 -49
- package/dist/scripts/fixNotificationSettings.js +0 -39
- package/dist/scripts/fixSurveyRadioBakedInSubCodes.js +0 -64
- package/dist/scripts/fixWrongUserIdForStatusUpdates.js +0 -49
- package/dist/scripts/gallery/exportGalleryData.js +0 -40
- package/dist/scripts/gallery/importGalleryForCommunity.js +0 -168
- package/dist/scripts/gallery/readJsonAndDownloadImagesVersion2.js +0 -55
- package/dist/scripts/gallery/refreshAcApiPostIdsForCommunity.js +0 -58
- package/dist/scripts/genderAnalysis.js +0 -63
- package/dist/scripts/genderAnalysisByStatus.js +0 -62
- package/dist/scripts/importAllLocalesFromLocalFolders.js +0 -55
- package/dist/scripts/importDomain.js +0 -1652
- package/dist/scripts/keys/addOidcToDomain.cjs +0 -61
- package/dist/scripts/landUseGame/export3Ddata.js +0 -162
- package/dist/scripts/listLanguagesForGroup.js +0 -54
- package/dist/scripts/loadTestCreateDummyContentForGroup.js +0 -27
- package/dist/scripts/makeRecursiveMapData.js +0 -103
- package/dist/scripts/mapping/community_map_csv.js +0 -145
- package/dist/scripts/moveCommunityToDomain.js +0 -22
- package/dist/scripts/moveGroupToCommunity.js +0 -23
- package/dist/scripts/movePostToGroup.js +0 -101
- package/dist/scripts/movePostsToGroupsRecountGroupFromUrl.js +0 -297
- package/dist/scripts/oldMovePostToGroup.js +0 -153
- package/dist/scripts/processCsvForPdfUrls.js +0 -37
- package/dist/scripts/processCsvForTranslationAndToxicity.js +0 -125
- package/dist/scripts/recount/recount_recursive_communities.js +0 -125
- package/dist/scripts/recountALLCommunityGroupCounts.js +0 -37
- package/dist/scripts/recountAll.js +0 -97
- package/dist/scripts/recountCommunitesFromUrl.js +0 -58
- package/dist/scripts/recountCommunity.js +0 -19
- package/dist/scripts/recountGroup.js +0 -218
- package/dist/scripts/recountGroupNoUserChange.js +0 -219
- package/dist/scripts/resetAllEndorsementsForGroup.js +0 -57
- package/dist/scripts/resetEnTranslationForGroup.js +0 -45
- package/dist/scripts/setAdminOnAll.cjs +0 -107
- package/dist/scripts/setDomainAdmin.cjs +0 -43
- package/dist/scripts/setDomainLocales.js +0 -33
- package/dist/scripts/setEarlQuestionIdOnGroup.cjs +0 -29
- package/dist/scripts/setLanguageOnGroupCommunitesFromUrl.js +0 -86
- package/dist/scripts/setMemberOfAll.js +0 -101
- package/dist/scripts/setNewUserForContentOfCommunity.js +0 -189
- package/dist/scripts/setOfficialStatusOnAllPostsForCommunity.js +0 -35
- package/dist/scripts/setUserOnAll.js +0 -101
- package/dist/scripts/showCategoryForGroup.js +0 -18
- package/dist/scripts/showOldActivityTypes.js +0 -14
- package/dist/scripts/showPostsMissingCategoryForGroup.js +0 -17
- package/dist/scripts/showStatuses.js +0 -17
- package/dist/scripts/showUniqueVotersInCommunity.js +0 -61
- package/dist/scripts/showUserAgentsAndIpsForEmails.js +0 -66
- package/dist/scripts/simpleExportForGroupsForCommunity.js +0 -46
- package/dist/scripts/simpleExportForPointsForCommunity.js +0 -82
- package/dist/scripts/simpleExportForPostsForCommunity.js +0 -61
- package/dist/scripts/testForEndorsments.js +0 -21
- package/dist/scripts/undeleteGroupAndAllContent.js +0 -151
- package/dist/scripts/undeletePost.js +0 -135
- package/dist/scripts/unlinkSsn.js +0 -23
- package/dist/scripts/updateFromAlthingi.js +0 -303
- package/dist/server.js +0 -3
- package/dist/utils/airbrake.cjs +0 -17
- package/dist/utils/cjsCodeReview.js +0 -99
- package/dist/utils/community_mapping_tools.cjs +0 -124
- package/dist/utils/copy_utils.cjs +0 -1399
- package/dist/utils/docx_utils.cjs +0 -464
- package/dist/utils/export_utils.cjs +0 -491
- package/dist/utils/i18n.cjs +0 -17
- package/dist/utils/is_valid_db_id.cjs +0 -28
- package/dist/utils/logger.cjs +0 -25
- package/dist/utils/loggerTs.js +0 -26
- package/dist/utils/manifest_generator.cjs +0 -104
- package/dist/utils/parse_domain.cjs +0 -16
- package/dist/utils/recount_utils.cjs +0 -415
- package/dist/utils/sharing_parameters.cjs +0 -111
- package/dist/utils/sitemap_generator.cjs +0 -286
- package/dist/utils/to_json.cjs +0 -14
- package/dist/utils/ypLanguages.js +0 -747
- package/dist/webSockets.js +0 -77
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var express = require('express');
|
|
3
|
-
var router = express.Router();
|
|
4
|
-
var models = require("../../models/index.cjs");
|
|
5
|
-
var auth = require('../../authorization.cjs');
|
|
6
|
-
var log = require('../utils/logger.cjs');
|
|
7
|
-
var _ = require('lodash');
|
|
8
|
-
var moment = require('moment');
|
|
9
|
-
var getRecommendationFor = require('../engine/recommendations/events_manager.cjs').getRecommendationFor;
|
|
10
|
-
var airbrake = null;
|
|
11
|
-
if (process.env.AIRBRAKE_PROJECT_ID) {
|
|
12
|
-
airbrake = require('../utils/airbrake.cjs');
|
|
13
|
-
}
|
|
14
|
-
var OVERALL_LIMIT = 7;
|
|
15
|
-
var DATE_OPTIONS = { name: "date", after: moment().add(-1000, 'months').toISOString() };
|
|
16
|
-
//var DATE_OPTIONS_YEAR = { name:"date", after: moment().add(-300, 'months').toISOString() };
|
|
17
|
-
var setupOptions = function (req) {
|
|
18
|
-
var options = {
|
|
19
|
-
user_id: req.user ? req.user.id : -1
|
|
20
|
-
};
|
|
21
|
-
return options;
|
|
22
|
-
};
|
|
23
|
-
var processRecommendations = function (levelType, req, res, recommendedItemIds, error) {
|
|
24
|
-
if (error) {
|
|
25
|
-
log.error("Recommendation Error " + levelType, { err: error, id: req.params.id, userId: req.user ? req.user.id : -1, errorStatus: 500 });
|
|
26
|
-
if (airbrake) {
|
|
27
|
-
airbrake.notify(error).then((airbrakeErr) => {
|
|
28
|
-
if (airbrakeErr.error) {
|
|
29
|
-
log.error("AirBrake Error", { context: 'airbrake', err: airbrakeErr.error, errorStatus: 500 });
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
res.send([]);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
if (recommendedItemIds.length > OVERALL_LIMIT) {
|
|
37
|
-
recommendedItemIds = _.dropRight(recommendedItemIds, recommendedItemIds.length - OVERALL_LIMIT);
|
|
38
|
-
}
|
|
39
|
-
log.info("Recommendations domains status", { recommendedItemIds: recommendedItemIds });
|
|
40
|
-
models.Post.findAll({
|
|
41
|
-
where: {
|
|
42
|
-
id: {
|
|
43
|
-
$in: recommendedItemIds
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
order: [
|
|
47
|
-
[{ model: models.Image, as: 'PostHeaderImages' }, 'updated_at', 'asc'],
|
|
48
|
-
[{ model: models.Video, as: "PostVideos" }, { model: models.Image, as: 'VideoImages' }, 'updated_at', 'asc']
|
|
49
|
-
],
|
|
50
|
-
attributes: ['id', 'name', 'description', 'public_data', 'status', 'content_type', 'official_status', 'counter_endorsements_up', 'cover_media_type',
|
|
51
|
-
'counter_endorsements_down', 'group_id', 'language', 'counter_points', 'counter_flags', 'location', 'created_at'],
|
|
52
|
-
include: [
|
|
53
|
-
{
|
|
54
|
-
// Category
|
|
55
|
-
model: models.Category,
|
|
56
|
-
required: false,
|
|
57
|
-
include: [
|
|
58
|
-
{
|
|
59
|
-
model: models.Image,
|
|
60
|
-
required: false,
|
|
61
|
-
as: 'CategoryIconImages'
|
|
62
|
-
}
|
|
63
|
-
]
|
|
64
|
-
},
|
|
65
|
-
// Group
|
|
66
|
-
{
|
|
67
|
-
model: models.Group,
|
|
68
|
-
required: true,
|
|
69
|
-
attributes: models.Group.defaultAttributesPublic,
|
|
70
|
-
where: {
|
|
71
|
-
status: {
|
|
72
|
-
$in: ['active', 'featured']
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
include: [
|
|
76
|
-
{
|
|
77
|
-
model: models.Category,
|
|
78
|
-
required: false
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
model: models.Community,
|
|
82
|
-
attributes: ['id', 'name', 'theme_id'],
|
|
83
|
-
required: false
|
|
84
|
-
}
|
|
85
|
-
]
|
|
86
|
-
},
|
|
87
|
-
{
|
|
88
|
-
model: models.Video,
|
|
89
|
-
required: false,
|
|
90
|
-
attributes: ['id', 'formats', 'updated_at', 'viewable', 'public_meta'],
|
|
91
|
-
as: 'PostVideos',
|
|
92
|
-
include: [
|
|
93
|
-
{
|
|
94
|
-
model: models.Image,
|
|
95
|
-
as: 'VideoImages',
|
|
96
|
-
attributes: ["formats", 'updated_at'],
|
|
97
|
-
required: false
|
|
98
|
-
},
|
|
99
|
-
]
|
|
100
|
-
},
|
|
101
|
-
// User
|
|
102
|
-
{
|
|
103
|
-
model: models.User,
|
|
104
|
-
required: false,
|
|
105
|
-
attributes: models.User.defaultAttributesWithSocialMediaPublic
|
|
106
|
-
},
|
|
107
|
-
// Image
|
|
108
|
-
{
|
|
109
|
-
model: models.Image,
|
|
110
|
-
required: false,
|
|
111
|
-
as: 'PostHeaderImages'
|
|
112
|
-
},
|
|
113
|
-
// PointRevision
|
|
114
|
-
{
|
|
115
|
-
model: models.PostRevision,
|
|
116
|
-
required: false
|
|
117
|
-
}
|
|
118
|
-
]
|
|
119
|
-
}).then(function (posts) {
|
|
120
|
-
res.send(posts);
|
|
121
|
-
}).catch(function (error) {
|
|
122
|
-
log.error("Recommendation Error " + levelType, { err: error, id: req.params.id, userId: req.user ? req.user.id : -1, errorStatus: 500 });
|
|
123
|
-
if (airbrake) {
|
|
124
|
-
airbrake.notify(error).then((airbrakeErr) => {
|
|
125
|
-
if (airbrakeErr.error) {
|
|
126
|
-
log.error("AirBrake Error", { context: 'airbrake', err: airbrakeErr.error, errorStatus: 500 });
|
|
127
|
-
}
|
|
128
|
-
res.send([]);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
res.send([]);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var processRecommendationsLight = function (groupId, req, res, recommendedItemIds, error, redisCacheKey) {
|
|
138
|
-
if (error) {
|
|
139
|
-
log.error("processRecommendationsLight Error", { err: error, userId: req.user ? req.user.id : -1, errorStatus: 500 });
|
|
140
|
-
if (airbrake) {
|
|
141
|
-
airbrake.notify(error).then((airbrakeErr) => {
|
|
142
|
-
if (airbrakeErr.error) {
|
|
143
|
-
log.error("AirBrake Error", { context: 'airbrake', err: airbrakeErr.error, errorStatus: 500 });
|
|
144
|
-
}
|
|
145
|
-
res.send({ recommendations: [], groupId: groupId });
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
res.send({ recommendations: [], groupId: groupId });
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
else if (!recommendedItemIds) {
|
|
153
|
-
log.error("processRecommendationsLight no recommendedItemIds", { userId: req.user ? req.user.id : -1, errorStatus: 500 });
|
|
154
|
-
res.send({ recommendations: [], groupId: groupId });
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
log.info("processRecommendationsLight for group status");
|
|
158
|
-
models.Post.findAll({
|
|
159
|
-
where: {
|
|
160
|
-
id: {
|
|
161
|
-
$in: recommendedItemIds
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
attributes: ['id', 'name', 'description'],
|
|
165
|
-
include: [
|
|
166
|
-
{
|
|
167
|
-
model: models.Group,
|
|
168
|
-
required: true,
|
|
169
|
-
attributes: models.Group.defaultAttributesPublic,
|
|
170
|
-
where: {
|
|
171
|
-
id: groupId
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
]
|
|
175
|
-
}).then(function (posts) {
|
|
176
|
-
posts.sort(function (a, b) {
|
|
177
|
-
return recommendedItemIds.indexOf(a.id) - recommendedItemIds.indexOf(b.id);
|
|
178
|
-
});
|
|
179
|
-
const recommendationsInfo = { recommendations: posts, groupId: groupId };
|
|
180
|
-
if (redisCacheKey) {
|
|
181
|
-
req.redisClient.setEx(redisCacheKey, process.env.RECOMMENDATIONS_CACHE_TTL ? parseInt(process.env.RECOMMENDATIONS_CACHE_TTL) : 5, JSON.stringify(recommendationsInfo));
|
|
182
|
-
}
|
|
183
|
-
res.send(recommendationsInfo);
|
|
184
|
-
}).catch(function (error) {
|
|
185
|
-
log.error("processRecommendationsLight Error ", { err: error, userId: req.user ? req.user.id : -1, errorStatus: 500 });
|
|
186
|
-
if (airbrake) {
|
|
187
|
-
airbrake.notify(error).then((airbrakeErr) => {
|
|
188
|
-
if (airbrakeErr.error) {
|
|
189
|
-
log.error("AirBrake Error", { context: 'airbrake', err: airbrakeErr.error, errorStatus: 500 });
|
|
190
|
-
}
|
|
191
|
-
res.send({ recommendations: [], groupId: groupId });
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
res.send({ recommendations: [], groupId: groupId });
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
router.get('/domains/:id', auth.can('view domain'), function (req, res) {
|
|
201
|
-
var options = setupOptions(req);
|
|
202
|
-
options = _.merge(options, {
|
|
203
|
-
domain_id: req.params.id,
|
|
204
|
-
limit: OVERALL_LIMIT * 2
|
|
205
|
-
});
|
|
206
|
-
getRecommendationFor(req, options.user_id, DATE_OPTIONS, options, function (error, recommendedItemIds) {
|
|
207
|
-
processRecommendations("domain", req, res, recommendedItemIds, error);
|
|
208
|
-
}, req.user ? req.user.default_locale : null);
|
|
209
|
-
});
|
|
210
|
-
router.get('/communities/:id', auth.can('view community'), function (req, res) {
|
|
211
|
-
var options = setupOptions(req);
|
|
212
|
-
options = _.merge(options, {
|
|
213
|
-
community_id: req.params.id,
|
|
214
|
-
limit: OVERALL_LIMIT * 2
|
|
215
|
-
}, req.user ? req.user.default_locale : null);
|
|
216
|
-
getRecommendationFor(req, options.user_id, DATE_OPTIONS, options, function (error, recommendedItemIds) {
|
|
217
|
-
processRecommendations("community", req, res, recommendedItemIds, error);
|
|
218
|
-
}, req.user ? req.user.default_locale : null);
|
|
219
|
-
});
|
|
220
|
-
router.get('/groups/:id', auth.can('view group'), function (req, res) {
|
|
221
|
-
var options = setupOptions(req);
|
|
222
|
-
options = _.merge(options, {
|
|
223
|
-
group_id: req.params.id,
|
|
224
|
-
limit: OVERALL_LIMIT * 2
|
|
225
|
-
});
|
|
226
|
-
getRecommendationFor(req, options.user_id, DATE_OPTIONS, options, function (error, recommendedItemIds) {
|
|
227
|
-
processRecommendations("group", req, res, recommendedItemIds, error);
|
|
228
|
-
}, req.user ? req.user.default_locale : null);
|
|
229
|
-
});
|
|
230
|
-
router.put('/groups/:id/getPostRecommendations', auth.can('view group'), function (req, res) {
|
|
231
|
-
const redisCacheKey = "cache:getPostRecommendations:" + req.params.id + ":userId:" + (req.user ? req.user.id : "notLoggedIn");
|
|
232
|
-
req.redisClient.get(redisCacheKey).then(recommendations => {
|
|
233
|
-
if (recommendations) {
|
|
234
|
-
res.send(JSON.parse(recommendations));
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
var options = setupOptions(req);
|
|
238
|
-
options = _.merge(options, {
|
|
239
|
-
group_id: req.params.id,
|
|
240
|
-
limit: 100
|
|
241
|
-
});
|
|
242
|
-
models.Group.findOne({
|
|
243
|
-
where: {
|
|
244
|
-
id: req.params.id
|
|
245
|
-
},
|
|
246
|
-
attributes: [
|
|
247
|
-
'id', 'configuration'
|
|
248
|
-
]
|
|
249
|
-
}).then(group => {
|
|
250
|
-
if (group) {
|
|
251
|
-
var dateOptions = null; //DATE_OPTIONS_YEAR;
|
|
252
|
-
if (group.configuration && group.configuration.maxDaysBackForRecommendations && group.configuration.maxDaysBackForRecommendations) {
|
|
253
|
-
var maxDays = parseInt(group.configuration.maxDaysBackForRecommendations);
|
|
254
|
-
dateOptions = { name: "date", after: moment().add(-Math.abs(maxDays), 'days').toISOString() };
|
|
255
|
-
}
|
|
256
|
-
getRecommendationFor(req, options.user_id, dateOptions, options, function (error, recommendedItemIds) {
|
|
257
|
-
if (!error) {
|
|
258
|
-
processRecommendationsLight(req.params.id, req, res, recommendedItemIds, error, redisCacheKey);
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
log.error("Error from getRecommendationFor", { error });
|
|
262
|
-
res.send({ recommendations: [], groupId: req.params.id });
|
|
263
|
-
}
|
|
264
|
-
}, req.user ? req.user.default_locale : null);
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
log.error("Group not found");
|
|
268
|
-
res.send({ recommendations: [], groupId: req.params.id });
|
|
269
|
-
}
|
|
270
|
-
}).catch(error => {
|
|
271
|
-
log.error(error);
|
|
272
|
-
res.send({ recommendations: [], groupId: req.params.id });
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}).catch(error => {
|
|
276
|
-
log.error(error);
|
|
277
|
-
res.send({ recommendations: [], groupId: req.params.id });
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
module.exports = router;
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { OpenAI } from "openai";
|
|
2
|
-
export class AiHelper {
|
|
3
|
-
constructor(wsClientSocket = undefined) {
|
|
4
|
-
this.modelName = "gpt-4o";
|
|
5
|
-
this.maxTokens = 2048;
|
|
6
|
-
this.temperature = 0.7;
|
|
7
|
-
this.cacheExpireTime = 60 * 60;
|
|
8
|
-
this.moderationSystemPrompt = (instructions) => `The user will provide you with a question and an answer.
|
|
9
|
-
Your job is to moderate the answer if it passes automated moderation or not.
|
|
10
|
-
Moderation instructions:
|
|
11
|
-
${instructions}
|
|
12
|
-
|
|
13
|
-
Only output: PASSES or FAILS`;
|
|
14
|
-
this.moderationUserPrompt = (question, answer) => `
|
|
15
|
-
Question: ${question}
|
|
16
|
-
Answer: ${answer}
|
|
17
|
-
`;
|
|
18
|
-
this.getModerationResponse = async (instructions, question, answerToModerate) => {
|
|
19
|
-
const messages = [
|
|
20
|
-
{
|
|
21
|
-
role: "system",
|
|
22
|
-
content: this.moderationSystemPrompt(instructions),
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
role: "user",
|
|
26
|
-
content: this.moderationUserPrompt(question, answerToModerate),
|
|
27
|
-
},
|
|
28
|
-
];
|
|
29
|
-
console.log(JSON.stringify(messages, null, 2));
|
|
30
|
-
const response = await this.openaiClient.chat.completions.create({
|
|
31
|
-
model: this.modelName,
|
|
32
|
-
messages,
|
|
33
|
-
max_tokens: 5,
|
|
34
|
-
temperature: 0,
|
|
35
|
-
});
|
|
36
|
-
if (response &&
|
|
37
|
-
response.choices &&
|
|
38
|
-
response.choices[0] &&
|
|
39
|
-
response.choices[0].message &&
|
|
40
|
-
response.choices[0].message.content) {
|
|
41
|
-
console.log("Moderation response:", response.choices[0].message.content);
|
|
42
|
-
return ["PASSES", "PASS"].includes(response.choices[0].message.content.toUpperCase())
|
|
43
|
-
? true
|
|
44
|
-
: false;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
this.openaiClient = new OpenAI({
|
|
51
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
52
|
-
});
|
|
53
|
-
this.wsClientSocket = wsClientSocket;
|
|
54
|
-
}
|
|
55
|
-
async streamChatCompletions(messages) {
|
|
56
|
-
const stream = await this.openaiClient.chat.completions.create({
|
|
57
|
-
model: this.modelName,
|
|
58
|
-
messages,
|
|
59
|
-
max_tokens: this.maxTokens,
|
|
60
|
-
temperature: this.temperature,
|
|
61
|
-
stream: true,
|
|
62
|
-
});
|
|
63
|
-
await this.streamWebSocketResponses(stream);
|
|
64
|
-
}
|
|
65
|
-
sendToClient(sender, message, type = "stream") {
|
|
66
|
-
this.wsClientSocket?.send(JSON.stringify({
|
|
67
|
-
sender,
|
|
68
|
-
type: type,
|
|
69
|
-
message,
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
async streamWebSocketResponses(stream) {
|
|
73
|
-
return new Promise(async (resolve, reject) => {
|
|
74
|
-
this.sendToClient("bot", "", "start");
|
|
75
|
-
try {
|
|
76
|
-
let botMessage = "";
|
|
77
|
-
for await (const part of stream) {
|
|
78
|
-
this.sendToClient("bot", part.choices[0].delta.content);
|
|
79
|
-
botMessage += part.choices[0].delta.content;
|
|
80
|
-
}
|
|
81
|
-
if (this.redisClient && this.cacheKeyForFullResponse) {
|
|
82
|
-
this.redisClient.set(this.cacheKeyForFullResponse, botMessage, "EX", this.cacheExpireTime);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
console.error(error);
|
|
87
|
-
this.sendToClient("bot", "There has been an error, please retry", "error");
|
|
88
|
-
reject();
|
|
89
|
-
}
|
|
90
|
-
finally {
|
|
91
|
-
this.sendToClient("bot", "", "end");
|
|
92
|
-
}
|
|
93
|
-
resolve();
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
async getAnswerIdeas(question, previousIdeas, firstMessage) {
|
|
97
|
-
try {
|
|
98
|
-
const moderationResponse = await this.openaiClient.moderations.create({
|
|
99
|
-
input: question,
|
|
100
|
-
});
|
|
101
|
-
console.log("Moderation response:", moderationResponse);
|
|
102
|
-
const flagged = moderationResponse.results[0].flagged;
|
|
103
|
-
console.log("Flagged:", flagged);
|
|
104
|
-
if (flagged) {
|
|
105
|
-
console.error("Flagged:", question);
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
let firstMessageWithPreviousIdeasTemplate = "";
|
|
110
|
-
let previewIdeasText = "";
|
|
111
|
-
if (previousIdeas && previousIdeas.length > 0) {
|
|
112
|
-
previewIdeasText = `Previous answer ideas:\n${JSON.stringify(previousIdeas, null, 2)}\n\n`;
|
|
113
|
-
if (firstMessage) {
|
|
114
|
-
firstMessageWithPreviousIdeasTemplate =
|
|
115
|
-
"For your answers please follow the tone of voice, prose, style, and length of the Previous answer ideas\n";
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const messages = [
|
|
119
|
-
{
|
|
120
|
-
role: "system",
|
|
121
|
-
content: `You are a highly competent AI that is able to generate clear answer ideas for questions.
|
|
122
|
-
Genereate up to 10 high quality answer ideas.
|
|
123
|
-
Never use numbers at the start of each line.
|
|
124
|
-
Always output the ideas in the same language the user is asking the question.
|
|
125
|
-
Never use a dash or quote or anything similar at the start of each line, just start with the text.
|
|
126
|
-
Never output more than 30 words per idea.
|
|
127
|
-
\n${firstMessageWithPreviousIdeasTemplate}`,
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
role: "user",
|
|
131
|
-
content: `What are some possible answers to the question: ${question}\n\n${previewIdeasText}Answers:\n`,
|
|
132
|
-
},
|
|
133
|
-
];
|
|
134
|
-
await this.streamChatCompletions(messages);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
console.error("Error in getAnswerIdeas:", error);
|
|
139
|
-
this.sendToClient("bot", "There has been an error, please retry", "error");
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async getAiAnalysis(questionId, contextPrompt, answers, cacheKeyForFullResponse, redisClient, locale, topOrBottomIdeasText, typeOfAnalysisText) {
|
|
144
|
-
this.redisClient = redisClient;
|
|
145
|
-
this.cacheKeyForFullResponse = cacheKeyForFullResponse;
|
|
146
|
-
const basePrePrompt = `You are a highly competent text and ideas analysis AI.
|
|
147
|
-
Instructions:
|
|
148
|
-
If an answer sounds implausible as an answer to the question, then include a short observation about it in your analysis.
|
|
149
|
-
Keep your output short, under 300 words.
|
|
150
|
-
The answers have been rated by the public using a pairwise voting method, so the user is always selecting one to win or one to lose.
|
|
151
|
-
Generally, do not include the number of wins and losses in your answers.
|
|
152
|
-
If there are very few wins or losses, under 10 for most of the ideas, then always output a disclaimer to that end, in a separate second paragraph.
|
|
153
|
-
Don't output Idea 1, Idea 2 in your answer.
|
|
154
|
-
Be creative and think step by step.
|
|
155
|
-
|
|
156
|
-
Output:
|
|
157
|
-
If the prompt asks for a table always output a markdown table.
|
|
158
|
-
Always output in a clear markdown format.
|
|
159
|
-
Always start with the type of analysis and if those are top or bottom ideas.
|
|
160
|
-
|
|
161
|
-
Example output:
|
|
162
|
-
|
|
163
|
-
## Points for the most popular answers
|
|
164
|
-
|
|
165
|
-
<Your dynamic markdown output>
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
`;
|
|
169
|
-
const answersText = answers
|
|
170
|
-
.map((answer) => `${answer.data.content} (Won: ${answer.wins}, Lost: ${answer.losses})`)
|
|
171
|
-
.join("\n");
|
|
172
|
-
try {
|
|
173
|
-
const moderationResponse = await this.openaiClient.moderations.create({
|
|
174
|
-
input: answersText,
|
|
175
|
-
});
|
|
176
|
-
const flagged = moderationResponse.results[0].flagged;
|
|
177
|
-
if (flagged) {
|
|
178
|
-
console.error("Flagged:", answersText);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
const messages = [
|
|
183
|
-
{
|
|
184
|
-
role: "system",
|
|
185
|
-
content: `${basePrePrompt}\n${contextPrompt}`,
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
role: "user",
|
|
189
|
-
content: `The question: ${questionId}
|
|
190
|
-
${topOrBottomIdeasText}
|
|
191
|
-
Type of analysis: ${typeOfAnalysisText}
|
|
192
|
-
Language to output: ${locale}
|
|
193
|
-
Answers to analyse:\n${answersText}`,
|
|
194
|
-
},
|
|
195
|
-
];
|
|
196
|
-
this.streamChatCompletions(messages);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
catch (error) {
|
|
200
|
-
console.error("Error in getAiAnalysis:", error);
|
|
201
|
-
this.sendToClient("bot", "There has been an error, please retry", "error");
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { OpenAI } from "openai";
|
|
2
|
-
import { YpBaseChatBot } from "../../llms/baseChatBot.js";
|
|
3
|
-
import ioredis from "ioredis";
|
|
4
|
-
import { v4 as uuidv4 } from "uuid";
|
|
5
|
-
const tlsOptions = process.env.REDIS_MEMORY_URL?.startsWith("rediss://")
|
|
6
|
-
? { rejectUnauthorized: false }
|
|
7
|
-
: undefined;
|
|
8
|
-
export class ExplainAnswersAssistant extends YpBaseChatBot {
|
|
9
|
-
constructor(wsClientId, wsClients, languageName) {
|
|
10
|
-
const redisConnection = new ioredis.default(process.env.REDIS_MEMORY_URL ||
|
|
11
|
-
process.env.REDIS_URL ||
|
|
12
|
-
"redis://localhost:6379", {
|
|
13
|
-
tls: tlsOptions,
|
|
14
|
-
});
|
|
15
|
-
super(wsClientId, wsClients, redisConnection, `${YpBaseChatBot.redisMemoryKeyPrefix}-${uuidv4()}-explain-answers-assistant`);
|
|
16
|
-
this.modelName = "gpt-4o";
|
|
17
|
-
this.maxTokens = 4000;
|
|
18
|
-
this.temperature = 0.8;
|
|
19
|
-
this.explainConversation = async (chatLog) => {
|
|
20
|
-
this.setChatLog(chatLog);
|
|
21
|
-
let messages = chatLog.map((message) => {
|
|
22
|
-
return {
|
|
23
|
-
role: message.sender,
|
|
24
|
-
content: message.message,
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
const systemMessage = {
|
|
28
|
-
role: "system",
|
|
29
|
-
content: this.renderSystemPrompt(),
|
|
30
|
-
};
|
|
31
|
-
messages.unshift(systemMessage);
|
|
32
|
-
const stream = await this.openaiClient.chat.completions.create({
|
|
33
|
-
model: this.llmModel,
|
|
34
|
-
messages,
|
|
35
|
-
max_tokens: this.maxTokens,
|
|
36
|
-
temperature: this.temperature,
|
|
37
|
-
stream: true,
|
|
38
|
-
});
|
|
39
|
-
this.streamWebSocketResponses(stream);
|
|
40
|
-
};
|
|
41
|
-
this.languageName = languageName;
|
|
42
|
-
this.openaiClient = new OpenAI({
|
|
43
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
renderSystemPrompt() {
|
|
47
|
-
return `The user is doing pairwise voting on two answers at the time, to a question, the user needs help deciding what to vote on.
|
|
48
|
-
|
|
49
|
-
Instructions:
|
|
50
|
-
Use a relevant emoji for the first and second answers.
|
|
51
|
-
Use thumbs emojis for pros and thumb down emjoi for cons
|
|
52
|
-
Use summary emoji for summary.
|
|
53
|
-
Use simple and upbeat language.
|
|
54
|
-
Ask the user clarifying questions if needed.
|
|
55
|
-
Always answers in the language the user asks for.
|
|
56
|
-
|
|
57
|
-
Output:
|
|
58
|
-
* Each answer
|
|
59
|
-
-- One short paragraph, max three sentences, explanation in a very simple language
|
|
60
|
-
-- The top pro and con
|
|
61
|
-
-- If this is likely to be a root cause of the problem set out in the question
|
|
62
|
-
* Never offer the user your opinion as we don't want to influence the user, they must make their own decision.
|
|
63
|
-
* Always output in this language: ${this.languageName}
|
|
64
|
-
`;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import { v4 as uuidv4 } from "uuid";
|
|
4
|
-
import axios from "axios";
|
|
5
|
-
import models from "../../../models/index.cjs";
|
|
6
|
-
import { CollectionImageGenerator } from "../../llms/imageGeneration/collectionImageGenerator.js";
|
|
7
|
-
const dbModels = models;
|
|
8
|
-
const Image = dbModels.Image;
|
|
9
|
-
export class AoiIconGenerator extends CollectionImageGenerator {
|
|
10
|
-
async createCollectionImage(workPackage) {
|
|
11
|
-
// 1. Generate the image and record using the base implementation.
|
|
12
|
-
const { imageId, imageUrl } = await super.createCollectionImage(workPackage);
|
|
13
|
-
// 2. Now process the image for the icon:
|
|
14
|
-
// Download the generated image to a temporary location.
|
|
15
|
-
const tempIconPath = path.join("/tmp", `${uuidv4()}-icon.png`);
|
|
16
|
-
await this.imageProcessorService.downloadImage(imageUrl, tempIconPath, axios);
|
|
17
|
-
if (!fs.existsSync(tempIconPath)) {
|
|
18
|
-
throw new Error("Failed to download the generated image for icon processing.");
|
|
19
|
-
}
|
|
20
|
-
// Resize the downloaded image to 400x400 pixels.
|
|
21
|
-
const resizedIconPath = await this.imageProcessorService.resizeImage(tempIconPath, 400, 400);
|
|
22
|
-
// Define a new S3 path for the icon image.
|
|
23
|
-
const iconS3ImagePath = `ypGenAi/${workPackage.collectionType}/${workPackage.collectionId}/${uuidv4()}-icon.png`;
|
|
24
|
-
// Upload the resized icon to S3.
|
|
25
|
-
await this.s3Service.uploadImageToS3(process.env.S3_BUCKET, resizedIconPath, iconS3ImagePath);
|
|
26
|
-
// Construct a public URL for the icon image.
|
|
27
|
-
const newIconUrl = process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN
|
|
28
|
-
? `https://${process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN}/${iconS3ImagePath}`
|
|
29
|
-
: `https://${process.env.S3_BUCKET}.s3.amazonaws.com/${iconS3ImagePath}`;
|
|
30
|
-
// Optionally, update the DB record with the new icon URL.
|
|
31
|
-
const imageRecord = await Image.findOne({ where: { id: imageId } });
|
|
32
|
-
if (imageRecord) {
|
|
33
|
-
imageRecord.formats = JSON.stringify([newIconUrl]);
|
|
34
|
-
await imageRecord.save();
|
|
35
|
-
}
|
|
36
|
-
return { imageId, imageUrl: newIconUrl };
|
|
37
|
-
}
|
|
38
|
-
}
|