@intlayer/backend 5.4.2 → 5.5.0

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.
Files changed (105) hide show
  1. package/dist/cjs/controllers/ai.controller.cjs +73 -57
  2. package/dist/cjs/controllers/ai.controller.cjs.map +1 -1
  3. package/dist/cjs/controllers/dictionary.controller.cjs +5 -0
  4. package/dist/cjs/controllers/dictionary.controller.cjs.map +1 -1
  5. package/dist/cjs/export.cjs +4 -2
  6. package/dist/cjs/export.cjs.map +1 -1
  7. package/dist/cjs/routes/ai.routes.cjs +6 -0
  8. package/dist/cjs/routes/ai.routes.cjs.map +1 -1
  9. package/dist/cjs/services/dictionary.service.cjs +6 -1
  10. package/dist/cjs/services/dictionary.service.cjs.map +1 -1
  11. package/dist/cjs/utils/AI/aiSdk.cjs +140 -0
  12. package/dist/cjs/utils/AI/aiSdk.cjs.map +1 -0
  13. package/dist/cjs/utils/AI/askDocQuestion/PROMPT.md +2 -1
  14. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs +32 -27
  15. package/dist/cjs/utils/AI/askDocQuestion/askDocQuestion.cjs.map +1 -1
  16. package/dist/cjs/utils/AI/askDocQuestion/embeddings.json +13523 -0
  17. package/dist/cjs/utils/AI/auditDictionary/PROMPT.md +4 -0
  18. package/dist/cjs/utils/AI/auditDictionary/index.cjs +36 -43
  19. package/dist/cjs/utils/AI/auditDictionary/index.cjs.map +1 -1
  20. package/dist/cjs/utils/AI/auditDictionaryField/PROMPT.md +4 -0
  21. package/dist/cjs/utils/AI/auditDictionaryField/index.cjs +34 -28
  22. package/dist/cjs/utils/AI/auditDictionaryField/index.cjs.map +1 -1
  23. package/dist/cjs/utils/AI/auditDictionaryMetadata/PROMPT.md +4 -0
  24. package/dist/cjs/utils/AI/auditDictionaryMetadata/index.cjs +23 -23
  25. package/dist/cjs/utils/AI/auditDictionaryMetadata/index.cjs.map +1 -1
  26. package/dist/cjs/utils/{auditTag → AI/auditTag}/PROMPT.md +4 -0
  27. package/dist/cjs/utils/{auditTag → AI/auditTag}/index.cjs +27 -27
  28. package/dist/cjs/utils/AI/auditTag/index.cjs.map +1 -0
  29. package/dist/cjs/utils/AI/autocomplete/PROMPT.md +4 -0
  30. package/dist/cjs/utils/AI/autocomplete/index.cjs +25 -22
  31. package/dist/cjs/utils/AI/autocomplete/index.cjs.map +1 -1
  32. package/dist/cjs/utils/AI/translateJSON/PROMPT.md +53 -0
  33. package/dist/cjs/utils/AI/translateJSON/index.cjs +106 -0
  34. package/dist/cjs/utils/AI/translateJSON/index.cjs.map +1 -0
  35. package/dist/cjs/utils/extractJSON.cjs +52 -0
  36. package/dist/cjs/utils/extractJSON.cjs.map +1 -0
  37. package/dist/esm/controllers/ai.controller.mjs +71 -56
  38. package/dist/esm/controllers/ai.controller.mjs.map +1 -1
  39. package/dist/esm/controllers/dictionary.controller.mjs +5 -0
  40. package/dist/esm/controllers/dictionary.controller.mjs.map +1 -1
  41. package/dist/esm/export.mjs +3 -2
  42. package/dist/esm/export.mjs.map +1 -1
  43. package/dist/esm/routes/ai.routes.mjs +8 -1
  44. package/dist/esm/routes/ai.routes.mjs.map +1 -1
  45. package/dist/esm/services/dictionary.service.mjs +6 -1
  46. package/dist/esm/services/dictionary.service.mjs.map +1 -1
  47. package/dist/esm/utils/AI/aiSdk.mjs +115 -0
  48. package/dist/esm/utils/AI/aiSdk.mjs.map +1 -0
  49. package/dist/esm/utils/AI/askDocQuestion/PROMPT.md +2 -1
  50. package/dist/esm/utils/AI/askDocQuestion/askDocQuestion.mjs +32 -27
  51. package/dist/esm/utils/AI/askDocQuestion/askDocQuestion.mjs.map +1 -1
  52. package/dist/esm/utils/AI/askDocQuestion/embeddings.json +13523 -0
  53. package/dist/esm/utils/AI/auditDictionary/PROMPT.md +4 -0
  54. package/dist/esm/utils/AI/auditDictionary/index.mjs +36 -43
  55. package/dist/esm/utils/AI/auditDictionary/index.mjs.map +1 -1
  56. package/dist/esm/utils/AI/auditDictionaryField/PROMPT.md +4 -0
  57. package/dist/esm/utils/AI/auditDictionaryField/index.mjs +34 -28
  58. package/dist/esm/utils/AI/auditDictionaryField/index.mjs.map +1 -1
  59. package/dist/esm/utils/AI/auditDictionaryMetadata/PROMPT.md +4 -0
  60. package/dist/esm/utils/AI/auditDictionaryMetadata/index.mjs +23 -23
  61. package/dist/esm/utils/AI/auditDictionaryMetadata/index.mjs.map +1 -1
  62. package/dist/esm/utils/{auditTag → AI/auditTag}/PROMPT.md +4 -0
  63. package/dist/esm/utils/AI/auditTag/index.mjs +49 -0
  64. package/dist/esm/utils/AI/auditTag/index.mjs.map +1 -0
  65. package/dist/esm/utils/AI/autocomplete/PROMPT.md +4 -0
  66. package/dist/esm/utils/AI/autocomplete/index.mjs +25 -22
  67. package/dist/esm/utils/AI/autocomplete/index.mjs.map +1 -1
  68. package/dist/esm/utils/AI/translateJSON/PROMPT.md +53 -0
  69. package/dist/esm/utils/AI/translateJSON/index.mjs +81 -0
  70. package/dist/esm/utils/AI/translateJSON/index.mjs.map +1 -0
  71. package/dist/esm/utils/extractJSON.mjs +28 -0
  72. package/dist/esm/utils/extractJSON.mjs.map +1 -0
  73. package/dist/types/controllers/ai.controller.d.ts +12 -21
  74. package/dist/types/controllers/ai.controller.d.ts.map +1 -1
  75. package/dist/types/controllers/dictionary.controller.d.ts.map +1 -1
  76. package/dist/types/export.d.ts +12 -11
  77. package/dist/types/export.d.ts.map +1 -1
  78. package/dist/types/routes/ai.routes.d.ts +5 -0
  79. package/dist/types/routes/ai.routes.d.ts.map +1 -1
  80. package/dist/types/services/dictionary.service.d.ts +2 -2
  81. package/dist/types/services/dictionary.service.d.ts.map +1 -1
  82. package/dist/types/utils/AI/aiSdk.d.ts +41 -0
  83. package/dist/types/utils/AI/aiSdk.d.ts.map +1 -0
  84. package/dist/types/utils/AI/askDocQuestion/askDocQuestion.d.ts +2 -1
  85. package/dist/types/utils/AI/askDocQuestion/askDocQuestion.d.ts.map +1 -1
  86. package/dist/types/utils/AI/auditDictionary/index.d.ts +10 -15
  87. package/dist/types/utils/AI/auditDictionary/index.d.ts.map +1 -1
  88. package/dist/types/utils/AI/auditDictionaryField/index.d.ts +9 -14
  89. package/dist/types/utils/AI/auditDictionaryField/index.d.ts.map +1 -1
  90. package/dist/types/utils/AI/auditDictionaryMetadata/index.d.ts +7 -13
  91. package/dist/types/utils/AI/auditDictionaryMetadata/index.d.ts.map +1 -1
  92. package/dist/types/utils/AI/auditTag/index.d.ts +18 -0
  93. package/dist/types/utils/AI/auditTag/index.d.ts.map +1 -0
  94. package/dist/types/utils/AI/autocomplete/index.d.ts +6 -12
  95. package/dist/types/utils/AI/autocomplete/index.d.ts.map +1 -1
  96. package/dist/types/utils/AI/translateJSON/index.d.ts +24 -0
  97. package/dist/types/utils/AI/translateJSON/index.d.ts.map +1 -0
  98. package/dist/types/utils/extractJSON.d.ts +6 -0
  99. package/dist/types/utils/extractJSON.d.ts.map +1 -0
  100. package/package.json +13 -7
  101. package/dist/cjs/utils/auditTag/index.cjs.map +0 -1
  102. package/dist/esm/utils/auditTag/index.mjs +0 -49
  103. package/dist/esm/utils/auditTag/index.mjs.map +0 -1
  104. package/dist/types/utils/auditTag/index.d.ts +0 -30
  105. package/dist/types/utils/auditTag/index.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/AI/auditTag/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAM7C,OAAO,EAAE,SAAS,EAA2B,MAAM,UAAU,CAAC;AAS9D,MAAM,MAAM,YAAY,GAAG;IACzB,YAAY,EAAE,UAAU,EAAE,CAAC;IAC3B,GAAG,EAAE,GAAG,CAAC;IACT,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAKF;;;GAGG;AACH,eAAO,MAAM,QAAQ,GAAU,mCAI5B,YAAY,KAAG,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAwC5D,CAAC"}
