@intlayer/backend 5.1.4 → 5.1.6
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/dist/cjs/controllers/ai.controller.cjs +61 -43
- package/dist/cjs/controllers/ai.controller.cjs.map +1 -1
- package/dist/cjs/controllers/dictionary.controller.cjs +8 -12
- package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
- package/dist/cjs/controllers/organization.controller.cjs +17 -1
- package/dist/cjs/controllers/organization.controller.cjs.map +1 -1
- package/dist/cjs/controllers/project.controller.cjs +1 -0
- package/dist/cjs/controllers/project.controller.cjs.map +1 -1
- package/dist/cjs/controllers/sessionAuth.controller.cjs +6 -12
- package/dist/cjs/controllers/sessionAuth.controller.cjs.map +1 -1
- package/dist/cjs/controllers/stripe.controller.cjs +31 -10
- package/dist/cjs/controllers/stripe.controller.cjs.map +1 -1
- package/dist/cjs/controllers/tag.controller.cjs +0 -7
- package/dist/cjs/controllers/tag.controller.cjs.map +1 -1
- package/dist/cjs/controllers/user.controller.cjs +1 -1
- package/dist/cjs/controllers/user.controller.cjs.map +1 -1
- package/dist/cjs/emails/InviteUserEmail.cjs +3 -3
- package/dist/cjs/emails/InviteUserEmail.cjs.map +1 -1
- package/dist/cjs/emails/PasswordChangeConfirmation.cjs +3 -3
- package/dist/cjs/emails/PasswordChangeConfirmation.cjs.map +1 -1
- package/dist/cjs/emails/ResetUserPassword.cjs +3 -3
- package/dist/cjs/emails/ResetUserPassword.cjs.map +1 -1
- package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs +19 -3
- package/dist/cjs/emails/SubscriptionPaymentCancellation.cjs.map +1 -1
- package/dist/cjs/emails/SubscriptionPaymentError.cjs +19 -3
- package/dist/cjs/emails/SubscriptionPaymentError.cjs.map +1 -1
- package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs +19 -3
- package/dist/cjs/emails/SubscriptionPaymentSuccess.cjs.map +1 -1
- package/dist/cjs/emails/ValidateUserEmail.cjs +3 -3
- package/dist/cjs/emails/ValidateUserEmail.cjs.map +1 -1
- package/dist/cjs/emails/Welcome.cjs +3 -3
- package/dist/cjs/emails/Welcome.cjs.map +1 -1
- package/dist/cjs/export.cjs +10 -10
- package/dist/cjs/export.cjs.map +1 -1
- package/dist/cjs/routes/ai.routes.cjs +21 -15
- package/dist/cjs/routes/ai.routes.cjs.map +1 -1
- package/dist/cjs/routes/dictionary.routes.cjs +15 -12
- package/dist/cjs/routes/dictionary.routes.cjs.map +1 -1
- package/dist/cjs/routes/event-listener.routes.cjs +4 -4
- package/dist/cjs/routes/event-listener.routes.cjs.map +1 -1
- package/dist/cjs/routes/organization.routes.cjs +15 -15
- package/dist/cjs/routes/organization.routes.cjs.map +1 -1
- package/dist/cjs/routes/project.routes.cjs +30 -18
- package/dist/cjs/routes/project.routes.cjs.map +1 -1
- package/dist/cjs/routes/sessionAuth.routes.cjs +38 -35
- package/dist/cjs/routes/sessionAuth.routes.cjs.map +1 -1
- package/dist/cjs/routes/stripe.routes.cjs +23 -11
- package/dist/cjs/routes/stripe.routes.cjs.map +1 -1
- package/dist/cjs/routes/tags.routes.cjs +11 -11
- package/dist/cjs/routes/tags.routes.cjs.map +1 -1
- package/dist/cjs/routes/user.routes.cjs +13 -13
- package/dist/cjs/routes/user.routes.cjs.map +1 -1
- package/dist/cjs/schemas/dictionary.schema.cjs +0 -4
- package/dist/cjs/schemas/dictionary.schema.cjs.map +1 -1
- package/dist/cjs/schemas/project.schema.cjs +2 -2
- package/dist/cjs/schemas/project.schema.cjs.map +1 -1
- package/dist/cjs/services/dictionary.service.cjs.map +1 -1
- package/dist/cjs/services/email.service.cjs +1 -1
- package/dist/cjs/services/email.service.cjs.map +1 -1
- package/dist/cjs/services/subscription.service.cjs +81 -2
- package/dist/cjs/services/subscription.service.cjs.map +1 -1
- package/dist/cjs/types/dictionary.types.cjs.map +1 -1
- package/dist/cjs/utils/AI/{askDocQuestion.cjs → askDocQuestion/askDocQuestion.cjs} +1 -1
- package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs.map +1 -0
- package/dist/{esm/utils/AI → cjs/utils/AI/askDocQuestion}/embeddings.json +4288 -4288
- package/dist/cjs/utils/{auditDictionary → AI/auditDictionary}/index.cjs +5 -3
- package/dist/cjs/utils/AI/auditDictionary/index.cjs.map +1 -0
- package/dist/cjs/utils/{auditDictionaryField → AI/auditDictionaryField}/PROMPT.md +17 -7
- package/dist/cjs/utils/{auditDictionaryField → AI/auditDictionaryField}/index.cjs +5 -3
- package/dist/cjs/utils/AI/auditDictionaryField/index.cjs.map +1 -0
- package/dist/cjs/utils/{auditDictionaryMetadata → AI/auditDictionaryMetadata}/index.cjs +5 -3
- package/dist/cjs/utils/AI/auditDictionaryMetadata/index.cjs.map +1 -0
- package/dist/cjs/utils/AI/autocomplete/PROMPT.md +13 -0
- package/dist/cjs/utils/AI/autocomplete/index.cjs +73 -0
- package/dist/cjs/utils/AI/autocomplete/index.cjs.map +1 -0
- package/dist/cjs/utils/auditTag/index.cjs +4 -2
- package/dist/cjs/utils/auditTag/index.cjs.map +1 -1
- package/dist/cjs/utils/errors/errorCodes.cjs +26 -0
- package/dist/cjs/utils/errors/errorCodes.cjs.map +1 -1
- package/dist/cjs/utils/mongoDB/connectDB.cjs +10 -0
- package/dist/cjs/utils/mongoDB/connectDB.cjs.map +1 -1
- package/dist/cjs/webhooks/stripe.webhook.cjs +42 -0
- package/dist/cjs/webhooks/stripe.webhook.cjs.map +1 -1
- package/dist/esm/controllers/ai.controller.mjs +59 -42
- package/dist/esm/controllers/ai.controller.mjs.map +1 -1
- package/dist/esm/controllers/dictionary.controller.mjs +8 -12
- package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
- package/dist/esm/controllers/organization.controller.mjs +18 -2
- package/dist/esm/controllers/organization.controller.mjs.map +1 -1
- package/dist/esm/controllers/project.controller.mjs +1 -0
- package/dist/esm/controllers/project.controller.mjs.map +1 -1
- package/dist/esm/controllers/sessionAuth.controller.mjs +6 -12
- package/dist/esm/controllers/sessionAuth.controller.mjs.map +1 -1
- package/dist/esm/controllers/stripe.controller.mjs +30 -10
- package/dist/esm/controllers/stripe.controller.mjs.map +1 -1
- package/dist/esm/controllers/tag.controller.mjs +0 -7
- package/dist/esm/controllers/tag.controller.mjs.map +1 -1
- package/dist/esm/controllers/user.controller.mjs +2 -2
- package/dist/esm/controllers/user.controller.mjs.map +1 -1
- package/dist/esm/emails/InviteUserEmail.mjs +3 -3
- package/dist/esm/emails/InviteUserEmail.mjs.map +1 -1
- package/dist/esm/emails/PasswordChangeConfirmation.mjs +3 -3
- package/dist/esm/emails/PasswordChangeConfirmation.mjs.map +1 -1
- package/dist/esm/emails/ResetUserPassword.mjs +3 -3
- package/dist/esm/emails/ResetUserPassword.mjs.map +1 -1
- package/dist/esm/emails/SubscriptionPaymentCancellation.mjs +19 -3
- package/dist/esm/emails/SubscriptionPaymentCancellation.mjs.map +1 -1
- package/dist/esm/emails/SubscriptionPaymentError.mjs +19 -3
- package/dist/esm/emails/SubscriptionPaymentError.mjs.map +1 -1
- package/dist/esm/emails/SubscriptionPaymentSuccess.mjs +19 -3
- package/dist/esm/emails/SubscriptionPaymentSuccess.mjs.map +1 -1
- package/dist/esm/emails/ValidateUserEmail.mjs +3 -3
- package/dist/esm/emails/ValidateUserEmail.mjs.map +1 -1
- package/dist/esm/emails/Welcome.mjs +3 -3
- package/dist/esm/emails/Welcome.mjs.map +1 -1
- package/dist/esm/export.mjs +10 -10
- package/dist/esm/export.mjs.map +1 -1
- package/dist/esm/routes/ai.routes.mjs +22 -15
- package/dist/esm/routes/ai.routes.mjs.map +1 -1
- package/dist/esm/routes/dictionary.routes.mjs +14 -11
- package/dist/esm/routes/dictionary.routes.mjs.map +1 -1
- package/dist/esm/routes/event-listener.routes.mjs +4 -4
- package/dist/esm/routes/event-listener.routes.mjs.map +1 -1
- package/dist/esm/routes/organization.routes.mjs +13 -13
- package/dist/esm/routes/organization.routes.mjs.map +1 -1
- package/dist/esm/routes/project.routes.mjs +28 -16
- package/dist/esm/routes/project.routes.mjs.map +1 -1
- package/dist/esm/routes/sessionAuth.routes.mjs +37 -34
- package/dist/esm/routes/sessionAuth.routes.mjs.map +1 -1
- package/dist/esm/routes/stripe.routes.mjs +22 -9
- package/dist/esm/routes/stripe.routes.mjs.map +1 -1
- package/dist/esm/routes/tags.routes.mjs +9 -9
- package/dist/esm/routes/tags.routes.mjs.map +1 -1
- package/dist/esm/routes/user.routes.mjs +11 -11
- package/dist/esm/routes/user.routes.mjs.map +1 -1
- package/dist/esm/schemas/dictionary.schema.mjs +0 -4
- package/dist/esm/schemas/dictionary.schema.mjs.map +1 -1
- package/dist/esm/schemas/project.schema.mjs +2 -2
- package/dist/esm/schemas/project.schema.mjs.map +1 -1
- package/dist/esm/services/dictionary.service.mjs.map +1 -1
- package/dist/esm/services/email.service.mjs +1 -1
- package/dist/esm/services/email.service.mjs.map +1 -1
- package/dist/esm/services/subscription.service.mjs +78 -1
- package/dist/esm/services/subscription.service.mjs.map +1 -1
- package/dist/esm/utils/AI/{askDocQuestion.mjs → askDocQuestion/askDocQuestion.mjs} +1 -1
- package/dist/esm/utils/AI/askDocQuestion/askDocQuestion.mjs.map +1 -0
- package/dist/{cjs/utils/AI → esm/utils/AI/askDocQuestion}/embeddings.json +4288 -4288
- package/dist/esm/utils/{auditDictionary → AI/auditDictionary}/index.mjs +5 -3
- package/dist/esm/utils/AI/auditDictionary/index.mjs.map +1 -0
- package/dist/esm/utils/{auditDictionaryField → AI/auditDictionaryField}/PROMPT.md +17 -7
- package/dist/esm/utils/{auditDictionaryField → AI/auditDictionaryField}/index.mjs +5 -3
- package/dist/esm/utils/AI/auditDictionaryField/index.mjs.map +1 -0
- package/dist/esm/utils/{auditDictionaryMetadata → AI/auditDictionaryMetadata}/index.mjs +5 -3
- package/dist/esm/utils/AI/auditDictionaryMetadata/index.mjs.map +1 -0
- package/dist/esm/utils/AI/autocomplete/PROMPT.md +13 -0
- package/dist/esm/utils/AI/autocomplete/index.mjs +48 -0
- package/dist/esm/utils/AI/autocomplete/index.mjs.map +1 -0
- package/dist/esm/utils/auditTag/index.mjs +4 -2
- package/dist/esm/utils/auditTag/index.mjs.map +1 -1
- package/dist/esm/utils/errors/errorCodes.mjs +26 -0
- package/dist/esm/utils/errors/errorCodes.mjs.map +1 -1
- package/dist/esm/utils/mongoDB/connectDB.mjs +10 -0
- package/dist/esm/utils/mongoDB/connectDB.mjs.map +1 -1
- package/dist/esm/webhooks/stripe.webhook.mjs +32 -0
- package/dist/esm/webhooks/stripe.webhook.mjs.map +1 -1
- package/dist/types/controllers/ai.controller.d.ts +17 -2
- package/dist/types/controllers/ai.controller.d.ts.map +1 -1
- package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
- package/dist/types/controllers/organization.controller.d.ts.map +1 -1
- package/dist/types/controllers/project.controller.d.ts.map +1 -1
- package/dist/types/controllers/sessionAuth.controller.d.ts +4 -3
- package/dist/types/controllers/sessionAuth.controller.d.ts.map +1 -1
- package/dist/types/controllers/stripe.controller.d.ts +15 -7
- package/dist/types/controllers/stripe.controller.d.ts.map +1 -1
- package/dist/types/controllers/tag.controller.d.ts.map +1 -1
- package/dist/types/emails/SubscriptionPaymentCancellation.d.ts +4 -3
- package/dist/types/emails/SubscriptionPaymentCancellation.d.ts.map +1 -1
- package/dist/types/emails/SubscriptionPaymentError.d.ts +4 -3
- package/dist/types/emails/SubscriptionPaymentError.d.ts.map +1 -1
- package/dist/types/emails/SubscriptionPaymentSuccess.d.ts +4 -3
- package/dist/types/emails/SubscriptionPaymentSuccess.d.ts.map +1 -1
- package/dist/types/export.d.ts +5 -5
- package/dist/types/export.d.ts.map +1 -1
- package/dist/types/routes/ai.routes.d.ts +6 -1
- package/dist/types/routes/ai.routes.d.ts.map +1 -1
- package/dist/types/routes/dictionary.routes.d.ts +4 -4
- package/dist/types/routes/dictionary.routes.d.ts.map +1 -1
- package/dist/types/routes/event-listener.routes.d.ts +1 -1
- package/dist/types/routes/event-listener.routes.d.ts.map +1 -1
- package/dist/types/routes/organization.routes.d.ts +5 -5
- package/dist/types/routes/organization.routes.d.ts.map +1 -1
- package/dist/types/routes/project.routes.d.ts +5 -5
- package/dist/types/routes/project.routes.d.ts.map +1 -1
- package/dist/types/routes/sessionAuth.routes.d.ts +4 -7
- package/dist/types/routes/sessionAuth.routes.d.ts.map +1 -1
- package/dist/types/routes/stripe.routes.d.ts +6 -1
- package/dist/types/routes/stripe.routes.d.ts.map +1 -1
- package/dist/types/routes/tags.routes.d.ts +3 -3
- package/dist/types/routes/tags.routes.d.ts.map +1 -1
- package/dist/types/routes/user.routes.d.ts +4 -4
- package/dist/types/routes/user.routes.d.ts.map +1 -1
- package/dist/types/schemas/dictionary.schema.d.ts.map +1 -1
- package/dist/types/services/dictionary.service.d.ts.map +1 -1
- package/dist/types/services/subscription.service.d.ts +9 -0
- package/dist/types/services/subscription.service.d.ts.map +1 -1
- package/dist/types/types/dictionary.types.d.ts +0 -1
- package/dist/types/types/dictionary.types.d.ts.map +1 -1
- package/dist/types/utils/AI/askDocQuestion/askDocQuestion.d.ts.map +1 -0
- package/dist/types/utils/{auditDictionary → AI/auditDictionary}/index.d.ts +8 -5
- package/dist/types/utils/AI/auditDictionary/index.d.ts.map +1 -0
- package/dist/types/utils/{auditDictionaryField → AI/auditDictionaryField}/index.d.ts +8 -5
- package/dist/types/utils/AI/auditDictionaryField/index.d.ts.map +1 -0
- package/dist/types/utils/{auditDictionaryMetadata → AI/auditDictionaryMetadata}/index.d.ts +8 -5
- package/dist/types/utils/AI/auditDictionaryMetadata/index.d.ts.map +1 -0
- package/dist/types/utils/AI/autocomplete/index.d.ts +22 -0
- package/dist/types/utils/AI/autocomplete/index.d.ts.map +1 -0
- package/dist/types/utils/auditTag/index.d.ts +7 -4
- package/dist/types/utils/auditTag/index.d.ts.map +1 -1
- package/dist/types/utils/errors/errorCodes.d.ts +26 -0
- package/dist/types/utils/errors/errorCodes.d.ts.map +1 -1
- package/dist/types/utils/mongoDB/connectDB.d.ts.map +1 -1
- package/dist/types/webhooks/stripe.webhook.d.ts.map +1 -1
- package/package.json +11 -10
- package/dist/cjs/utils/AI/askDocQuestion.cjs.map +0 -1
- package/dist/cjs/utils/auditDictionary/index.cjs.map +0 -1
- package/dist/cjs/utils/auditDictionaryField/index.cjs.map +0 -1
- package/dist/cjs/utils/auditDictionaryMetadata/index.cjs.map +0 -1
- package/dist/esm/utils/AI/askDocQuestion.mjs.map +0 -1
- package/dist/esm/utils/auditDictionary/index.mjs.map +0 -1
- package/dist/esm/utils/auditDictionaryField/index.mjs.map +0 -1
- package/dist/esm/utils/auditDictionaryMetadata/index.mjs.map +0 -1
- package/dist/types/utils/AI/askDocQuestion.d.ts.map +0 -1
- package/dist/types/utils/auditDictionary/index.d.ts.map +0 -1
- package/dist/types/utils/auditDictionaryField/index.d.ts.map +0 -1
- package/dist/types/utils/auditDictionaryMetadata/index.d.ts.map +0 -1
- /package/dist/cjs/utils/{auditDictionary → AI/auditDictionary}/CJS_FORMAT.md +0 -0
- /package/dist/cjs/utils/{auditDictionary → AI/auditDictionary}/JSON_FORMAT.md +0 -0
- /package/dist/cjs/utils/{auditDictionary → AI/auditDictionary}/JSX_FORMAT.md +0 -0
- /package/dist/cjs/utils/{auditDictionary → AI/auditDictionary}/MJS_FORMAT.md +0 -0
- /package/dist/cjs/utils/{auditDictionary → AI/auditDictionary}/PROMPT.md +0 -0
- /package/dist/cjs/utils/{auditDictionary → AI/auditDictionary}/TSX_FORMAT.md +0 -0
- /package/dist/cjs/utils/{auditDictionary → AI/auditDictionary}/TS_FORMAT.md +0 -0
- /package/dist/cjs/utils/{auditDictionaryMetadata → AI/auditDictionaryMetadata}/PROMPT.md +0 -0
- /package/dist/esm/utils/{auditDictionary → AI/auditDictionary}/CJS_FORMAT.md +0 -0
- /package/dist/esm/utils/{auditDictionary → AI/auditDictionary}/JSON_FORMAT.md +0 -0
- /package/dist/esm/utils/{auditDictionary → AI/auditDictionary}/JSX_FORMAT.md +0 -0
- /package/dist/esm/utils/{auditDictionary → AI/auditDictionary}/MJS_FORMAT.md +0 -0
- /package/dist/esm/utils/{auditDictionary → AI/auditDictionary}/PROMPT.md +0 -0
- /package/dist/esm/utils/{auditDictionary → AI/auditDictionary}/TSX_FORMAT.md +0 -0
- /package/dist/esm/utils/{auditDictionary → AI/auditDictionary}/TS_FORMAT.md +0 -0
- /package/dist/esm/utils/{auditDictionaryMetadata → AI/auditDictionaryMetadata}/PROMPT.md +0 -0
- /package/dist/types/utils/AI/{askDocQuestion.d.ts → askDocQuestion/askDocQuestion.d.ts} +0 -0
|
@@ -2,7 +2,7 @@ import { readFileSync } from "fs";
|
|
|
2
2
|
import { dirname, join } from "path";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
4
|
import { getLocaleName } from "@intlayer/core";
|
|
5
|
-
import { logger } from "
|
|
5
|
+
import { logger } from "./../../../logger/index.mjs";
|
|
6
6
|
import { OpenAI } from "openai";
|
|
7
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
8
|
const getFileContent = (relativeFilePath) => {
|
|
@@ -31,13 +31,14 @@ const auditDictionary = async ({
|
|
|
31
31
|
model,
|
|
32
32
|
openAiApiKey,
|
|
33
33
|
customPrompt,
|
|
34
|
+
temperature,
|
|
34
35
|
locales,
|
|
35
36
|
defaultLocale,
|
|
36
37
|
tags
|
|
37
38
|
}) => {
|
|
38
39
|
try {
|
|
39
40
|
const openai = new OpenAI({
|
|
40
|
-
apiKey: openAiApiKey
|
|
41
|
+
apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY
|
|
41
42
|
});
|
|
42
43
|
const splitted = (filePath ?? ".json").split(".");
|
|
43
44
|
const fileExtension = splitted[splitted.length - 1];
|
|
@@ -52,7 +53,8 @@ const auditDictionary = async ({
|
|
|
52
53
|
FILE_TEMPLATE[fileExtension]
|
|
53
54
|
).replace("{{fileContent}}", fileContent).replace("{{tagsInstructions}}", formatTagInstructions(tags));
|
|
54
55
|
const chatCompletion = await openai.chat.completions.create({
|
|
55
|
-
model: model ?? "gpt-4o-
|
|
56
|
+
model: openAiApiKey ? model ?? "gpt-4o-2024-11-20" : "gpt-4o-2024-11-20",
|
|
57
|
+
temperature: openAiApiKey ? temperature ?? 0.1 : 0.1,
|
|
56
58
|
messages: [{ role: "system", content: prompt }]
|
|
57
59
|
});
|
|
58
60
|
const newContent = chatCompletion.choices[0].message?.content;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/utils/AI/auditDictionary/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { getLocaleName } from '@intlayer/core';\nimport { logger } from '@logger';\nimport type { Locales } from 'intlayer';\nimport { OpenAI } from 'openai';\nimport type { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AIOptions = {\n model?: string;\n temperature?: number;\n openAiApiKey?: string;\n};\n\nexport type AuditOptions = {\n locales: Locales[];\n defaultLocale: Locales;\n fileContent: string;\n filePath?: string;\n customPrompt?: string;\n tags?: Tag[];\n} & AIOptions;\nexport type AuditFileResultData = { fileContent: string; tokenUsed: number };\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\nconst FILE_TEMPLATE: Record<string, string> = {\n ts: getFileContent('./TS_FORMAT.md'),\n tsx: getFileContent('./TSX_FORMAT.md'),\n js: getFileContent('./MJS_FORMAT.md'),\n mjs: getFileContent('./MJS_FORMAT.md'),\n cjs: getFileContent('./CJS_FORMAT.md'),\n jsx: getFileContent('./JSX_FORMAT.md'),\n json: getFileContent('./JSON_FORMAT.md'),\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Formats a locale with its full name and returns a string representation.\n *\n * @function\n * @param locale - A locale from the project's configuration (e.g., 'en-US', 'fr-FR').\n * @returns A formatted string combining the locale's name and code. Example: \"English (US): en-US\".\n */\nconst formatLocaleWithName = (locale: Locales): string => {\n // getLocaleName returns a human-readable name for the locale.\n const localeName = getLocaleName(locale);\n\n // Concatenate both the readable name and the locale code.\n return `${locale}: ${localeName}`;\n};\n\n/**\n * Formats an array of tags with their keys and instructions.\n *\n * @function\n * @param tags - An array of tags from the project's configuration.\n * @returns A string representation of the tags, with their keys and instructions.\n */\nconst formatTagInstructions = (tags: Tag[] = []) =>\n tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join('\\n\\n');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n */\nexport const auditDictionary = async ({\n fileContent,\n filePath,\n model,\n openAiApiKey,\n customPrompt,\n temperature,\n locales,\n defaultLocale,\n tags,\n}: AuditOptions): Promise<AuditFileResultData | undefined> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,\n });\n\n // Read the file's content.\n const splitted = (filePath ?? '.json').split('.');\n const fileExtension = splitted[splitted.length - 1];\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace('{{filePath}}', filePath ?? 'Not provided')\n .replace(\n '{{defaultLocale}}',\n `{${formatLocaleWithName(defaultLocale)}}`\n )\n .replace(\n '{{otherLocales}}',\n `{${locales.map(formatLocaleWithName).join(', ')}}`\n )\n .replace(\n '{{declarationsContentTemplate}}',\n FILE_TEMPLATE[fileExtension]\n )\n .replace('{{fileContent}}', fileContent)\n .replace('{{tagsInstructions}}', formatTagInstructions(tags));\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: openAiApiKey\n ? (model ?? 'gpt-4o-2024-11-20')\n : 'gpt-4o-2024-11-20',\n temperature: openAiApiKey ? (temperature ?? 0.1) : 0.1,\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AAEvB,SAAS,cAAc;AAGvB,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAyBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,eAAe,KAAK,WAAW,gBAAgB;AACrD,QAAM,cAAc,aAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAEA,MAAM,gBAAwC;AAAA,EAC5C,IAAI,eAAe,gBAAgB;AAAA,EACnC,KAAK,eAAe,iBAAiB;AAAA,EACrC,IAAI,eAAe,iBAAiB;AAAA,EACpC,KAAK,eAAe,iBAAiB;AAAA,EACrC,KAAK,eAAe,iBAAiB;AAAA,EACrC,KAAK,eAAe,iBAAiB;AAAA,EACrC,MAAM,eAAe,kBAAkB;AACzC;AAGA,MAAM,kBAAkB,eAAe,aAAa;AASpD,MAAM,uBAAuB,CAAC,WAA4B;AAExD,QAAM,aAAa,cAAc,MAAM;AAGvC,SAAO,GAAG,MAAM,KAAK,UAAU;AACjC;AASA,MAAM,wBAAwB,CAAC,OAAc,CAAC,MAC5C,KAAK,IAAI,CAAC,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,YAAY,EAAE,EAAE,KAAK,MAAM;AAQ7D,MAAM,kBAAkB,OAAO;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA8D;AAC5D,MAAI;AAIF,UAAM,SAAS,IAAI,OAAO;AAAA,MACxB,QAAQ,gBAAgB,QAAQ,IAAI;AAAA,IACtC,CAAC;AAGD,UAAM,YAAY,YAAY,SAAS,MAAM,GAAG;AAChD,UAAM,gBAAgB,SAAS,SAAS,SAAS,CAAC;AAGlD,UAAM,SACJ,gBACA,gBAAgB,QAAQ,gBAAgB,YAAY,cAAc,EAC/D;AAAA,MACC;AAAA,MACA,IAAI,qBAAqB,aAAa,CAAC;AAAA,IACzC,EACC;AAAA,MACC;AAAA,MACA,IAAI,QAAQ,IAAI,oBAAoB,EAAE,KAAK,IAAI,CAAC;AAAA,IAClD,EACC;AAAA,MACC;AAAA,MACA,cAAc,aAAa;AAAA,IAC7B,EACC,QAAQ,mBAAmB,WAAW,EACtC,QAAQ,wBAAwB,sBAAsB,IAAI,CAAC;AAGhE,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,eACF,SAAS,sBACV;AAAA,MACJ,aAAa,eAAgB,eAAe,MAAO;AAAA,MACnD,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,WAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
You are an expert in internationalization, copy writing and content management. Your task is to audit the given
|
|
1
|
+
You are an expert in internationalization, copy writing and content management. Your task is to audit the given dictionary. If the element is not declared, review it. If this element is missing, write it by considering the given context of the dictionary, and by following instructions.
|
|
2
2
|
|
|
3
3
|
**Instructions:**
|
|
4
4
|
|
|
5
5
|
1. **Terminology:**
|
|
6
6
|
|
|
7
|
-
- **Dictionary:** A
|
|
8
|
-
- **Tag:** A tag is attached to a
|
|
9
|
-
- **KeyPath** The KeyPath correspond to to the path to retrieve the targeted element from the `content` key of the
|
|
7
|
+
- **Dictionary:** A dictionary is a is a file (.ts, .js or .json) that contains the multilingual declaration related to a specific content. A dictionary file is usually related to a specific component, or page or section of a website.
|
|
8
|
+
- **Tag:** A tag is attached to a dictionary and is used to group dictionary and harmonize them.
|
|
9
|
+
- **KeyPath** The KeyPath correspond to to the path to retrieve the targeted element from the `content` key of the dictionary file.
|
|
10
10
|
|
|
11
11
|
2. **Locales:**
|
|
12
12
|
|
|
@@ -15,6 +15,7 @@ You are an expert in internationalization, copy writing and content management.
|
|
|
15
15
|
3. **Audit Requirements:**
|
|
16
16
|
|
|
17
17
|
- **Consistency:** Ensure that all keys have translations for all specified locales.
|
|
18
|
+
- **Incoherence:** Ensure that all content is coherent and not misspelled.
|
|
18
19
|
- **Missing Content:** Identify any missing translations and specify the expected content.
|
|
19
20
|
- **Misplaced Content:** Detect if any translations are placed under incorrect keys.
|
|
20
21
|
- **Type Compliance:** Verify that the content types match the declarations (e.g., strings, string arrays).
|
|
@@ -23,7 +24,8 @@ You are an expert in internationalization, copy writing and content management.
|
|
|
23
24
|
|
|
24
25
|
- **Return Only the Targeted Content:** Provide the updated targeted content as plain text without any markdown, additional comments or explanations.
|
|
25
26
|
- **Consider the locale context:** If the targeted field correspond to a specific language, contains similar languages, as `zh` or `en-GB`, consider return the content in this specified language.
|
|
26
|
-
- **
|
|
27
|
+
- **Fix Incoherent Content:** If the content is inconsistent, misspelled, understandable, or contains errors, fix it by providing a more accurate content.
|
|
28
|
+
- **Escape Special Characters:** If the content contain special characters, escape them using the appropriate escape sequence.
|
|
27
29
|
- **Respect the tags instructions:** If the tags instructions are provided, ensure that the audited file adheres to them.
|
|
28
30
|
|
|
29
31
|
5. **Example Scenario:**
|
|
@@ -75,7 +77,7 @@ You are an expert in internationalization, copy writing and content management.
|
|
|
75
77
|
audienceType: {
|
|
76
78
|
object1: enu({
|
|
77
79
|
"1": t({
|
|
78
|
-
en: "
|
|
80
|
+
en: "Developes, _lln_ Managers",
|
|
79
81
|
es: "Desarrolladores, Gestores de Contenido",
|
|
80
82
|
fr: "Développeurs, Responsables de contenu",
|
|
81
83
|
}),
|
|
@@ -92,7 +94,15 @@ You are an expert in internationalization, copy writing and content management.
|
|
|
92
94
|
|
|
93
95
|
- **Input target:**
|
|
94
96
|
|
|
95
|
-
`[{type: "object", key: "audienceType"},{type: "enumeration", key: ">2"},{type: "
|
|
97
|
+
`[{type: "object", key: "audienceType"},{type: "enumeration", key: ">2"},{type: "translation", key: "es"}]`
|
|
98
|
+
|
|
99
|
+
- **Expected Output:**
|
|
100
|
+
|
|
101
|
+
Desarrolladores, Gestores de Contenido
|
|
102
|
+
|
|
103
|
+
- **Input target:**
|
|
104
|
+
|
|
105
|
+
`[{type: "object", key: "audienceType"},{type: "enumeration", key: "1"},{type: "translation", key: "fr"}]`
|
|
96
106
|
|
|
97
107
|
- **Expected Output:**
|
|
98
108
|
|
|
@@ -2,7 +2,7 @@ import { readFileSync } from "fs";
|
|
|
2
2
|
import { dirname, join } from "path";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
4
|
import { getLocaleName } from "@intlayer/core";
|
|
5
|
-
import { logger } from "
|
|
5
|
+
import { logger } from "./../../../logger/index.mjs";
|
|
6
6
|
import { OpenAI } from "openai";
|
|
7
7
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
8
|
const getFileContent = (relativeFilePath) => {
|
|
@@ -20,6 +20,7 @@ const auditDictionaryField = async ({
|
|
|
20
20
|
fileContent,
|
|
21
21
|
model,
|
|
22
22
|
openAiApiKey,
|
|
23
|
+
temperature,
|
|
23
24
|
customPrompt,
|
|
24
25
|
locales,
|
|
25
26
|
keyPath,
|
|
@@ -27,14 +28,15 @@ const auditDictionaryField = async ({
|
|
|
27
28
|
}) => {
|
|
28
29
|
try {
|
|
29
30
|
const openai = new OpenAI({
|
|
30
|
-
apiKey: openAiApiKey
|
|
31
|
+
apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY
|
|
31
32
|
});
|
|
32
33
|
const prompt = customPrompt ?? CHAT_GPT_PROMPT.replace(
|
|
33
34
|
"{{otherLocales}}",
|
|
34
35
|
`{${locales.map(formatLocaleWithName).join(", ")}}`
|
|
35
36
|
).replace("{{keyPath}}", JSON.stringify(keyPath)).replace("{{fileContent}}", fileContent).replace("{{tagsInstructions}}", formatTagInstructions(tags));
|
|
36
37
|
const chatCompletion = await openai.chat.completions.create({
|
|
37
|
-
model: model ?? "gpt-4o-
|
|
38
|
+
model: openAiApiKey ? model ?? "gpt-4o-2024-11-20" : "gpt-4o-2024-11-20",
|
|
39
|
+
temperature: openAiApiKey ? temperature ?? 0.1 : 0.1,
|
|
38
40
|
messages: [{ role: "system", content: prompt }]
|
|
39
41
|
});
|
|
40
42
|
const newContent = chatCompletion.choices[0].message?.content;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/utils/AI/auditDictionaryField/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { getLocaleName, type KeyPath } from '@intlayer/core';\nimport { logger } from '@logger';\nimport type { Locales } from 'intlayer';\nimport { OpenAI } from 'openai';\nimport type { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AIOptions = {\n model?: string;\n temperature?: number;\n openAiApiKey?: string;\n};\n\nexport type AuditDictionaryFieldOptions = {\n locales: Locales[];\n fileContent: string;\n customPrompt?: string;\n keyPath: KeyPath[];\n tags?: Tag[];\n} & AIOptions;\nexport type AuditDictionaryFieldResultData = {\n fileContent: string;\n tokenUsed: number;\n};\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Formats a locale with its full name and returns a string representation.\n *\n * @function\n * @param locale - A locale from the project's configuration (e.g., 'en-US', 'fr-FR').\n * @returns A formatted string combining the locale's name and code. Example: \"English (US): en-US\".\n */\nconst formatLocaleWithName = (locale: Locales): string => {\n // getLocaleName returns a human-readable name for the locale.\n const localeName = getLocaleName(locale);\n\n // Concatenate both the readable name and the locale code.\n return `${locale}: ${localeName}`;\n};\n\n/**\n * Formats an array of tags with their keys and instructions.\n *\n * @function\n * @param tags - An array of tags from the project's configuration.\n * @returns A string representation of the tags, with their keys and instructions.\n */\nconst formatTagInstructions = (tags: Tag[] = []) =>\n tags.map((tag) => `- ${tag.key}: ${tag.instructions}`).join('\\n\\n');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n */\nexport const auditDictionaryField = async ({\n fileContent,\n model,\n openAiApiKey,\n temperature,\n customPrompt,\n locales,\n keyPath,\n tags,\n}: AuditDictionaryFieldOptions): Promise<\n AuditDictionaryFieldResultData | undefined\n> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,\n });\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace(\n '{{otherLocales}}',\n `{${locales.map(formatLocaleWithName).join(', ')}}`\n )\n .replace('{{keyPath}}', JSON.stringify(keyPath))\n .replace('{{fileContent}}', fileContent)\n .replace('{{tagsInstructions}}', formatTagInstructions(tags));\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: openAiApiKey\n ? (model ?? 'gpt-4o-2024-11-20')\n : 'gpt-4o-2024-11-20',\n temperature: openAiApiKey ? (temperature ?? 0.1) : 0.1,\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,qBAAmC;AAC5C,SAAS,cAAc;AAEvB,SAAS,cAAc;AAGvB,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AA2BxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,eAAe,KAAK,WAAW,gBAAgB;AACrD,QAAM,cAAc,aAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAGA,MAAM,kBAAkB,eAAe,aAAa;AASpD,MAAM,uBAAuB,CAAC,WAA4B;AAExD,QAAM,aAAa,cAAc,MAAM;AAGvC,SAAO,GAAG,MAAM,KAAK,UAAU;AACjC;AASA,MAAM,wBAAwB,CAAC,OAAc,CAAC,MAC5C,KAAK,IAAI,CAAC,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,YAAY,EAAE,EAAE,KAAK,MAAM;AAQ7D,MAAM,uBAAuB,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAEK;AACH,MAAI;AAIF,UAAM,SAAS,IAAI,OAAO;AAAA,MACxB,QAAQ,gBAAgB,QAAQ,IAAI;AAAA,IACtC,CAAC;AAGD,UAAM,SACJ,gBACA,gBAAgB;AAAA,MACd;AAAA,MACA,IAAI,QAAQ,IAAI,oBAAoB,EAAE,KAAK,IAAI,CAAC;AAAA,IAClD,EACG,QAAQ,eAAe,KAAK,UAAU,OAAO,CAAC,EAC9C,QAAQ,mBAAmB,WAAW,EACtC,QAAQ,wBAAwB,sBAAsB,IAAI,CAAC;AAGhE,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,eACF,SAAS,sBACV;AAAA,MACJ,aAAa,eAAgB,eAAe,MAAO;AAAA,MACnD,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,WAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "fs";
|
|
2
2
|
import { dirname, join } from "path";
|
|
3
3
|
import { fileURLToPath } from "url";
|
|
4
|
-
import { logger } from "
|
|
4
|
+
import { logger } from "./../../../logger/index.mjs";
|
|
5
5
|
import { OpenAI } from "openai";
|
|
6
6
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
const getFileContent = (relativeFilePath) => {
|
|
@@ -13,13 +13,14 @@ const CHAT_GPT_PROMPT = getFileContent("./PROMPT.md");
|
|
|
13
13
|
const auditDictionaryMetadata = async ({
|
|
14
14
|
model,
|
|
15
15
|
openAiApiKey,
|
|
16
|
+
temperature,
|
|
16
17
|
customPrompt,
|
|
17
18
|
tags,
|
|
18
19
|
fileContent
|
|
19
20
|
}) => {
|
|
20
21
|
try {
|
|
21
22
|
const openai = new OpenAI({
|
|
22
|
-
apiKey: openAiApiKey
|
|
23
|
+
apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY
|
|
23
24
|
});
|
|
24
25
|
const prompt = customPrompt ?? CHAT_GPT_PROMPT.replace(
|
|
25
26
|
"{{tags}}",
|
|
@@ -30,7 +31,8 @@ const auditDictionaryMetadata = async ({
|
|
|
30
31
|
)}`
|
|
31
32
|
).replace("{{contentDeclaration}}", fileContent);
|
|
32
33
|
const chatCompletion = await openai.chat.completions.create({
|
|
33
|
-
model: model ?? "gpt-4o-
|
|
34
|
+
model: openAiApiKey ? model ?? "gpt-4o-2024-11-20" : "gpt-4o-2024-11-20",
|
|
35
|
+
temperature: openAiApiKey ? temperature ?? 0.1 : 0.1,
|
|
34
36
|
messages: [{ role: "system", content: prompt }]
|
|
35
37
|
});
|
|
36
38
|
const newContent = chatCompletion.choices[0].message?.content;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/utils/AI/auditDictionaryMetadata/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { logger } from '@logger';\nimport { OpenAI } from 'openai';\nimport type { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AIOptions = {\n model?: string;\n temperature?: number;\n openAiApiKey?: string;\n};\n\nexport type AuditOptions = {\n tags: Tag[];\n fileContent: string;\n customPrompt?: string;\n} & AIOptions;\nexport type AuditFileResultData = { fileContent: string; tokenUsed: number };\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n */\nexport const auditDictionaryMetadata = async ({\n model,\n openAiApiKey,\n temperature,\n customPrompt,\n tags,\n fileContent,\n}: AuditOptions): Promise<AuditFileResultData | undefined> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,\n });\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace(\n '{{tags}}',\n `${JSON.stringify(\n tags\n .map(({ key, description }) => `- ${key}: ${description}`)\n .join('\\n\\n'),\n null,\n 2\n )}`\n ).replace('{{contentDeclaration}}', fileContent);\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: openAiApiKey\n ? (model ?? 'gpt-4o-2024-11-20')\n : 'gpt-4o-2024-11-20',\n temperature: openAiApiKey ? (temperature ?? 0.1) : 0.1,\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AACvB,SAAS,cAAc;AAGvB,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAsBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,eAAe,KAAK,WAAW,gBAAgB;AACrD,QAAM,cAAc,aAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAGA,MAAM,kBAAkB,eAAe,aAAa;AAS7C,MAAM,0BAA0B,OAAO;AAAA,EAC5C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA8D;AAC5D,MAAI;AAIF,UAAM,SAAS,IAAI,OAAO;AAAA,MACxB,QAAQ,gBAAgB,QAAQ,IAAI;AAAA,IACtC,CAAC;AAGD,UAAM,SACJ,gBACA,gBAAgB;AAAA,MACd;AAAA,MACA,GAAG,KAAK;AAAA,QACN,KACG,IAAI,CAAC,EAAE,KAAK,YAAY,MAAM,KAAK,GAAG,KAAK,WAAW,EAAE,EACxD,KAAK,MAAM;AAAA,QACd;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,EAAE,QAAQ,0BAA0B,WAAW;AAGjD,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,eACF,SAAS,sBACV;AAAA,MACJ,aAAa,eAAgB,eAAe,MAAO;AAAA,MACnD,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,WAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Your role is to autocomplete the user input.
|
|
2
|
+
|
|
3
|
+
Without prior context, you can try to:
|
|
4
|
+
|
|
5
|
+
- complete the user's word,
|
|
6
|
+
- guess the next word(s)
|
|
7
|
+
- complete the sentence
|
|
8
|
+
|
|
9
|
+
Your completion should not exceed one sentence. Minimize the completion length if you're unsure about the user's input.
|
|
10
|
+
|
|
11
|
+
The user input will be provided in the next user message: { role: 'user', content: 'xxx' }
|
|
12
|
+
|
|
13
|
+
You should return your autocompletion without any additional text or formatting.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { logger } from "./../../../logger/index.mjs";
|
|
5
|
+
import { OpenAI } from "openai";
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
const getFileContent = (relativeFilePath) => {
|
|
8
|
+
const absolutePath = join(__dirname, relativeFilePath);
|
|
9
|
+
const fileContent = readFileSync(absolutePath, "utf-8");
|
|
10
|
+
return fileContent;
|
|
11
|
+
};
|
|
12
|
+
const CHAT_GPT_PROMPT = getFileContent("./PROMPT.md");
|
|
13
|
+
const autocomplete = async ({
|
|
14
|
+
text,
|
|
15
|
+
model,
|
|
16
|
+
openAiApiKey,
|
|
17
|
+
temperature,
|
|
18
|
+
customPrompt
|
|
19
|
+
}) => {
|
|
20
|
+
try {
|
|
21
|
+
const openai = new OpenAI({
|
|
22
|
+
apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY
|
|
23
|
+
});
|
|
24
|
+
const prompt = customPrompt ?? CHAT_GPT_PROMPT;
|
|
25
|
+
const chatCompletion = await openai.chat.completions.create({
|
|
26
|
+
model: openAiApiKey ? model ?? "gpt-4o-mini" : "gpt-4o-mini",
|
|
27
|
+
temperature: openAiApiKey ? temperature ?? 0.1 : 0.1,
|
|
28
|
+
messages: [
|
|
29
|
+
{ role: "system", content: prompt },
|
|
30
|
+
{ role: "user", content: text }
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
const newContent = chatCompletion.choices[0].message?.content;
|
|
34
|
+
logger.info(
|
|
35
|
+
`${chatCompletion.usage?.total_tokens} tokens used in the request`
|
|
36
|
+
);
|
|
37
|
+
return {
|
|
38
|
+
autocompletion: newContent ?? "",
|
|
39
|
+
tokenUsed: chatCompletion.usage?.total_tokens ?? 0
|
|
40
|
+
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
console.error(error);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
export {
|
|
46
|
+
autocomplete
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/utils/AI/autocomplete/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { logger } from '@logger';\nimport { OpenAI } from 'openai';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AIOptions = {\n model?: string;\n temperature?: number;\n openAiApiKey?: string;\n};\n\nexport type AutocompleteOptions = {\n text: string;\n customPrompt?: string;\n} & AIOptions;\nexport type AutocompleteFileResultData = {\n autocompletion: string;\n tokenUsed: number;\n};\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Autocompletes a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n */\nexport const autocomplete = async ({\n text,\n model,\n openAiApiKey,\n temperature,\n customPrompt,\n}: AutocompleteOptions): Promise<AutocompleteFileResultData | undefined> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,\n });\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt = customPrompt ?? CHAT_GPT_PROMPT;\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: openAiApiKey ? (model ?? 'gpt-4o-mini') : 'gpt-4o-mini',\n temperature: openAiApiKey ? (temperature ?? 0.1) : 0.1,\n messages: [\n { role: 'system', content: prompt },\n { role: 'user', content: text },\n ],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n autocompletion: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AACvB,SAAS,cAAc;AAEvB,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAwBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,eAAe,KAAK,WAAW,gBAAgB;AACrD,QAAM,cAAc,aAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAGA,MAAM,kBAAkB,eAAe,aAAa;AAS7C,MAAM,eAAe,OAAO;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA4E;AAC1E,MAAI;AAIF,UAAM,SAAS,IAAI,OAAO;AAAA,MACxB,QAAQ,gBAAgB,QAAQ,IAAI;AAAA,IACtC,CAAC;AAGD,UAAM,SAAS,gBAAgB;AAG/B,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,eAAgB,SAAS,gBAAiB;AAAA,MACjD,aAAa,eAAgB,eAAe,MAAO;AAAA,MACnD,UAAU;AAAA,QACR,EAAE,MAAM,UAAU,SAAS,OAAO;AAAA,QAClC,EAAE,MAAM,QAAQ,SAAS,KAAK;AAAA,MAChC;AAAA,IACF,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,WAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,gBAAgB,cAAc;AAAA,MAC9B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -14,19 +14,21 @@ const auditTag = async ({
|
|
|
14
14
|
model,
|
|
15
15
|
openAiApiKey,
|
|
16
16
|
customPrompt,
|
|
17
|
+
temperature,
|
|
17
18
|
tag,
|
|
18
19
|
dictionaries
|
|
19
20
|
}) => {
|
|
20
21
|
try {
|
|
21
22
|
const openai = new OpenAI({
|
|
22
|
-
apiKey: openAiApiKey
|
|
23
|
+
apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY
|
|
23
24
|
});
|
|
24
25
|
const prompt = customPrompt ?? CHAT_GPT_PROMPT.replace("{{tag}}", `${JSON.stringify(tag)}`).replace(
|
|
25
26
|
"{{contentDeclarations}}",
|
|
26
27
|
dictionaries.map((dictionary) => `- ${JSON.stringify(dictionary)}`).join("\n\n")
|
|
27
28
|
);
|
|
28
29
|
const chatCompletion = await openai.chat.completions.create({
|
|
29
|
-
model: model ?? "gpt-4o-
|
|
30
|
+
model: openAiApiKey ? model ?? "gpt-4o-2024-11-20" : "gpt-4o-2024-11-20",
|
|
31
|
+
temperature: openAiApiKey ? temperature ?? 0.1 : 0.1,
|
|
30
32
|
messages: [{ role: "system", content: prompt }]
|
|
31
33
|
});
|
|
32
34
|
const newContent = chatCompletion.choices[0].message?.content;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/auditTag/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { logger } from '@logger';\nimport { OpenAI } from 'openai';\nimport type { Dictionary } from '@/types/dictionary.types';\nimport type { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/auditTag/index.ts"],"sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { fileURLToPath } from 'url';\nimport { logger } from '@logger';\nimport { OpenAI } from 'openai';\nimport type { Dictionary } from '@/types/dictionary.types';\nimport type { Tag } from '@/types/tag.types';\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nexport type AIOptions = {\n model?: string;\n temperature?: number;\n openAiApiKey?: string;\n};\n\nexport type AuditOptions = {\n tag: Tag;\n dictionaries: Dictionary[];\n customPrompt?: string;\n} & AIOptions;\nexport type AuditFileResultData = { fileContent: string; tokenUsed: number };\n\n/**\n * Reads the content of a file synchronously.\n *\n * @function\n * @param relativeFilePath - The relative or absolute path to the target file.\n * @returns The entire contents of the specified file as a UTF-8 encoded string.\n */\nconst getFileContent = (relativeFilePath: string): string => {\n const absolutePath = join(__dirname, relativeFilePath);\n const fileContent = readFileSync(absolutePath, 'utf-8');\n return fileContent;\n};\n\n// The prompt template to send to ChatGPT, requesting an audit of content declaration files.\nconst CHAT_GPT_PROMPT = getFileContent('./PROMPT.md');\n\n/**\n * Audits a content declaration file by constructing a prompt for ChatGPT.\n * The prompt includes details about the project's locales, file paths of content declarations,\n * and requests for identifying issues or inconsistencies. It prints the prompt for each file,\n * and could be adapted to send requests to the ChatGPT model.\n *\n * @async\n * @function\n * @param filePath - The relative or absolute path to the target file.\n * @param options - Optional configuration for the audit process.\n * @returns This function returns a Promise that resolves once the audit is complete.\n */\nexport const auditTag = async ({\n model,\n openAiApiKey,\n customPrompt,\n temperature,\n tag,\n dictionaries,\n}: AuditOptions): Promise<AuditFileResultData | undefined> => {\n try {\n // Optionally, you could initialize and configure the OpenAI client here, if you intend to make API calls.\n // Uncomment and configure the following lines if you have `openai` installed and want to call the API:\n\n const openai = new OpenAI({\n apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY,\n });\n\n // Prepare the prompt for ChatGPT by replacing placeholders with actual values.\n const prompt =\n customPrompt ??\n CHAT_GPT_PROMPT.replace('{{tag}}', `${JSON.stringify(tag)}`).replace(\n '{{contentDeclarations}}',\n dictionaries\n .map((dictionary) => `- ${JSON.stringify(dictionary)}`)\n .join('\\n\\n')\n );\n\n // Example of how you might request a completion from ChatGPT:\n const chatCompletion = await openai.chat.completions.create({\n model: openAiApiKey\n ? (model ?? 'gpt-4o-2024-11-20')\n : 'gpt-4o-2024-11-20',\n temperature: openAiApiKey ? (temperature ?? 0.1) : 0.1,\n messages: [{ role: 'system', content: prompt }],\n });\n\n const newContent = chatCompletion.choices[0].message?.content;\n\n logger.info(\n `${chatCompletion.usage?.total_tokens} tokens used in the request`\n );\n\n return {\n fileContent: newContent ?? '',\n tokenUsed: chatCompletion.usage?.total_tokens ?? 0,\n };\n } catch (error) {\n console.error(error);\n }\n};\n"],"mappings":"AAAA,SAAS,oBAAoB;AAC7B,SAAS,SAAS,YAAY;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,cAAc;AACvB,SAAS,cAAc;AAIvB,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAsBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,eAAe,KAAK,WAAW,gBAAgB;AACrD,QAAM,cAAc,aAAa,cAAc,OAAO;AACtD,SAAO;AACT;AAGA,MAAM,kBAAkB,eAAe,aAAa;AAc7C,MAAM,WAAW,OAAO;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA8D;AAC5D,MAAI;AAIF,UAAM,SAAS,IAAI,OAAO;AAAA,MACxB,QAAQ,gBAAgB,QAAQ,IAAI;AAAA,IACtC,CAAC;AAGD,UAAM,SACJ,gBACA,gBAAgB,QAAQ,WAAW,GAAG,KAAK,UAAU,GAAG,CAAC,EAAE,EAAE;AAAA,MAC3D;AAAA,MACA,aACG,IAAI,CAAC,eAAe,KAAK,KAAK,UAAU,UAAU,CAAC,EAAE,EACrD,KAAK,MAAM;AAAA,IAChB;AAGF,UAAM,iBAAiB,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MAC1D,OAAO,eACF,SAAS,sBACV;AAAA,MACJ,aAAa,eAAgB,eAAe,MAAO;AAAA,MACnD,UAAU,CAAC,EAAE,MAAM,UAAU,SAAS,OAAO,CAAC;AAAA,IAChD,CAAC;AAED,UAAM,aAAa,eAAe,QAAQ,CAAC,EAAE,SAAS;AAEtD,WAAO;AAAA,MACL,GAAG,eAAe,OAAO,YAAY;AAAA,IACvC;AAEA,WAAO;AAAA,MACL,aAAa,cAAc;AAAA,MAC3B,WAAW,eAAe,OAAO,gBAAgB;AAAA,IACnD;AAAA,EACF,SAAS,OAAO;AACd,YAAQ,MAAM,KAAK;AAAA,EACrB;AACF;","names":[]}
|
|
@@ -1088,6 +1088,19 @@ const errorData = {
|
|
|
1088
1088
|
},
|
|
1089
1089
|
statusCode: HttpStatusCodes.FORBIDDEN_403
|
|
1090
1090
|
},
|
|
1091
|
+
PROJECTS_EXIST: {
|
|
1092
|
+
title: {
|
|
1093
|
+
en: "Projects Exist",
|
|
1094
|
+
fr: "Des projets existent",
|
|
1095
|
+
es: "Existen proyectos"
|
|
1096
|
+
},
|
|
1097
|
+
message: {
|
|
1098
|
+
en: "Projects exist in this organization. Please delete them before deleting the organization.",
|
|
1099
|
+
fr: "Des projets existent dans cette organisation. Veuillez les supprimer avant de supprimer l'organisation.",
|
|
1100
|
+
es: "Existen proyectos en esta organizaci\xF3n. Por favor, elimine los antes de eliminar la organizaci\xF3n."
|
|
1101
|
+
},
|
|
1102
|
+
statusCode: HttpStatusCodes.FORBIDDEN_403
|
|
1103
|
+
},
|
|
1091
1104
|
PLAN_NOT_FOUND: {
|
|
1092
1105
|
title: {
|
|
1093
1106
|
en: "Plan Not Found",
|
|
@@ -1347,6 +1360,19 @@ const errorData = {
|
|
|
1347
1360
|
es: "La etiqueta especificada no est\xE1 en la organizaci\xF3n."
|
|
1348
1361
|
},
|
|
1349
1362
|
statusCode: HttpStatusCodes.FORBIDDEN_403
|
|
1363
|
+
},
|
|
1364
|
+
AI_ACCESS_DENIED: {
|
|
1365
|
+
title: {
|
|
1366
|
+
en: "Access denied",
|
|
1367
|
+
fr: "Acc\xE8s refus\xE9",
|
|
1368
|
+
es: "Acceso denegado"
|
|
1369
|
+
},
|
|
1370
|
+
message: {
|
|
1371
|
+
en: "Invalid Access keys. Access keys should be defined to use AI features. See https://intlayer.org/doc/concept/editor. Alternatively, you can add your own openAI API key in the settings.",
|
|
1372
|
+
fr: "Cl\xE9es d'acc\xE8s invalides. Les cl\xE9s d'acc\xE8s doivent \xEAtre d\xE9finies pour utiliser les fonctionnalit\xE9s AI. Voir https://intlayer.org/doc/concept/editor. Alternativement, vous pouvez ajouter votre propre cl\xE9 API openAI dans les param\xE8tres.",
|
|
1373
|
+
es: "Claves de acceso no v\xE1lidas. Las claves de acceso deben definirse para usar funciones AI. Ver https://intlayer.org/doc/concept/editor. Alternativamente, puede agregar su propia clave API openAI en la configuraci\xF3n."
|
|
1374
|
+
},
|
|
1375
|
+
statusCode: HttpStatusCodes.FORBIDDEN_403
|
|
1350
1376
|
}
|
|
1351
1377
|
};
|
|
1352
1378
|
export {
|