@yrpri/api 9.0.102 → 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/active-citizen/llms/imageGeneration/chatGptImageGenerator.js +56 -0
- package/active-citizen/llms/imageGeneration/collectionImageGenerator.js +6 -0
- package/agents/controllers/agentProductController.js +2 -1
- package/agents/controllers/agentSubscriptionController.js +20 -11
- package/agents/controllers/assistantsController.js +28 -18
- package/agents/controllers/policySynthAgents.js +33 -12
- package/agents/managers/newAiModelSetup.js +96 -0
- package/agents/managers/subscriptionManager.js +2 -2
- package/app.js +12 -12
- package/authorization.cjs +4 -0
- package/controllers/allOurIdeas.js +2 -1
- package/controllers/communities.cjs +47 -1
- package/controllers/groups.cjs +67 -4
- package/controllers/index.cjs +7 -7
- package/controllers/nonSpa.cjs +1 -1
- package/package.json +46 -44
- package/server.d.ts +104 -2
- package/utils/copy_utils.cjs +7 -1
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts +0 -21
- package/active-citizen/engine/allOurIdeas/aiHelper.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/explainAnswersAssistant.d.ts.map +0 -1
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts +0 -12
- package/active-citizen/engine/allOurIdeas/iconGenerator.d.ts.map +0 -1
- package/active-citizen/engine/analytics/export_anon_community_activities.d.ts.map +0 -1
- package/active-citizen/engine/analytics/importer.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/categories_dataset.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/dataset_tools.d.ts.map +0 -1
- package/active-citizen/engine/old/exporters/sentiment_dataset.d.ts.map +0 -1
- package/active-citizen/engine/reports/xls_all_our_ideas_export.js +0 -141
- package/active-citizen/llms/baseChatBot.d.ts +0 -51
- package/active-citizen/llms/baseChatBot.d.ts.map +0 -1
- package/active-citizen/llms/collectionImageGenerator.js +0 -357
- package/active-citizen/llms/llmTranslation.d.ts +0 -24
- package/active-citizen/llms/llmTranslation.d.ts.map +0 -1
- package/active-citizen/scripts/fix_old_delayed_notifications.d.ts.map +0 -1
- package/active-citizen/scripts/kue_status.d.ts.map +0 -1
- package/active-citizen/scripts/kue_watch_stuck_jobs.d.ts.map +0 -1
- package/active-citizen/scripts/translation_clear_language.d.ts.map +0 -1
- package/active-citizen/scripts/translation_delete.d.ts.map +0 -1
- package/active-citizen/scripts/translation_replace_text_from_url.d.ts.map +0 -1
- package/active-citizen/scripts/translation_update.d.ts.map +0 -1
- package/active-citizen/scripts/translations_list.d.ts.map +0 -1
- package/active-citizen/utils/airbrake.d.ts.map +0 -1
- package/active-citizen/utils/airbrake.js +0 -17
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts +0 -21
- package/active-citizen/utils/updateAllLocalesFromEn.d.ts.map +0 -1
- package/active-citizen/utils/updateLocaleFolders.d.ts +0 -2
- package/active-citizen/utils/updateLocaleFolders.d.ts.map +0 -1
- package/active-citizen/workers/cloudflare/voiceSession/worker.js +0 -213
- package/active-citizen/workers/generativeAi.d.ts.map +0 -1
- package/agents/agentProductManager.js +0 -91
- package/agents/assistants/agentAssistantOld.js +0 -863
- package/agents/assistants/modes/agentConfigurationMode.js +0 -63
- package/agents/assistants/modes/agentOperationsMode.js +0 -195
- package/agents/assistants/modes/commonTools.js +0 -58
- package/agents/assistants/modes/directConversationMode.js +0 -14
- package/agents/assistants/modes/toolHandlers/accountHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/commonHandlers.js +0 -57
- package/agents/assistants/modes/toolHandlers/commonTools.js +0 -58
- package/agents/assistants/modes/toolHandlers/loginHandlers.js +0 -46
- package/agents/assistants/modes/toolHandlers/subscriptionHandlers.js +0 -469
- package/agents/assistants/modes/tools/agentConnectionTools.js +0 -326
- package/agents/assistants/modes/tools/commonHandlers.js +0 -57
- package/agents/assistants/modes/tools/loginHandlers.js +0 -46
- package/agents/assistants/modes/tools/subscriptionHandlers.js +0 -469
- package/agents/assistants/modes/tools/workflowConversationTools.js +0 -326
- package/agents/assistants/modes/tools/workflowTools.js +0 -112
- package/agents/controllers/assistantController.js +0 -243
- package/agents/managers/workflowManager.js +0 -76
- package/agents/models/testData/setupConfig.js +0 -140
- package/agents/models/workflow.js +0 -53
- package/agents/models/workflowConverstation.js +0 -53
- package/agents/subscriptionManager.js +0 -218
- package/agents/tools/updateCommunityWorkflow.js +0 -1
- package/agents/tools/updateTemplateWorkflow.js +0 -45
- package/app.d.ts +0 -40
- package/app.d.ts.map +0 -1
- package/bot_control.d.ts.map +0 -1
- package/migrations/200824_create_embeddings_and_org_update.cjs +0 -15
- package/migrations/270724_createUsersAndAdminsForClasses.cjs +0 -100
- package/publish.d.ts.map +0 -1
- package/repack.d.ts.map +0 -1
- package/scripts/addRatingUsersToGroup.d.ts.map +0 -1
- package/scripts/addUserToOrganization.d.ts.map +0 -1
- package/scripts/analyseRatingsForCommunity.d.ts.map +0 -1
- package/scripts/analyzeAndFixBrokenPointUsers.d.ts.map +0 -1
- package/scripts/analyzeEndorsementsByCountry.d.ts.map +0 -1
- package/scripts/analyzePostsForCommunity.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/listUpdates.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/mergeLatestPostsToUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdate.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForGroup.d.ts.map +0 -1
- package/scripts/bulkStatusUpdates/performUpdateForGroup.js +0 -125
- package/scripts/bulkStatusUpdates/performUpdateForStatus.d.ts.map +0 -1
- package/scripts/change/changeVideoAspectTo.d.ts.map +0 -1
- package/scripts/change/setDomainAdmin.cjs +0 -45
- package/scripts/changeCommunityGroupcount.d.ts.map +0 -1
- package/scripts/changeCommunityPostCount.d.ts.map +0 -1
- package/scripts/changeGroupPostCount.d.ts.map +0 -1
- package/scripts/changeLanguage.d.ts.map +0 -1
- package/scripts/changeOfficalStatus.d.ts.map +0 -1
- package/scripts/cleanups/deleteAnonNotifications.d.ts.map +0 -1
- package/scripts/cleanups/deleteAnonNotifications.js +0 -91
- package/scripts/cleanups/deleteLinkGroupsWithDeletedCommunities.d.ts.map +0 -1
- package/scripts/cleanups/removeAllUsersFromHiddenPublicGroup.d.ts.map +0 -1
- package/scripts/clearAllEndorsementInGroup.d.ts.map +0 -1
- package/scripts/cloning/clearUsersForCommunitiesFromUrl.d.ts.map +0 -1
- package/scripts/cloning/cloneFromUrlScript.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/cloneWBFromUrlScriptNoUsersOrPoints.d.ts.map +0 -1
- package/scripts/cloning/cloneWBSerbianFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityOneGroupToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainNoUsersNoEndorsements.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithEverything.d.ts.map +0 -1
- package/scripts/cloning/copyCommunityToDomainWithOnlyGroups.d.ts.map +0 -1
- package/scripts/cloning/copyGroupConfigAndTranslationsFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostToGroupOld.d.ts.map +0 -1
- package/scripts/cloning/copyPostVideosFromURL.d.ts.map +0 -1
- package/scripts/cloning/copyPostWithOutAnyVotingOrActivities.d.ts.map +0 -1
- package/scripts/cloning/deepCloneSerbianWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/deepCloneWBFromUrlScriptAndCreateLinks.d.ts.map +0 -1
- package/scripts/cloning/setAdminsFromURL.d.ts.map +0 -1
- package/scripts/cloning/setExternalIdsFromURL.d.ts.map +0 -1
- package/scripts/countCommunity.d.ts.map +0 -1
- package/scripts/countCommunityUsers.d.ts.map +0 -1
- package/scripts/countDelayedNotifications.d.ts.map +0 -1
- package/scripts/countGroup.d.ts.map +0 -1
- package/scripts/countStuff.d.ts.map +0 -1
- package/scripts/countUniqueVotersInAGroup.d.ts.map +0 -1
- package/scripts/createInvitesAndShow.d.ts.map +0 -1
- package/scripts/database/seedTestAiModels.js +0 -64
- package/scripts/database/sync_database.d.ts.map +0 -1
- package/scripts/database/sync_dev_database.d.ts.map +0 -1
- package/scripts/debugNotifications.d.ts.map +0 -1
- package/scripts/deleteAllNewsFeeds.d.ts.map +0 -1
- package/scripts/deleteCategory.d.ts.map +0 -1
- package/scripts/deleteOldAppActivities.d.ts.map +0 -1
- package/scripts/deletePostContactDataForCommunity.d.ts.map +0 -1
- package/scripts/destroy/destroy_all_but_one_domain.d.ts.map +0 -1
- package/scripts/displayAuthorForPost.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/analyseEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/endorsementFraudDetection/bulkDeleteDuplicateEndorsmentsFromUrl.d.ts.map +0 -1
- package/scripts/exportAllStatusChanges.d.ts.map +0 -1
- package/scripts/exportClientAcitivity.d.ts.map +0 -1
- package/scripts/exportEndorsementsForCommunity.d.ts.map +0 -1
- package/scripts/exportPointQualitiesForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsAndPointsForCommunity.d.ts.map +0 -1
- package/scripts/exportPostsDataSetForDomain.d.ts.map +0 -1
- package/scripts/exportPostsForGroup.d.ts.map +0 -1
- package/scripts/exportRatingsForPost.d.ts.map +0 -1
- package/scripts/exportUserEndorsementsWithUserAnalysis.d.ts.map +0 -1
- package/scripts/exportUsersForCommunity.d.ts.map +0 -1
- package/scripts/exportUsersForDomain.d.ts.map +0 -1
- package/scripts/exportUsersForGroup.d.ts.map +0 -1
- package/scripts/exports/ratingDistribution.d.ts.map +0 -1
- package/scripts/exports/whoEndorsedWhatByCommunity.d.ts.map +0 -1
- package/scripts/findUnusedClientImports.d.ts.map +0 -1
- package/scripts/fixAllPostPointCounts.d.ts.map +0 -1
- package/scripts/fixAnonNotificationsSettings.d.ts.map +0 -1
- package/scripts/fixCountKopavogur.d.ts.map +0 -1
- package/scripts/fixEndorsementsAfterCopyPostToGroup.d.ts.map +0 -1
- package/scripts/fixExternalUserId.d.ts.map +0 -1
- package/scripts/fixGroupAccess.d.ts.map +0 -1
- package/scripts/fixGroupIdeasAndPointsCount.d.ts.map +0 -1
- package/scripts/fixNotificationSettings.d.ts.map +0 -1
- package/scripts/fixSurveyRadioBakedInSubCodes.d.ts.map +0 -1
- package/scripts/fixWrongUserIdForStatusUpdates.d.ts.map +0 -1
- package/scripts/gallery/exportGalleryData.d.ts.map +0 -1
- package/scripts/gallery/importGalleryForCommunity.d.ts.map +0 -1
- package/scripts/gallery/readJsonAndDownloadImagesVersion2.d.ts.map +0 -1
- package/scripts/gallery/refreshAcApiPostIdsForCommunity.d.ts.map +0 -1
- package/scripts/genderAnalysis.d.ts.map +0 -1
- package/scripts/genderAnalysisByStatus.d.ts.map +0 -1
- package/scripts/importAllLocalesFromLocalFolders.d.ts.map +0 -1
- package/scripts/importDomain.d.ts.map +0 -1
- package/scripts/landUseGame/export3Ddata.d.ts.map +0 -1
- package/scripts/listLanguagesForGroup.d.ts.map +0 -1
- package/scripts/loadTestCreateDummyContentForGroup.d.ts.map +0 -1
- package/scripts/makeRecursiveMapData.d.ts.map +0 -1
- package/scripts/mapping/community_map_csv.d.ts.map +0 -1
- package/scripts/moveCommunityToDomain.d.ts.map +0 -1
- package/scripts/moveGroupToCommunity.d.ts.map +0 -1
- package/scripts/movePostToGroup.d.ts.map +0 -1
- package/scripts/movePostsToGroupsRecountGroupFromUrl.d.ts.map +0 -1
- package/scripts/oldMovePostToGroup.d.ts.map +0 -1
- package/scripts/processCsvForPdfUrls.d.ts.map +0 -1
- package/scripts/processCsvForTranslationAndToxicity.d.ts.map +0 -1
- package/scripts/recount/recount_recursive_communities.d.ts.map +0 -1
- package/scripts/recountALLCommunityGroupCounts.d.ts.map +0 -1
- package/scripts/recountAll.d.ts.map +0 -1
- package/scripts/recountCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/recountCommunity.d.ts.map +0 -1
- package/scripts/recountGroup.d.ts.map +0 -1
- package/scripts/recountGroupNoUserChange.d.ts.map +0 -1
- package/scripts/resetAllEndorsementsForGroup.d.ts.map +0 -1
- package/scripts/resetEnTranslationForGroup.d.ts.map +0 -1
- package/scripts/setDomainLocales.d.ts.map +0 -1
- package/scripts/setLanguageOnGroupCommunitesFromUrl.d.ts.map +0 -1
- package/scripts/setMemberOfAll.d.ts.map +0 -1
- package/scripts/setNewUserForContentOfCommunity.d.ts.map +0 -1
- package/scripts/setOfficialStatusOnAllPostsForCommunity.d.ts.map +0 -1
- package/scripts/setUserOnAll.d.ts.map +0 -1
- package/scripts/showCategoryForGroup.d.ts.map +0 -1
- package/scripts/showOldActivityTypes.d.ts.map +0 -1
- package/scripts/showPostsMissingCategoryForGroup.d.ts.map +0 -1
- package/scripts/showStatuses.d.ts.map +0 -1
- package/scripts/showUniqueVotersInCommunity.d.ts.map +0 -1
- package/scripts/showUserAgentsAndIpsForEmails.d.ts.map +0 -1
- package/scripts/simpleExportForGroupsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPointsForCommunity.d.ts.map +0 -1
- package/scripts/simpleExportForPostsForCommunity.d.ts.map +0 -1
- package/scripts/testForEndorsments.d.ts.map +0 -1
- package/scripts/undeleteGroupAndAllContent.d.ts.map +0 -1
- package/scripts/undeletePost.d.ts.map +0 -1
- package/scripts/unlinkSsn.d.ts.map +0 -1
- package/scripts/updateFromAlthingi.d.ts.map +0 -1
- package/server.d.ts.map +0 -1
- package/utils/copyGroup.js +0 -246
- package/utils/loggerTs.d.ts +0 -4
- package/utils/loggerTs.d.ts.map +0 -1
- package/utils/ypLanguages.d.ts +0 -18
- package/utils/ypLanguages.d.ts.map +0 -1
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import ExcelJS from "exceljs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import fetch from "node-fetch";
|
|
4
|
-
import { Headers } from "node-fetch";
|
|
5
|
-
const PAIRWISE_API_HOST = process.env.PAIRWISE_API_HOST; // Your API host
|
|
6
|
-
const defaultAuthHeader = new Headers({
|
|
7
|
-
"Content-Type": "application/json",
|
|
8
|
-
Authorization: `Basic ${Buffer.from(`${process.env.PAIRWISE_USERNAME}:${process.env.PAIRWISE_PASSWORD}`).toString("base64")}`,
|
|
9
|
-
});
|
|
10
|
-
async function fetchChoices(questionId, utmSource) {
|
|
11
|
-
try {
|
|
12
|
-
const response = await fetch(`${PAIRWISE_API_HOST}/questions/${questionId}/choices?utm_source=${utmSource || ""}`, {
|
|
13
|
-
method: "GET",
|
|
14
|
-
headers: defaultAuthHeader,
|
|
15
|
-
});
|
|
16
|
-
if (!response.ok) {
|
|
17
|
-
console.error(response.statusText);
|
|
18
|
-
throw new Error("Fetching choices failed.");
|
|
19
|
-
}
|
|
20
|
-
const choices = (await response.json());
|
|
21
|
-
return choices;
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
console.error("Error fetching choices:", error);
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
async function fetchVotes(choiceId, utmSource) {
|
|
29
|
-
try {
|
|
30
|
-
let url = `${PAIRWISE_API_HOST}/choices/${choiceId}/votes?valid_record=true`;
|
|
31
|
-
if (utmSource) {
|
|
32
|
-
url += `&utm_source=${utmSource}`;
|
|
33
|
-
}
|
|
34
|
-
const response = await fetch(url, {
|
|
35
|
-
method: "GET",
|
|
36
|
-
headers: defaultAuthHeader,
|
|
37
|
-
});
|
|
38
|
-
if (!response.ok) {
|
|
39
|
-
console.error(response.statusText);
|
|
40
|
-
throw new Error("Fetching votes failed.");
|
|
41
|
-
}
|
|
42
|
-
const votes = (await response.json());
|
|
43
|
-
return votes;
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
console.error("Error fetching votes:", error);
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
export async function exportChoiceVotes(questionId, utmSource, outputFolder = "tmp") {
|
|
51
|
-
console.log(`Exporting choice votes for question ${questionId} with utm_source ${utmSource}`);
|
|
52
|
-
const choices = (await fetchChoices(questionId, utmSource));
|
|
53
|
-
console.log(`Found ${choices.length} choices`);
|
|
54
|
-
const workbook = new ExcelJS.Workbook();
|
|
55
|
-
const choicesSheet = workbook.addWorksheet("Choices");
|
|
56
|
-
const winningVotesSheet = workbook.addWorksheet("Winning Votes");
|
|
57
|
-
const losingVotesSheet = workbook.addWorksheet("Losing Votes");
|
|
58
|
-
// Setting the headers
|
|
59
|
-
const choicesHeaders = [
|
|
60
|
-
"Id",
|
|
61
|
-
"Question Id",
|
|
62
|
-
"Wins",
|
|
63
|
-
"Losses",
|
|
64
|
-
"Votes",
|
|
65
|
-
"Score",
|
|
66
|
-
"Data",
|
|
67
|
-
"Elo Rating",
|
|
68
|
-
"Seed",
|
|
69
|
-
];
|
|
70
|
-
choicesSheet.addRow(choicesHeaders);
|
|
71
|
-
const votesHeaders = [
|
|
72
|
-
"Id",
|
|
73
|
-
"Voter Id",
|
|
74
|
-
"Question Id",
|
|
75
|
-
"Prompt Id",
|
|
76
|
-
"Choice Id",
|
|
77
|
-
"Loser Choice Id",
|
|
78
|
-
"Created At",
|
|
79
|
-
"Updated At",
|
|
80
|
-
"Time Viewed",
|
|
81
|
-
"UTM Source",
|
|
82
|
-
"UTM Campaign",
|
|
83
|
-
"UTM Medium",
|
|
84
|
-
"UTM Content",
|
|
85
|
-
];
|
|
86
|
-
winningVotesSheet.addRow(votesHeaders);
|
|
87
|
-
losingVotesSheet.addRow(votesHeaders);
|
|
88
|
-
for (let choice of choices) {
|
|
89
|
-
const votes = (await fetchVotes(choice.id, utmSource));
|
|
90
|
-
const voteCount = choice.wins + choice.losses;
|
|
91
|
-
choicesSheet.addRow([
|
|
92
|
-
choice.id,
|
|
93
|
-
choice.question_id,
|
|
94
|
-
choice.wins,
|
|
95
|
-
choice.losses,
|
|
96
|
-
voteCount,
|
|
97
|
-
choice.score,
|
|
98
|
-
choice.data,
|
|
99
|
-
"N/A",
|
|
100
|
-
"N/A",
|
|
101
|
-
]);
|
|
102
|
-
votes.winning_votes.forEach((vote) => {
|
|
103
|
-
winningVotesSheet.addRow([
|
|
104
|
-
vote.id,
|
|
105
|
-
vote.voter_id,
|
|
106
|
-
vote.question_id,
|
|
107
|
-
vote.prompt_id,
|
|
108
|
-
vote.choice_id,
|
|
109
|
-
vote.loser_choice_id,
|
|
110
|
-
vote.created_at,
|
|
111
|
-
vote.updated_at,
|
|
112
|
-
vote.time_viewed,
|
|
113
|
-
vote.tracking.utmSource,
|
|
114
|
-
vote.tracking.utmCampaign,
|
|
115
|
-
vote.tracking.utmMedium,
|
|
116
|
-
vote.tracking.utmContent,
|
|
117
|
-
]);
|
|
118
|
-
});
|
|
119
|
-
votes.losing_votes.forEach((vote) => {
|
|
120
|
-
losingVotesSheet.addRow([
|
|
121
|
-
vote.id,
|
|
122
|
-
vote.voter_id,
|
|
123
|
-
vote.question_id,
|
|
124
|
-
vote.prompt_id,
|
|
125
|
-
vote.choice_id,
|
|
126
|
-
vote.loser_choice_id,
|
|
127
|
-
vote.created_at,
|
|
128
|
-
vote.updated_at,
|
|
129
|
-
vote.time_viewed,
|
|
130
|
-
vote.tracking.utmSource,
|
|
131
|
-
vote.tracking.utmCampaign,
|
|
132
|
-
vote.tracking.utmMedium,
|
|
133
|
-
vote.tracking.utmContent,
|
|
134
|
-
]);
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
// Saving the Excel file
|
|
138
|
-
const filePath = path.join(outputFolder, "choice_votes.xlsx");
|
|
139
|
-
await workbook.xlsx.writeFile(filePath);
|
|
140
|
-
console.log(`Generated choice votes file at: ${filePath}`);
|
|
141
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/// <reference types="./server.d.ts" />
|
|
2
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
import { OpenAI } from "openai";
|
|
4
|
-
import { Stream } from "openai/streaming.js";
|
|
5
|
-
import WebSocket from "ws";
|
|
6
|
-
export declare class YpBaseChatBot {
|
|
7
|
-
wsClientId: string;
|
|
8
|
-
wsClientSocket: WebSocket;
|
|
9
|
-
openaiClient: OpenAI;
|
|
10
|
-
memory: PsChatBotMemoryData;
|
|
11
|
-
broadcastingLiveCosts: boolean;
|
|
12
|
-
liveCostsBroadcastInterval: number;
|
|
13
|
-
liveCostsInactivityTimeout: number;
|
|
14
|
-
static redisMemoryKeyPrefix: string;
|
|
15
|
-
tempeture: number;
|
|
16
|
-
maxTokens: number;
|
|
17
|
-
llmModel: string;
|
|
18
|
-
persistMemory: boolean;
|
|
19
|
-
memoryId: string | undefined;
|
|
20
|
-
liveCostsBroadcastTimeout: NodeJS.Timeout | undefined;
|
|
21
|
-
liveCostsBoadcastStartAt: Date | undefined;
|
|
22
|
-
lastSentToUserAt: Date | undefined;
|
|
23
|
-
lastBroacastedCosts: number | undefined;
|
|
24
|
-
get redisKey(): string;
|
|
25
|
-
static loadMemoryFromRedis(memoryId: string): Promise<PsChatBotMemoryData | undefined>;
|
|
26
|
-
static getFullCostOfMemory(memory: PsChatBotMemoryData): number | undefined;
|
|
27
|
-
loadMemory(): Promise<PsChatBotMemoryData>;
|
|
28
|
-
constructor(wsClientId: string, wsClients: Map<string, WebSocket>, memoryId?: string | undefined);
|
|
29
|
-
setupMemory(memoryId?: string | undefined): Promise<void>;
|
|
30
|
-
get fullLLMCostsForMemory(): number | undefined;
|
|
31
|
-
getLoadedMemory(): Promise<PsChatBotMemoryData>;
|
|
32
|
-
sendMemoryId(): void;
|
|
33
|
-
saveMemory(): Promise<void>;
|
|
34
|
-
renderSystemPrompt(): string;
|
|
35
|
-
sendAgentStart(name: string, hasNoStreaming?: boolean): void;
|
|
36
|
-
sendAgentCompleted(name: string, lastAgent?: boolean, error?: string | undefined): void;
|
|
37
|
-
sendAgentUpdate(message: string): void;
|
|
38
|
-
startBroadcastingLiveCosts(): void;
|
|
39
|
-
broadCastLiveCosts(): void;
|
|
40
|
-
stopBroadcastingLiveCosts(): void;
|
|
41
|
-
get emptyChatBotStagesData(): Record<YpChatBotMemoryStageTypes, IEngineInnovationStagesData>;
|
|
42
|
-
getEmptyMemory(): PsChatBotMemoryData;
|
|
43
|
-
sendToClient(sender: string, message: string, type?: string): void;
|
|
44
|
-
streamWebSocketResponses(stream: Stream<OpenAI.Chat.Completions.ChatCompletionChunk>): Promise<void>;
|
|
45
|
-
getTokenCosts(estimateTokens: number, type: "in" | "out"): number;
|
|
46
|
-
addToExternalSolutionsMemoryCosts(text: string, type: "in" | "out"): void;
|
|
47
|
-
saveMemoryIfNeeded(): Promise<void>;
|
|
48
|
-
setChatLog(chatLog: PsSimpleChatLog[]): Promise<void>;
|
|
49
|
-
conversation: (chatLog: PsSimpleChatLog[]) => Promise<void>;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=baseChatBot.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"baseChatBot.d.ts","sourceRoot":"","sources":["../../../active-citizen/llms/baseChatBot.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,SAAS,MAAM,IAAI,CAAC;AAgB3B,qBAAa,aAAa;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,SAAS,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAG,mBAAmB,CAAC;IAC7B,qBAAqB,UAAS;IAC9B,0BAA0B,SAAQ;IAClC,0BAA0B,SAAkB;IAC5C,MAAM,CAAC,oBAAoB,SAAuB;IAClD,SAAS,SAAO;IAChB,SAAS,SAAQ;IACjB,QAAQ,SAAwB;IAChC,aAAa,UAAS;IACtB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAa;IAEzC,yBAAyB,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAa;IAClE,wBAAwB,EAAE,IAAI,GAAG,SAAS,CAAC;IAC3C,gBAAgB,EAAE,IAAI,GAAG,SAAS,CAAC;IACnC,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC,IAAI,QAAQ,WAEX;IAED,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM;IAqB3C,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,mBAAmB;IAatD,UAAU;gBAkBR,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,EACjC,QAAQ,GAAE,MAAM,GAAG,SAAqB;IAepC,WAAW,CAAC,QAAQ,GAAE,MAAM,GAAG,SAAqB;IAe1D,IAAI,qBAAqB,uBAMxB;IAEK,eAAe;IAIrB,YAAY;IAUN,UAAU;IAahB,kBAAkB;IAIlB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,cAAc,UAAO;IAYlD,kBAAkB,CAChB,IAAI,EAAE,MAAM,EACZ,SAAS,UAAQ,EACjB,KAAK,GAAE,MAAM,GAAG,SAAqB;IAkBvC,eAAe,CAAC,OAAO,EAAE,MAAM;IAU/B,0BAA0B;IAS1B,kBAAkB;IAiClB,yBAAyB;IAQzB,IAAI,sBAAsB,mEASzB;IAED,cAAc;IAoCd,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,SAAW;IAevD,wBAAwB,CAE5B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,mBAAmB,CAAC;IAqC7D,aAAa,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,KAAK;IAexD,iCAAiC,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,GAAG,KAAK;IAwC5D,kBAAkB;IAMlB,UAAU,CAAC,OAAO,EAAE,eAAe,EAAE;IAM3C,YAAY,YAAmB,eAAe,EAAE,mBA0B9C;CACH"}
|
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
import { AzureOpenAI, OpenAI } from "openai";
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
import AWS from "aws-sdk";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import path from "path";
|
|
6
|
-
import { v4 as uuidv4 } from "uuid";
|
|
7
|
-
import models from "../../models/index.cjs";
|
|
8
|
-
import sharp from "sharp";
|
|
9
|
-
import Replicate from "replicate";
|
|
10
|
-
const dbModels = models;
|
|
11
|
-
const Image = dbModels.Image;
|
|
12
|
-
const AcBackgroundJob = dbModels.AcBackgroundJob;
|
|
13
|
-
const maxRetryCount = 3;
|
|
14
|
-
const disableFlux = false;
|
|
15
|
-
export class CollectionImageGenerator {
|
|
16
|
-
async resizeImage(imagePath, width, height) {
|
|
17
|
-
const resizedImageFilePath = path.join("/tmp", `${uuidv4()}.png`);
|
|
18
|
-
try {
|
|
19
|
-
// 1) Initialize Sharp instance
|
|
20
|
-
const image = sharp(imagePath).rotate(); // rotate fixes orientation from EXIF
|
|
21
|
-
// 2) Read metadata to validate format
|
|
22
|
-
const metadata = await image.metadata();
|
|
23
|
-
const validFormats = [
|
|
24
|
-
"jpeg",
|
|
25
|
-
"png",
|
|
26
|
-
"webp",
|
|
27
|
-
"gif",
|
|
28
|
-
"tiff",
|
|
29
|
-
"avif",
|
|
30
|
-
"svg"
|
|
31
|
-
];
|
|
32
|
-
if (!metadata.format || !validFormats.includes(metadata.format)) {
|
|
33
|
-
throw new Error(`Unsupported format: ${metadata.format} (expected one of ${validFormats.join(", ")})`);
|
|
34
|
-
}
|
|
35
|
-
// 3) Resize + convert
|
|
36
|
-
await image
|
|
37
|
-
.resize({
|
|
38
|
-
width,
|
|
39
|
-
height,
|
|
40
|
-
fit: "inside",
|
|
41
|
-
withoutEnlargement: true,
|
|
42
|
-
})
|
|
43
|
-
.toFormat("png", {
|
|
44
|
-
quality: 90,
|
|
45
|
-
progressive: true,
|
|
46
|
-
})
|
|
47
|
-
.toFile(resizedImageFilePath);
|
|
48
|
-
// 4) Remove the original file after successful resize
|
|
49
|
-
fs.unlinkSync(imagePath);
|
|
50
|
-
return resizedImageFilePath;
|
|
51
|
-
}
|
|
52
|
-
catch (err) {
|
|
53
|
-
console.error("Error resizing image:", err);
|
|
54
|
-
if (fs.existsSync(resizedImageFilePath)) {
|
|
55
|
-
fs.unlinkSync(resizedImageFilePath);
|
|
56
|
-
}
|
|
57
|
-
throw err;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async downloadImage(imageUrl, imageFilePath) {
|
|
61
|
-
const response = await axios({
|
|
62
|
-
method: "GET",
|
|
63
|
-
url: imageUrl,
|
|
64
|
-
responseType: "stream",
|
|
65
|
-
});
|
|
66
|
-
const writer = fs.createWriteStream(imageFilePath);
|
|
67
|
-
response.data.pipe(writer);
|
|
68
|
-
return new Promise((resolve, reject) => {
|
|
69
|
-
writer.on("finish", () => resolve());
|
|
70
|
-
writer.on("error", reject);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
async deleteS3Url(imageUrl) {
|
|
74
|
-
const { bucket, key } = this.parseImageUrl(imageUrl);
|
|
75
|
-
if (!bucket || !key) {
|
|
76
|
-
throw new Error("Could not parse bucket or key from URL");
|
|
77
|
-
}
|
|
78
|
-
const s3 = new AWS.S3();
|
|
79
|
-
const params = {
|
|
80
|
-
Bucket: bucket,
|
|
81
|
-
Key: key,
|
|
82
|
-
ACL: "private",
|
|
83
|
-
};
|
|
84
|
-
console.log(`Disabling/Deleting Key from S3: ${JSON.stringify(params)}`);
|
|
85
|
-
return new Promise((resolve, reject) => {
|
|
86
|
-
s3.putObjectAcl(params, (err, data) => {
|
|
87
|
-
if (err) {
|
|
88
|
-
console.error(`Error deleting image from S3: ${err}`);
|
|
89
|
-
reject(err);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
console.log(`Deleted image from S3: ${imageUrl}`, data);
|
|
93
|
-
if (process.env.CLOUDFLARE_API_KEY &&
|
|
94
|
-
process.env.CLOUDFLARE_ZONE_ID) {
|
|
95
|
-
console.log("Purging Cloudflare cache for image:", imageUrl);
|
|
96
|
-
axios
|
|
97
|
-
.post(`https://api.cloudflare.com/client/v4/zones/${process.env.CLOUDFLARE_ZONE_ID}/purge_cache`, { files: [imageUrl] }, {
|
|
98
|
-
headers: {
|
|
99
|
-
Authorization: `Bearer ${process.env.CLOUDFLARE_API_KEY}`,
|
|
100
|
-
"Content-Type": "application/json",
|
|
101
|
-
},
|
|
102
|
-
})
|
|
103
|
-
.then((response) => {
|
|
104
|
-
console.log("Cloudflare cache purged:", response.data);
|
|
105
|
-
resolve(data);
|
|
106
|
-
})
|
|
107
|
-
.catch((error) => {
|
|
108
|
-
if (error.response) {
|
|
109
|
-
console.error("Error purging Cloudflare cache:", error.response.data);
|
|
110
|
-
console.error("Status code:", error.response.status);
|
|
111
|
-
console.error("Headers:", error.response.headers);
|
|
112
|
-
}
|
|
113
|
-
else if (error.request) {
|
|
114
|
-
console.error("No response received:", error.request);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
console.error("Error setting up request:", error.message);
|
|
118
|
-
}
|
|
119
|
-
resolve(data);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
resolve(data);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
parseImageUrl(imageUrl) {
|
|
130
|
-
let bucket, key;
|
|
131
|
-
if (process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN &&
|
|
132
|
-
imageUrl.includes(process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN)) {
|
|
133
|
-
const urlPath = new URL(imageUrl).pathname;
|
|
134
|
-
const [, ...pathParts] = urlPath.split("/");
|
|
135
|
-
bucket = process.env.S3_BUCKET;
|
|
136
|
-
key = pathParts.join("/");
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
const match = imageUrl.match(/https:\/\/(.+?)\.s3\.amazonaws\.com\/(.+)/);
|
|
140
|
-
if (match) {
|
|
141
|
-
bucket = match[1];
|
|
142
|
-
key = match[2];
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return { bucket, key };
|
|
146
|
-
}
|
|
147
|
-
async deleteMediaFormatsUrls(formats) {
|
|
148
|
-
formats.forEach(async (url) => {
|
|
149
|
-
await this.deleteS3Url(url);
|
|
150
|
-
console.log(`Have deleted image from S3: ${url}`);
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
async uploadImageToS3(bucket, filePath, key) {
|
|
154
|
-
const s3 = new AWS.S3();
|
|
155
|
-
const fileContent = fs.readFileSync(filePath);
|
|
156
|
-
const params = {
|
|
157
|
-
Bucket: bucket,
|
|
158
|
-
Key: key,
|
|
159
|
-
Body: fileContent,
|
|
160
|
-
ACL: "public-read",
|
|
161
|
-
ContentType: "image/png",
|
|
162
|
-
ContentDisposition: "inline",
|
|
163
|
-
};
|
|
164
|
-
return new Promise((resolve, reject) => {
|
|
165
|
-
s3.upload(params, (err, data) => {
|
|
166
|
-
if (err) {
|
|
167
|
-
reject(err);
|
|
168
|
-
}
|
|
169
|
-
fs.unlinkSync(filePath);
|
|
170
|
-
resolve(data);
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
async getImageUrlFromFlux(prompt, type = "logo") {
|
|
175
|
-
const replicate = new Replicate({
|
|
176
|
-
auth: process.env.REPLICATE_API_TOKEN,
|
|
177
|
-
});
|
|
178
|
-
let retryCount = 0;
|
|
179
|
-
let retrying = true;
|
|
180
|
-
let result;
|
|
181
|
-
let input = {
|
|
182
|
-
prompt: prompt,
|
|
183
|
-
};
|
|
184
|
-
if (type === "logo") {
|
|
185
|
-
input.aspect_ratio = "16:9";
|
|
186
|
-
}
|
|
187
|
-
else if (type === "icon") {
|
|
188
|
-
input.aspect_ratio = "1:1";
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
input.aspect_ratio = "16:9";
|
|
192
|
-
}
|
|
193
|
-
while (retrying && retryCount < maxRetryCount) {
|
|
194
|
-
try {
|
|
195
|
-
result = await replicate.run(process.env.FLUX_PRO_MODEL_NAME, { input });
|
|
196
|
-
if (result) {
|
|
197
|
-
retrying = false;
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
console.debug(`Result: NONE`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
catch (error) {
|
|
205
|
-
console.warn("Error generating image with Flux, retrying...");
|
|
206
|
-
console.warn(error.stack);
|
|
207
|
-
retryCount++;
|
|
208
|
-
console.warn(error);
|
|
209
|
-
const sleepingFor = 5000 + retryCount * 10000;
|
|
210
|
-
console.debug(`Sleeping for ${sleepingFor} milliseconds`);
|
|
211
|
-
await new Promise((resolve) => setTimeout(resolve, sleepingFor));
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
if (!result) {
|
|
215
|
-
console.error(`Error generating image after ${retryCount} retries`);
|
|
216
|
-
return undefined;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
async getImageUrlFromDalle(prompt, type = "logo") {
|
|
220
|
-
const azureOpenaAiBase = process.env["AZURE_OPENAI_API_BASE"];
|
|
221
|
-
const azureOpenAiApiKey = process.env["AZURE_OPENAI_API_KEY"];
|
|
222
|
-
let client;
|
|
223
|
-
if (azureOpenAiApiKey && azureOpenaAiBase) {
|
|
224
|
-
client = new AzureOpenAI({
|
|
225
|
-
apiKey: azureOpenAiApiKey,
|
|
226
|
-
endpoint: azureOpenaAiBase,
|
|
227
|
-
deployment: process.env.AZURE_OPENAI_API_DALLE_DEPLOYMENT_NAME,
|
|
228
|
-
apiVersion: "2024-10-21",
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
client = new OpenAI({
|
|
233
|
-
apiKey: process.env["OPENAI_API_KEY"],
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
let retryCount = 0;
|
|
237
|
-
let retrying = true;
|
|
238
|
-
let result;
|
|
239
|
-
let imageOptions;
|
|
240
|
-
if (type === "logo") {
|
|
241
|
-
imageOptions = {
|
|
242
|
-
n: 1,
|
|
243
|
-
size: "1792x1024",
|
|
244
|
-
quality: "hd",
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
else if (type === "icon") {
|
|
248
|
-
imageOptions = {
|
|
249
|
-
n: 1,
|
|
250
|
-
size: "1024x1024",
|
|
251
|
-
quality: "hd",
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
else {
|
|
255
|
-
imageOptions = {
|
|
256
|
-
n: 1,
|
|
257
|
-
size: "1792x1024",
|
|
258
|
-
quality: "hd",
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
while (retrying && retryCount < maxRetryCount) {
|
|
262
|
-
try {
|
|
263
|
-
if (azureOpenAiApiKey && azureOpenaAiBase) {
|
|
264
|
-
result = await client.images.generate({
|
|
265
|
-
prompt,
|
|
266
|
-
n: imageOptions.n,
|
|
267
|
-
size: imageOptions.size,
|
|
268
|
-
quality: imageOptions.quality,
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
result = await client.images.generate({
|
|
273
|
-
model: "dall-e-3",
|
|
274
|
-
prompt,
|
|
275
|
-
n: imageOptions.n,
|
|
276
|
-
size: imageOptions.size,
|
|
277
|
-
quality: imageOptions.quality,
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
if (result) {
|
|
281
|
-
retrying = false;
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
console.debug(`Result: NONE`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
catch (error) {
|
|
288
|
-
console.warn("Error generating image, retrying...");
|
|
289
|
-
console.warn(error.stack);
|
|
290
|
-
retryCount++;
|
|
291
|
-
console.warn(error);
|
|
292
|
-
const sleepingFor = 5000 + retryCount * 10000;
|
|
293
|
-
console.debug(`Sleeping for ${sleepingFor} milliseconds`);
|
|
294
|
-
await new Promise((resolve) => setTimeout(resolve, sleepingFor));
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (result) {
|
|
298
|
-
console.debug(`Result: ${JSON.stringify(result)}`);
|
|
299
|
-
const imageURL = result.data[0].url;
|
|
300
|
-
if (!imageURL)
|
|
301
|
-
throw new Error("Error getting generated image");
|
|
302
|
-
return imageURL;
|
|
303
|
-
}
|
|
304
|
-
else {
|
|
305
|
-
console.error(`Error generating image after ${retryCount} retries`);
|
|
306
|
-
return undefined;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
async createCollectionImage(workPackage) {
|
|
310
|
-
return new Promise(async (resolve, reject) => {
|
|
311
|
-
let newImageUrl;
|
|
312
|
-
const imageFilePath = path.join("/tmp", `${uuidv4()}.png`);
|
|
313
|
-
const s3ImagePath = `ypGenAi/${workPackage.collectionType}/${workPackage.collectionId}/${uuidv4()}.png`;
|
|
314
|
-
try {
|
|
315
|
-
let imageUrl;
|
|
316
|
-
if (!disableFlux &&
|
|
317
|
-
process.env.REPLICATE_API_TOKEN &&
|
|
318
|
-
process.env.FLUX_PRO_MODEL_NAME) {
|
|
319
|
-
imageUrl = await this.getImageUrlFromFlux(workPackage.prompt, workPackage.imageType);
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
imageUrl = await this.getImageUrlFromDalle(workPackage.prompt, workPackage.imageType);
|
|
323
|
-
}
|
|
324
|
-
if (imageUrl) {
|
|
325
|
-
await this.downloadImage(imageUrl, imageFilePath);
|
|
326
|
-
console.debug(fs.existsSync(imageFilePath)
|
|
327
|
-
? "File downloaded successfully."
|
|
328
|
-
: "File download failed.");
|
|
329
|
-
await this.uploadImageToS3(process.env.S3_BUCKET, imageFilePath, s3ImagePath);
|
|
330
|
-
if (process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN) {
|
|
331
|
-
newImageUrl = `https://${process.env.CLOUDFLARE_IMAGE_PROXY_DOMAIN}/${s3ImagePath}`;
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
newImageUrl = `https://${process.env.S3_BUCKET}.s3.amazonaws.com/${s3ImagePath}`;
|
|
335
|
-
}
|
|
336
|
-
const formats = JSON.stringify([newImageUrl]);
|
|
337
|
-
const image = await Image.build({
|
|
338
|
-
user_id: workPackage.userId,
|
|
339
|
-
s3_bucket_name: process.env.S3_BUCKET,
|
|
340
|
-
original_filename: "n/a",
|
|
341
|
-
formats,
|
|
342
|
-
user_agent: "AI worker",
|
|
343
|
-
ip_address: "127.0.0.1",
|
|
344
|
-
});
|
|
345
|
-
await image.save();
|
|
346
|
-
resolve({ imageId: image.id, imageUrl: newImageUrl });
|
|
347
|
-
}
|
|
348
|
-
else {
|
|
349
|
-
reject("Error getting image URL from prompt.");
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
catch (error) {
|
|
353
|
-
reject(error);
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/// <reference types="../webApps/client/src/typesAoi.d.ts" />
|
|
2
|
-
import { OpenAI } from "openai";
|
|
3
|
-
export declare class YpLlmTranslation {
|
|
4
|
-
openaiClient: OpenAI;
|
|
5
|
-
modelName: string;
|
|
6
|
-
maxTokens: number;
|
|
7
|
-
temperature: number;
|
|
8
|
-
constructor();
|
|
9
|
-
renderSchemaSystemMessage(jsonInSchema: string, jsonOutSchema: string, lengthInfo: string): string;
|
|
10
|
-
renderOneTranslationSystemMessage(): string;
|
|
11
|
-
renderListTranslationSystemMessage(): string;
|
|
12
|
-
renderOneTranslationUserMessage(language: string, stringToTranslate: string): string;
|
|
13
|
-
renderListTranslationUserMessage(language: string, textsToTranslate: Array<string>): string;
|
|
14
|
-
renderAnswersUserMessage(language: string, question: string, answer: AoiTranslationAnswerInData): string;
|
|
15
|
-
renderQuestionUserMessage(language: string, question: string, questionData: AoiTranslationQuestionInData): string;
|
|
16
|
-
getModerationFlag(content: string): Promise<boolean>;
|
|
17
|
-
getOneTranslation(languageIsoCode: string, stringToTranslate: string): Promise<string | null | undefined>;
|
|
18
|
-
getListTranslation(languageIsoCode: string, stringsToTranslate: string[]): Promise<string[] | null | undefined>;
|
|
19
|
-
getChoiceTranslation(languageIsoCode: string, answerContent: string, maxCharactersInTranslation?: number): Promise<string | null | undefined>;
|
|
20
|
-
getQuestionTranslation(languageIsoCode: string, question: string, maxCharactersInTranslation?: number): Promise<string | null | undefined>;
|
|
21
|
-
callSimpleLlm(languageName: string, toTranslate: string[] | string, parseJson: boolean, systemRenderer: Function, userRenderer: Function): Promise<string | object | null | undefined>;
|
|
22
|
-
callSchemaLlm(jsonInSchema: string, jsonOutSchema: string, lengthInfo: string, languageName: string, question: string, toTranslate: AoiTranslationAnswerInData | AoiTranslationQuestionInData | string[] | string, maxCharactersInTranslation: number | undefined, systemRenderer: Function, userRenderer: Function): Promise<string | null | undefined>;
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=llmTranslation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"llmTranslation.d.ts","sourceRoot":"","sources":["../../../active-citizen/llms/llmTranslation.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,qBAAa,gBAAgB;IAC3B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,SAAwB;IACjC,SAAS,SAAQ;IACjB,WAAW,SAAO;;IAUlB,yBAAyB,CACvB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM;IAoBpB,iCAAiC;IAejC,kCAAkC;IA2BlC,+BAA+B,CAAC,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM;IAO3E,gCAAgC,CAAC,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC;IAQlF,wBAAwB,CACtB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,0BAA0B;IAapC,yBAAyB,CACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,4BAA4B;IAU1C,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IASpD,iBAAiB,CACrB,eAAe,EAAE,MAAM,EACvB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAuB/B,kBAAkB,CACtB,eAAe,EAAE,MAAM,EACvB,kBAAkB,EAAE,MAAM,EAAE,GAC3B,OAAO,CAAC,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAuBjC,oBAAoB,CACxB,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,EACrB,0BAA0B,SAAM,GAC/B,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAmC/B,sBAAsB,CAC1B,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,EAChB,0BAA0B,SAAM,GAC/B,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAmC/B,aAAa,CACjB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EAAE,GAAG,MAAM,EAC9B,SAAS,EAAE,OAAO,EAClB,cAAc,EAAE,QAAQ,EACxB,YAAY,EAAE,QAAQ,GACrB,OAAO,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IA8CxC,aAAa,CACjB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,0BAA0B,GAAG,4BAA4B,GAAG,MAAM,EAAE,GAAG,MAAM,EAC1F,0BAA0B,EAAE,MAAM,GAAG,SAAS,EAC9C,cAAc,EAAE,QAAQ,EACxB,YAAY,EAAE,QAAQ,GACrB,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CAgEtC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fix_old_delayed_notifications.d.ts","sourceRoot":"","sources":["../../../active-citizen/scripts/fix_old_delayed_notifications.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kue_status.d.ts","sourceRoot":"","sources":["../../../active-citizen/scripts/kue_status.js"],"names":[],"mappings":";AAgBA,uBAGG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kue_watch_stuck_jobs.d.ts","sourceRoot":"","sources":["../../../active-citizen/scripts/kue_watch_stuck_jobs.js"],"names":[],"mappings":";AAkBA,uBAGG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translation_clear_language.d.ts","sourceRoot":"","sources":["../../../active-citizen/scripts/translation_clear_language.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translation_delete.d.ts","sourceRoot":"","sources":["../../../active-citizen/scripts/translation_delete.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translation_replace_text_from_url.d.ts","sourceRoot":"","sources":["../../../active-citizen/scripts/translation_replace_text_from_url.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translation_update.d.ts","sourceRoot":"","sources":["../../../active-citizen/scripts/translation_update.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translations_list.d.ts","sourceRoot":"","sources":["../../../active-citizen/scripts/translations_list.js"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"airbrake.d.ts","sourceRoot":"","sources":["../../../active-citizen/utils/airbrake.js"],"names":[],"mappings":";AAEE,0BAAoB"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
if (process.env.AIRBRAKE_PROJECT_ID) {
|
|
2
|
-
const Airbrake = require('@airbrake/node');
|
|
3
|
-
let airBrake = null;
|
|
4
|
-
try {
|
|
5
|
-
airBrake = new Airbrake.Notifier({
|
|
6
|
-
projectId: process.env.AIRBRAKE_PROJECT_ID,
|
|
7
|
-
projectKey: process.env.AIRBRAKE_API_KEY,
|
|
8
|
-
performanceStats: false
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
airBrake = null;
|
|
13
|
-
console.error(error);
|
|
14
|
-
}
|
|
15
|
-
module.exports = airBrake;
|
|
16
|
-
}
|
|
17
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { OpenAI } from "openai";
|
|
2
|
-
export declare class YpLocaleTranslation {
|
|
3
|
-
openaiClient: OpenAI;
|
|
4
|
-
modelName: string;
|
|
5
|
-
maxTokens: number;
|
|
6
|
-
temperature: number;
|
|
7
|
-
constructor();
|
|
8
|
-
getValueByPath(obj: any, path: any): any;
|
|
9
|
-
loadAndCompareTranslations(): Promise<void>;
|
|
10
|
-
setValueAtPath(obj: any, path: any, value: any): void;
|
|
11
|
-
private loadJsonFile;
|
|
12
|
-
private updateWithMissingKeys;
|
|
13
|
-
excludeKeysFromTranslation: string[];
|
|
14
|
-
private extractMissingTranslations;
|
|
15
|
-
private chunkArray;
|
|
16
|
-
renderSystemPrompt(): string;
|
|
17
|
-
renderUserMessage(language: string, textsToTranslate: Array<string>): string;
|
|
18
|
-
translateUITexts(languageIsoCode: string, textsToTranslate: string[]): Promise<string[] | undefined>;
|
|
19
|
-
callLlm(languageName: string, inObject: string[]): Promise<string[] | undefined>;
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=updateAllLocalesFromEn.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateAllLocalesFromEn.d.ts","sourceRoot":"","sources":["../../../active-citizen/utils/updateAllLocalesFromEn.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAchC,qBAAa,mBAAmB;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,SAAwB;IACjC,SAAS,SAAQ;IACjB,WAAW,SAAO;;IAOlB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG;IAI5B,0BAA0B;IAsEhC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG;YAchC,YAAY;IAK1B,OAAO,CAAC,qBAAqB;IA+B7B,0BAA0B,WAUzB;IAED,OAAO,CAAC,0BAA0B;IAkClC,OAAO,CAAC,UAAU;IASlB,kBAAkB;IAyBlB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC;IAS7D,gBAAgB,CACpB,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,EAAE,GACzB,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAkB1B,OAAO,CACX,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC;CAmEjC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateLocaleFolders.d.ts","sourceRoot":"","sources":["../../../active-citizen/utils/updateLocaleFolders.ts"],"names":[],"mappings":""}
|