@@ -1,22 +1,16 @@
1
- export type AIOptions = {
2
- model?: string;
3
- temperature?: number;
4
- openAiApiKey?: string;
5
- };
1
+ import { AIOptions } from '../aiSdk';
6
2
  export type AutocompleteOptions = {
7
3
  text: string;
8
- customPrompt?: string;
9
- } & AIOptions;
4
+ aiOptions?: AIOptions;
5
+ };
10
6
  export type AutocompleteFileResultData = {
11
7
  autocompletion: string;
12
8
  tokenUsed: number;
13
9
  };
14
10
  /**
15
- * Autocompletes a content declaration file by constructing a prompt for ChatGPT.
11
+ * Autocompletes a content declaration file by constructing a prompt for AI models.
16
12
  * The prompt includes details about the project's locales, file paths of content declarations,
17
- * and requests for identifying issues or inconsistencies. It prints the prompt for each file,
18
- * and could be adapted to send requests to the ChatGPT model.
19
- *
13
+ * and requests for identifying issues or inconsistencies.
20
14
  */
21
- export declare const autocomplete: ({ text, model, openAiApiKey, temperature, customPrompt, }: AutocompleteOptions) => Promise<AutocompleteFileResultData | undefined>;
15
+ export declare const autocomplete: ({ text, aiOptions, }: AutocompleteOptions) => Promise<AutocompleteFileResultData | undefined>;
22
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/AI/autocomplete/index.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,SAAS,CAAC;AACd,MAAM,MAAM,0BAA0B,GAAG;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAkBF;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAU,2DAMhC,mBAAmB,KAAG,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAmCtE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/AI/autocomplete/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAA2B,MAAM,UAAU,CAAC;AAS9D,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAKF;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,sBAGhC,mBAAmB,KAAG,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAwCtE,CAAC"}
@@ -0,0 +1,24 @@
1
+ import type { Tag } from '../../../types/tag.types';
2
+ import type { Locales } from 'intlayer';
3
+ import { AIOptions } from '../aiSdk';
4
+ export type TranslateJSONOptions = {
5
+ entryFileContent: JSON;
6
+ presetOutputContent: JSON;
7
+ dictionaryDescription: string;
8
+ entryLocale: Locales;
9
+ outputLocale: Locales;
10
+ tags: Tag[];
11
+ aiOptions?: AIOptions;
12
+ mode: 'complete' | 'review';
13
+ };
14
+ export type TranslateJSONResultData = {
15
+ fileContent: string;
16
+ tokenUsed: number;
17
+ };
18
+ /**
19
+ * TranslateJSONs a content declaration file by constructing a prompt for AI models.
20
+ * The prompt includes details about the project's locales, file paths of content declarations,
21
+ * and requests for identifying issues or inconsistencies.
22
+ */
23
+ export declare const translateJSON: ({ entryFileContent, presetOutputContent, dictionaryDescription, aiOptions, entryLocale, outputLocale, tags, mode, }: TranslateJSONOptions) => Promise<TranslateJSONResultData | undefined>;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/AI/translateJSON/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAO7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGxC,OAAO,EAAE,SAAS,EAA2B,MAAM,UAAU,CAAC;AAS9D,MAAM,MAAM,oBAAoB,GAAG;IACjC,gBAAgB,EAAE,IAAI,CAAC;IACvB,mBAAmB,EAAE,IAAI,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAyCF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAU,qHASjC,oBAAoB,KAAG,OAAO,CAAC,uBAAuB,GAAG,SAAS,CAoDpE,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Extracts the first JSON value (object or array) from a string.
3
+ * Returns the parsed value, or throws if no valid JSON is found.
4
+ */
5
+ export declare const extractJson: <T = any>(input: string) => T;
6
+ //# sourceMappingURL=extractJSON.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractJSON.d.ts","sourceRoot":"","sources":["../../../src/utils/extractJSON.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,GAAG,GAAG,EAAE,OAAO,MAAM,KAAG,CA0BpD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/backend",
3
- "version": "5.4.2",
3
+ "version": "5.5.0",
4
4
  "private": false,
5
5
  "description": "Intlayer Backend is a an application that allow you to manage your Intlayer content and interact with the intlayer editor.",
6
6
  "keywords": [
@@ -50,7 +50,13 @@
50
50
  "./package.json"
51
51
  ],
52
52
  "dependencies": {
53
+ "@ai-sdk/anthropic": "^1.2.11",
54
+ "@ai-sdk/deepseek": "^0.1.17",
55
+ "@ai-sdk/google": "^1.2.17",
56
+ "@ai-sdk/mistral": "^1.2.8",
57
+ "@ai-sdk/openai": "^1.0.0",
53
58
  "@react-email/components": "^0.0.34",
59
+ "ai": "^4.2.0",
54
60
  "bcryptjs": "^3.0.2",
55
61
  "compression": "^1.8.0",
56
62
  "cookie-parser": "^1.4.7",
@@ -73,7 +79,7 @@
73
79
  "uuid": "^11.1.0",
74
80
  "validator": "^13.12.0",
75
81
  "winston": "^3.17.0",
76
- "express-intlayer": "5.4.2"
82
+ "express-intlayer": "5.5.0"
77
83
  },
78
84
  "devDependencies": {
79
85
  "@types/body-parser": "^1.19.5",
@@ -97,15 +103,15 @@
97
103
  "tsup": "^8.4.0",
98
104
  "tsx": "^4.19.3",
99
105
  "typescript": "^5.8.2",
100
- "@intlayer/core": "5.4.2",
101
- "@intlayer/config": "5.4.2",
106
+ "@intlayer/core": "5.5.0",
107
+ "@intlayer/config": "5.5.0",
102
108
  "@utils/eslint-config": "1.0.4",
103
109
  "@utils/ts-config": "1.0.4",
104
110
  "@utils/ts-config-types": "1.0.4",
105
111
  "@utils/tsup-config": "1.0.4",
106
- "intlayer": "5.4.2",
107
- "@intlayer/blog": "5.4.2",
108
- "@intlayer/docs": "5.4.2"
112
+ "intlayer": "5.5.0",
113
+ "@intlayer/blog": "^5.5.0",
114
+ "@intlayer/docs": "5.5.0"
109
115
  },
110
116
  "scripts": {
111
117
  "build": "pnpm build:package & pnpm build:types",
@@ -1 +0,0 @@
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;AAAA;AAAA;AAAA;AAAA;AAAA,gBAA6B;AAC7B,kBAA8B;AAC9B,iBAA8B;AAC9B,oBAAuB;AACvB,oBAAuB;AAJvB;AAQA,MAAM,gBAAY,yBAAQ,0BAAc,YAAY,GAAG,CAAC;AAsBxD,MAAM,iBAAiB,CAAC,qBAAqC;AAC3D,QAAM,mBAAe,kBAAK,WAAW,gBAAgB;AACrD,QAAM,kBAAc,wBAAa,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,qBAAO;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,yBAAO;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,49 +0,0 @@
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 auditTag = async ({
14
- model,
15
- openAiApiKey,
16
- customPrompt,
17
- temperature,
18
- tag,
19
- dictionaries
20
- }) => {
21
- try {
22
- const openai = new OpenAI({
23
- apiKey: openAiApiKey ?? process.env.OPENAI_API_KEY
24
- });
25
- const prompt = customPrompt ?? CHAT_GPT_PROMPT.replace("{{tag}}", `${JSON.stringify(tag)}`).replace(
26
- "{{contentDeclarations}}",
27
- dictionaries.map((dictionary) => `- ${JSON.stringify(dictionary)}`).join("\n\n")
28
- );
29
- const chatCompletion = await openai.chat.completions.create({
30
- model: openAiApiKey ? model ?? "gpt-4o-2024-11-20" : "gpt-4o-2024-11-20",
31
- temperature: openAiApiKey ? temperature ?? 0.1 : 0.1,
32
- messages: [{ role: "system", content: prompt }]
33
- });
34
- const newContent = chatCompletion.choices[0].message?.content;
35
- logger.info(
36
- `${chatCompletion.usage?.total_tokens} tokens used in the request`
37
- );
38
- return {
39
- fileContent: newContent ?? "",
40
- tokenUsed: chatCompletion.usage?.total_tokens ?? 0
41
- };
42
- } catch (error) {
43
- console.error(error);
44
- }
45
- };
46
- export {
47
- auditTag
48
- };
49
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
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":[]}
@@ -1,30 +0,0 @@
1
- import type { Dictionary } from '../../types/dictionary.types';
2
- import type { Tag } from '../../types/tag.types';
3
- export type AIOptions = {
4
- model?: string;
5
- temperature?: number;
6
- openAiApiKey?: string;
7
- };
8
- export type AuditOptions = {
9
- tag: Tag;
10
- dictionaries: Dictionary[];
11
- customPrompt?: string;
12
- } & AIOptions;
13
- export type AuditFileResultData = {
14
- fileContent: string;
15
- tokenUsed: number;
16
- };
17
- /**
18
- * Audits a content declaration file by constructing a prompt for ChatGPT.
19
- * The prompt includes details about the project's locales, file paths of content declarations,
20
- * and requests for identifying issues or inconsistencies. It prints the prompt for each file,
21
- * and could be adapted to send requests to the ChatGPT model.
22
- *
23
- * @async
24
- * @function
25
- * @param filePath - The relative or absolute path to the target file.
26
- * @param options - Optional configuration for the audit process.
27
- * @returns This function returns a Promise that resolves once the audit is complete.
28
- */
29
- export declare const auditTag: ({ model, openAiApiKey, customPrompt, temperature, tag, dictionaries, }: AuditOptions) => Promise<AuditFileResultData | undefined>;
30
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/auditTag/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAI7C,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,EAAE,GAAG,CAAC;IACT,YAAY,EAAE,UAAU,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,SAAS,CAAC;AACd,MAAM,MAAM,mBAAmB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAkB7E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,GAAU,wEAO5B,YAAY,KAAG,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAyCxD,CAAC"}