@breadstone-tools/localizator-ai 0.0.228 → 0.0.230
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/Generator/ResourceGenerator.d.ts +22 -0
- package/Generator/ResourceGenerator.d.ts.map +1 -1
- package/Generator/ResourceGenerator.js +95 -12
- package/Generator/ResourceGenerator.js.map +1 -1
- package/Generator/Schemas/ResourceModelSchema.d.ts +30 -0
- package/Generator/Schemas/ResourceModelSchema.d.ts.map +1 -0
- package/Generator/Schemas/ResourceModelSchema.js +33 -0
- package/Generator/Schemas/ResourceModelSchema.js.map +1 -0
- package/Generator/Strategies/ChatGptResourceGeneratorStrategy.d.ts +6 -6
- package/Generator/Strategies/ChatGptResourceGeneratorStrategy.d.ts.map +1 -1
- package/Generator/Strategies/ChatGptResourceGeneratorStrategy.js +25 -18
- package/Generator/Strategies/ChatGptResourceGeneratorStrategy.js.map +1 -1
- package/Generator/Strategies/GeminiResourceGeneratorStrategy.d.ts +6 -7
- package/Generator/Strategies/GeminiResourceGeneratorStrategy.d.ts.map +1 -1
- package/Generator/Strategies/GeminiResourceGeneratorStrategy.js +29 -54
- package/Generator/Strategies/GeminiResourceGeneratorStrategy.js.map +1 -1
- package/package.json +7 -6
|
@@ -69,5 +69,27 @@ export declare class ResourceGenerator {
|
|
|
69
69
|
* It could be that the serialization is not correct, so we can check the output.
|
|
70
70
|
*/
|
|
71
71
|
private dumpResult;
|
|
72
|
+
/**
|
|
73
|
+
* Loads existing translated models from the target file, if it exists.
|
|
74
|
+
*
|
|
75
|
+
* @private
|
|
76
|
+
* @param targetFilePath The path to the target file.
|
|
77
|
+
* @param resource The source resource info (used to determine the file type).
|
|
78
|
+
* @returns The existing models, or an empty array if the file does not exist.
|
|
79
|
+
*/
|
|
80
|
+
private loadExistingModels;
|
|
81
|
+
/**
|
|
82
|
+
* Merges newly translated models into the existing target models and writes the
|
|
83
|
+
* result to the original target file. New translations overwrite existing entries
|
|
84
|
+
* by key; keys that were not re-translated keep their previous value.
|
|
85
|
+
*
|
|
86
|
+
* @private
|
|
87
|
+
* @param existingModels The models already present in the target file.
|
|
88
|
+
* @param newModels The models that were successfully translated in this run.
|
|
89
|
+
* @param targetFilePath The target file path.
|
|
90
|
+
* @param locale The target locale.
|
|
91
|
+
* @param resource The source resource info.
|
|
92
|
+
*/
|
|
93
|
+
private mergeAndSave;
|
|
72
94
|
}
|
|
73
95
|
//# sourceMappingURL=ResourceGenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceGenerator.d.ts","sourceRoot":"","sources":["../../src/Generator/ResourceGenerator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAoF,KAAK,WAAW,EAAE,KAAK,OAAO,EAAE,MAAM,sCAAsC,CAAC;AACxK,OAAO,KAAK,EAAE,aAAa,EAAkB,cAAc,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAE7H,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAC;AAC3F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AAOzF;;;;GAIG;AACH,qBAAa,iBAAiB;IAI1B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;IAC1C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IACnD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IACrD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA0C;IAMtE;;;;;;;;OAQG;gBACgB,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,yBAAyB;
|
|
1
|
+
{"version":3,"file":"ResourceGenerator.d.ts","sourceRoot":"","sources":["../../src/Generator/ResourceGenerator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
|
@@ -37,9 +37,13 @@ class ResourceGenerator {
|
|
|
37
37
|
this._fileSystem = fileSystem;
|
|
38
38
|
this._transformer = transformer;
|
|
39
39
|
this._reader = reader;
|
|
40
|
+
const chatGptResourceGeneratorStrategy = new ChatGptResourceGeneratorStrategy_js_1.ChatGptResourceGeneratorStrategy(fileSystem, options.config);
|
|
41
|
+
const geminiResourceGeneratorStrategy = new GeminiResourceGeneratorStrategy_js_1.GeminiResourceGeneratorStrategy(fileSystem, options.config);
|
|
40
42
|
this._strategies = new Map()
|
|
41
|
-
.set('
|
|
42
|
-
.set('
|
|
43
|
+
.set('openai', chatGptResourceGeneratorStrategy)
|
|
44
|
+
.set('google', geminiResourceGeneratorStrategy)
|
|
45
|
+
.set('chatgpt', chatGptResourceGeneratorStrategy)
|
|
46
|
+
.set('gemini', geminiResourceGeneratorStrategy);
|
|
43
47
|
}
|
|
44
48
|
// #endregion
|
|
45
49
|
// #region Methods
|
|
@@ -97,6 +101,8 @@ class ResourceGenerator {
|
|
|
97
101
|
}
|
|
98
102
|
const chunks = utilities_1.ArrayExtensions.chunk(models, this._options.chunkSize);
|
|
99
103
|
const targetFilePath = this.getTargetFilePath(resource, locale);
|
|
104
|
+
// load existing target resource (if available) so partial results can be merged on failure
|
|
105
|
+
const existingModels = this.loadExistingModels(targetFilePath, resource);
|
|
100
106
|
this._logger.log(` Transcribing from ${(0, utilities_1.bold)(resource.locale)} to ${(0, utilities_1.bold)(locale)}`);
|
|
101
107
|
this._logger.log(` Splitting ${(0, utilities_1.bold)(models.length.toString())} models into ${(0, utilities_1.bold)(chunks.length.toString())} chunks`);
|
|
102
108
|
process_1.stdout.write(' Processing ');
|
|
@@ -112,17 +118,31 @@ class ResourceGenerator {
|
|
|
112
118
|
models = models.filter((x) => targetModels.every((y) => y.key !== x.key));
|
|
113
119
|
targetModels = m;
|
|
114
120
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
const allChunks = utilities_1.ArrayExtensions.chunk(models, this._options.chunkSize);
|
|
122
|
+
let processedChunkCount = 0;
|
|
123
|
+
for (const chunk of allChunks) {
|
|
124
|
+
try {
|
|
125
|
+
// eslint-disable-next-line no-await-in-loop
|
|
126
|
+
const x = await strategy.transcribe({
|
|
127
|
+
resource: resource,
|
|
128
|
+
models: chunk
|
|
129
|
+
}, locale);
|
|
130
|
+
// actually, gemini generates more models than the input, we have to check this here.
|
|
131
|
+
if (x.length !== chunk.length) {
|
|
132
|
+
this._logger.warn(` ${(0, utilities_1.yellow)('Warning:')} ${(0, utilities_1.bold)(chunk.length.toString())} models were expected, but ${(0, utilities_1.bold)(x.length.toString())} were generated.`);
|
|
133
|
+
}
|
|
134
|
+
targetModels.push(...x);
|
|
135
|
+
processedChunkCount++;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
process.stdout.write('\n');
|
|
139
|
+
this._logger.warn(` ${(0, utilities_1.yellow)('Chunk failed')} (${(0, utilities_1.bold)(processedChunkCount.toString())}/${(0, utilities_1.bold)(allChunks.length.toString())} chunks completed)`);
|
|
140
|
+
if (targetModels.length > 0) {
|
|
141
|
+
this._logger.log(` ${(0, utilities_1.bold)('Saving')} ${(0, utilities_1.bold)(targetModels.length.toString())} already translated models into target file...`);
|
|
142
|
+
this.mergeAndSave(existingModels, targetModels, targetFilePath, locale, resource);
|
|
143
|
+
}
|
|
144
|
+
throw error;
|
|
124
145
|
}
|
|
125
|
-
targetModels.push(...x);
|
|
126
146
|
}
|
|
127
147
|
process.stdout.write('\n');
|
|
128
148
|
this._logger.log(` ${(0, utilities_1.bold)(targetModels.length.toString())} models processed.`);
|
|
@@ -188,6 +208,69 @@ class ResourceGenerator {
|
|
|
188
208
|
this._logger.log(` ${(0, utilities_1.bold)('Dumping models to')} ${(0, utilities_1.dim)(tempFile.path)}`);
|
|
189
209
|
this._fileSystem.fileWriteAllJson(tempFile.path, models);
|
|
190
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Loads existing translated models from the target file, if it exists.
|
|
213
|
+
*
|
|
214
|
+
* @private
|
|
215
|
+
* @param targetFilePath The path to the target file.
|
|
216
|
+
* @param resource The source resource info (used to determine the file type).
|
|
217
|
+
* @returns The existing models, or an empty array if the file does not exist.
|
|
218
|
+
*/
|
|
219
|
+
loadExistingModels(targetFilePath, resource) {
|
|
220
|
+
try {
|
|
221
|
+
if (!this._fileSystem.fileExists(targetFilePath)) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
const targetResource = this._reader.scanDirectory(targetFilePath, resource.type).at(0);
|
|
225
|
+
if (!targetResource) {
|
|
226
|
+
return [];
|
|
227
|
+
}
|
|
228
|
+
return this._transformer.transform(targetResource);
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return [];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Merges newly translated models into the existing target models and writes the
|
|
236
|
+
* result to the original target file. New translations overwrite existing entries
|
|
237
|
+
* by key; keys that were not re-translated keep their previous value.
|
|
238
|
+
*
|
|
239
|
+
* @private
|
|
240
|
+
* @param existingModels The models already present in the target file.
|
|
241
|
+
* @param newModels The models that were successfully translated in this run.
|
|
242
|
+
* @param targetFilePath The target file path.
|
|
243
|
+
* @param locale The target locale.
|
|
244
|
+
* @param resource The source resource info.
|
|
245
|
+
*/
|
|
246
|
+
mergeAndSave(existingModels, newModels, targetFilePath, locale, resource) {
|
|
247
|
+
try {
|
|
248
|
+
const mergedMap = new Map();
|
|
249
|
+
// seed with existing translations
|
|
250
|
+
for (const model of existingModels) {
|
|
251
|
+
mergedMap.set(model.key, model);
|
|
252
|
+
}
|
|
253
|
+
// overlay with newly translated models (wins on key collision)
|
|
254
|
+
for (const model of newModels) {
|
|
255
|
+
mergedMap.set(model.key, model);
|
|
256
|
+
}
|
|
257
|
+
const mergedModels = Array.from(mergedMap.values());
|
|
258
|
+
const meta = {
|
|
259
|
+
name: this._fileSystem.pathGetFileName(targetFilePath),
|
|
260
|
+
path: targetFilePath,
|
|
261
|
+
locale: locale,
|
|
262
|
+
target: resource.type
|
|
263
|
+
};
|
|
264
|
+
const mergedResource = this._transformer.serialize(mergedModels, meta);
|
|
265
|
+
this._fileSystem.fileWriteAllText(targetFilePath, mergedResource.toString());
|
|
266
|
+
this._logger.log(` ${(0, utilities_1.bold)('Merged partial result into')} ${(0, utilities_1.dim)(utilities_1.Path.relative(process.cwd(), targetFilePath))}`);
|
|
267
|
+
this._logger.log(` ${(0, utilities_1.gray)(`${mergedModels.length} total keys (${newModels.length} newly translated, ${existingModels.length} existing).`)}`);
|
|
268
|
+
this.dumpResult(mergedModels);
|
|
269
|
+
}
|
|
270
|
+
catch (saveError) {
|
|
271
|
+
this._logger.warn(` ${(0, utilities_1.yellow)('Failed to save partial result:')} ${saveError instanceof Error ? saveError.message : String(saveError)}`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
191
274
|
}
|
|
192
275
|
exports.ResourceGenerator = ResourceGenerator;
|
|
193
276
|
//# sourceMappingURL=ResourceGenerator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResourceGenerator.js","sourceRoot":"","sources":["../../src/Generator/ResourceGenerator.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAElB,oEAAwK;AAExK,qCAAiC;AAGjC,0GAAoG;AACpG,wGAAkG;AAGlG,aAAa;AAEb;;;;GAIG;AACH,MAAa,iBAAiB;IAE1B,iBAAiB;IAEA,OAAO,CAAU;IACjB,WAAW,CAAc;IACzB,YAAY,CAAsB;IAClC,OAAO,CAAiB;IACxB,QAAQ,CAA4B;IACpC,WAAW,CAA0C;IAEtE,aAAa;IAEb,eAAe;IAEf;;;;;;;;OAQG;IACH,YAAmB,MAAe,EAAE,UAAuB,EAAE,WAAgC,EAAE,MAAsB,EAAE,OAAkC;QACrJ,IAAI,CAAC,OAAO,GAAG,MAAM,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CAAC,QAAQ,EAAE,CAAC,CAAC;YAC7E,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAA,gBAAI,EAAC,4BAA4B,CAAC,IAAI,IAAA,eAAG,EAAC,gBAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC;YACjH,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAA,gBAAI,EAAC,GAAG,YAAY,CAAC,MAAM,gBAAgB,SAAS,CAAC,MAAM,sBAAsB,cAAc,CAAC,MAAM,aAAa,CAAC,EAAE,CAAC,CAAC;YAE9I,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,SAAkB,EAAE,CAAC;YAC1B,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,IAAA,kBAAM,EAAC,gCAAgC,CAAC,IAAI,SAAS,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QAC7I,CAAC;IACL,CAAC;CAIJ;AArTD,8CAqTC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema (draft-07) describing a single resource model element.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Used with the Vercel AI SDK `jsonSchema()` helper so that
|
|
6
|
+
* `generateObject({ output: 'array', schema: jsonSchema(RESOURCE_MODEL_SCHEMA) })`
|
|
7
|
+
* produces an `Array<IResourceModel>`.
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export declare const RESOURCE_MODEL_SCHEMA: {
|
|
12
|
+
type: "object";
|
|
13
|
+
properties: {
|
|
14
|
+
key: {
|
|
15
|
+
type: "string";
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
value: {
|
|
19
|
+
type: "string";
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
comment: {
|
|
23
|
+
type: "string";
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
required: string[];
|
|
28
|
+
additionalProperties: false;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=ResourceModelSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceModelSchema.d.ts","sourceRoot":"","sources":["../../../src/Generator/Schemas/ResourceModelSchema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;CAkBjC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RESOURCE_MODEL_SCHEMA = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* JSON Schema (draft-07) describing a single resource model element.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Used with the Vercel AI SDK `jsonSchema()` helper so that
|
|
9
|
+
* `generateObject({ output: 'array', schema: jsonSchema(RESOURCE_MODEL_SCHEMA) })`
|
|
10
|
+
* produces an `Array<IResourceModel>`.
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
exports.RESOURCE_MODEL_SCHEMA = {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
key: {
|
|
18
|
+
type: 'string',
|
|
19
|
+
description: 'The key of the resource model. Must not be translated.'
|
|
20
|
+
},
|
|
21
|
+
value: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'The translated value of the resource model.'
|
|
24
|
+
},
|
|
25
|
+
comment: {
|
|
26
|
+
type: 'string',
|
|
27
|
+
description: 'The comment of the resource model.'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
required: ['key', 'value', 'comment'],
|
|
31
|
+
additionalProperties: false
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=ResourceModelSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResourceModelSchema.js","sourceRoot":"","sources":["../../../src/Generator/Schemas/ResourceModelSchema.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACU,QAAA,qBAAqB,GAAG;IACjC,IAAI,EAAE,QAAiB;IACvB,UAAU,EAAE;QACR,GAAG,EAAE;YACD,IAAI,EAAE,QAAiB;YACvB,WAAW,EAAE,wDAAwD;SACxE;QACD,KAAK,EAAE;YACH,IAAI,EAAE,QAAiB;YACvB,WAAW,EAAE,6CAA6C;SAC7D;QACD,OAAO,EAAE;YACL,IAAI,EAAE,QAAiB;YACvB,WAAW,EAAE,oCAAoC;SACpD;KACJ;IACD,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,CAAC;IACrC,oBAAoB,EAAE,KAAc;CACvC,CAAC"}
|
|
@@ -2,17 +2,17 @@ import type { IFileSystem } from '@breadstone-infrastructure/utilities';
|
|
|
2
2
|
import { BaseResourceGeneratorStrategy } from './Abstracts/BaseResourceGeneratorStrategy.js';
|
|
3
3
|
import type { IResourceGeneratorStrategyConfig } from './Interfaces/IResourceGeneratorStrategyConfig.js';
|
|
4
4
|
/**
|
|
5
|
-
* Service to handle AI-based translations using
|
|
5
|
+
* Service to handle AI-based translations using ChatGPT
|
|
6
6
|
*
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
9
|
export declare class ChatGptResourceGeneratorStrategy extends BaseResourceGeneratorStrategy {
|
|
10
|
-
private readonly
|
|
10
|
+
private readonly _openAiProvider;
|
|
11
11
|
/**
|
|
12
|
-
* Constructs a new instance of the `ChatGptResourceGeneratorStrategy` class
|
|
12
|
+
* Constructs a new instance of the `{@link ChatGptResourceGeneratorStrategy}` class
|
|
13
13
|
*
|
|
14
|
-
* @param fileSystem The service to handle file operations
|
|
15
|
-
* @param options The configuration options for the strategy
|
|
14
|
+
* @param fileSystem The service to handle file operations
|
|
15
|
+
* @param options The configuration options for the strategy
|
|
16
16
|
*/
|
|
17
17
|
constructor(fileSystem: IFileSystem, options: IResourceGeneratorStrategyConfig);
|
|
18
18
|
/**
|
|
@@ -20,7 +20,7 @@ export declare class ChatGptResourceGeneratorStrategy extends BaseResourceGenera
|
|
|
20
20
|
*
|
|
21
21
|
* @protected
|
|
22
22
|
* @override
|
|
23
|
-
* @param prompt The prompt to translate
|
|
23
|
+
* @param prompt The prompt to translate
|
|
24
24
|
* @returns The translated resource
|
|
25
25
|
*/
|
|
26
26
|
protected processResource(prompt: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatGptResourceGeneratorStrategy.d.ts","sourceRoot":"","sources":["../../../src/Generator/Strategies/ChatGptResourceGeneratorStrategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChatGptResourceGeneratorStrategy.d.ts","sourceRoot":"","sources":["../../../src/Generator/Strategies/ChatGptResourceGeneratorStrategy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAIxE,OAAO,EAAE,6BAA6B,EAAE,MAAM,8CAA8C,CAAC;AAC7F,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,kDAAkD,CAAC;AAIzG;;;;GAIG;AACH,qBAAa,gCAAiC,SAAQ,6BAA6B;IAI/E,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkC;IAMlE;;;;;OAKG;gBACgB,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,gCAAgC;IAYrF;;;;;;;OAOG;cACsB,eAAe,CAAC,MAAM,EAAE;QAC7C,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;KACnB,GAAG,OAAO,CAAC,MAAM,CAAC;CA0BtB"}
|
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// #region Imports
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
4
|
exports.ChatGptResourceGeneratorStrategy = void 0;
|
|
8
|
-
const openai_1 =
|
|
5
|
+
const openai_1 = require("@ai-sdk/openai");
|
|
6
|
+
const ai_1 = require("ai");
|
|
7
|
+
const ResourceModelSchema_js_1 = require("../Schemas/ResourceModelSchema.js");
|
|
9
8
|
const BaseResourceGeneratorStrategy_js_1 = require("./Abstracts/BaseResourceGeneratorStrategy.js");
|
|
10
9
|
// #endregion
|
|
11
10
|
/**
|
|
12
|
-
* Service to handle AI-based translations using
|
|
11
|
+
* Service to handle AI-based translations using ChatGPT
|
|
13
12
|
*
|
|
14
13
|
* @public
|
|
15
14
|
*/
|
|
16
15
|
class ChatGptResourceGeneratorStrategy extends BaseResourceGeneratorStrategy_js_1.BaseResourceGeneratorStrategy {
|
|
17
16
|
// #region Fields
|
|
18
|
-
|
|
17
|
+
_openAiProvider;
|
|
19
18
|
// #endregion
|
|
20
19
|
// #region Ctor
|
|
21
20
|
/**
|
|
22
|
-
* Constructs a new instance of the `ChatGptResourceGeneratorStrategy` class
|
|
21
|
+
* Constructs a new instance of the `{@link ChatGptResourceGeneratorStrategy}` class
|
|
23
22
|
*
|
|
24
|
-
* @param fileSystem The service to handle file operations
|
|
25
|
-
* @param options The configuration options for the strategy
|
|
23
|
+
* @param fileSystem The service to handle file operations
|
|
24
|
+
* @param options The configuration options for the strategy
|
|
26
25
|
*/
|
|
27
26
|
constructor(fileSystem, options) {
|
|
28
27
|
super(fileSystem, options);
|
|
29
|
-
this.
|
|
28
|
+
this._openAiProvider = (0, openai_1.createOpenAI)({
|
|
29
|
+
apiKey: this.config.apiKey
|
|
30
|
+
});
|
|
30
31
|
}
|
|
31
32
|
// #endregion
|
|
32
33
|
// #region Methods
|
|
@@ -35,24 +36,30 @@ class ChatGptResourceGeneratorStrategy extends BaseResourceGeneratorStrategy_js_
|
|
|
35
36
|
*
|
|
36
37
|
* @protected
|
|
37
38
|
* @override
|
|
38
|
-
* @param prompt The prompt to translate
|
|
39
|
+
* @param prompt The prompt to translate
|
|
39
40
|
* @returns The translated resource
|
|
40
41
|
*/
|
|
41
42
|
async processResource(prompt) {
|
|
42
43
|
try {
|
|
43
|
-
const
|
|
44
|
-
model: this.config.model,
|
|
44
|
+
const result = await (0, ai_1.generateText)({
|
|
45
|
+
model: this._openAiProvider(this.config.model),
|
|
46
|
+
output: ai_1.Output.array({
|
|
47
|
+
element: (0, ai_1.jsonSchema)(ResourceModelSchema_js_1.RESOURCE_MODEL_SCHEMA),
|
|
48
|
+
name: 'ResourceModel',
|
|
49
|
+
description: 'A translated key-value resource model with key, value, and comment.'
|
|
50
|
+
}),
|
|
51
|
+
system: prompt.system,
|
|
45
52
|
prompt: `
|
|
46
|
-
${prompt.
|
|
53
|
+
${prompt.assistant}
|
|
54
|
+
${prompt.content}
|
|
47
55
|
${Array.isArray(this.config.instructions) ? this.config.instructions.join('\n') : this.config.instructions}
|
|
48
56
|
`.trim(),
|
|
49
|
-
temperature: this.config.temperature
|
|
50
|
-
stream: false
|
|
57
|
+
temperature: this.config.temperature
|
|
51
58
|
});
|
|
52
|
-
return
|
|
59
|
+
return JSON.stringify(result.output);
|
|
53
60
|
}
|
|
54
61
|
catch (error) {
|
|
55
|
-
throw new Error(`[ChatGptResourceGeneratorStrategy]: ${error.message}`);
|
|
62
|
+
throw new Error(`[ChatGptResourceGeneratorStrategy]: ${error instanceof Error ? error.message : String(error)}`);
|
|
56
63
|
}
|
|
57
64
|
}
|
|
58
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatGptResourceGeneratorStrategy.js","sourceRoot":"","sources":["../../../src/Generator/Strategies/ChatGptResourceGeneratorStrategy.ts"],"names":[],"mappings":";AAAA,kBAAkB
|
|
1
|
+
{"version":3,"file":"ChatGptResourceGeneratorStrategy.js","sourceRoot":"","sources":["../../../src/Generator/Strategies/ChatGptResourceGeneratorStrategy.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAElB,2CAA8C;AAG9C,2BAAsD;AACtD,8EAA0E;AAC1E,mGAA6F;AAG7F,aAAa;AAEb;;;;GAIG;AACH,MAAa,gCAAiC,SAAQ,gEAA6B;IAE/E,iBAAiB;IAEA,eAAe,CAAkC;IAElE,aAAa;IAEb,eAAe;IAEf;;;;;OAKG;IACH,YAAmB,UAAuB,EAAE,OAAyC;QACjF,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE3B,IAAI,CAAC,eAAe,GAAG,IAAA,qBAAY,EAAC;YAChC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;SAC7B,CAAC,CAAC;IACP,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;;;OAOG;IACgB,KAAK,CAAC,eAAe,CAAC,MAIxC;QACG,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAA,iBAAY,EAAC;gBAC9B,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC9C,MAAM,EAAE,WAAM,CAAC,KAAK,CAAC;oBACjB,OAAO,EAAE,IAAA,eAAU,EAAiB,8CAAqB,CAAC;oBAC1D,IAAI,EAAE,eAAe;oBACrB,WAAW,EAAE,qEAAqE;iBACrF,CAAC;gBACF,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM,EAAE;sBACF,MAAM,CAAC,SAAS;sBAChB,MAAM,CAAC,OAAO;sBACd,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY;iBAC7G,CAAC,IAAI,EAAE;gBACR,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;aACvC,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,uCAAuC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACrH,CAAC;IACL,CAAC;CAIJ;AAlED,4EAkEC"}
|
|
@@ -7,21 +7,20 @@ import type { IResourceGeneratorStrategyConfig } from './Interfaces/IResourceGen
|
|
|
7
7
|
* @public
|
|
8
8
|
*/
|
|
9
9
|
export declare class GeminiResourceGeneratorStrategy extends BaseResourceGeneratorStrategy {
|
|
10
|
-
private readonly
|
|
11
|
-
private readonly _model;
|
|
10
|
+
private readonly _googleProvider;
|
|
12
11
|
/**
|
|
13
|
-
* Constructs a new instance of the `GeminiResourceGeneratorStrategy` class
|
|
12
|
+
* Constructs a new instance of the `{@link GeminiResourceGeneratorStrategy}` class
|
|
14
13
|
*
|
|
15
|
-
* @param fileSystem The service to handle file operations
|
|
16
|
-
* @param options The configuration options for the strategy
|
|
14
|
+
* @param fileSystem The service to handle file operations
|
|
15
|
+
* @param options The configuration options for the strategy
|
|
17
16
|
*/
|
|
18
17
|
constructor(fileSystem: IFileSystem, options: IResourceGeneratorStrategyConfig);
|
|
19
18
|
/**
|
|
20
|
-
* Translates a resource to the specified locale
|
|
19
|
+
* Translates a resource to the specified locale
|
|
21
20
|
*
|
|
22
21
|
* @protected
|
|
23
22
|
* @override
|
|
24
|
-
* @param prompt The prompt to translate
|
|
23
|
+
* @param prompt The prompt to translate
|
|
25
24
|
* @returns The translated resource
|
|
26
25
|
*/
|
|
27
26
|
protected processResource(prompt: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiResourceGeneratorStrategy.d.ts","sourceRoot":"","sources":["../../../src/Generator/Strategies/GeminiResourceGeneratorStrategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GeminiResourceGeneratorStrategy.d.ts","sourceRoot":"","sources":["../../../src/Generator/Strategies/GeminiResourceGeneratorStrategy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AAIxE,OAAO,EAAE,6BAA6B,EAAE,MAAM,8CAA8C,CAAC;AAC7F,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,kDAAkD,CAAC;AAIzG;;;;GAIG;AACH,qBAAa,+BAAgC,SAAQ,6BAA6B;IAI9E,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA8C;IAM9E;;;;;OAKG;gBACgB,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,gCAAgC;IAYrF;;;;;;;OAOG;cACsB,eAAe,CAAC,MAAM,EAAE;QAC7C,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;KACnB,GAAG,OAAO,CAAC,MAAM,CAAC;CA6BtB"}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// #region Imports
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.GeminiResourceGeneratorStrategy = void 0;
|
|
5
|
-
const
|
|
5
|
+
const google_1 = require("@ai-sdk/google");
|
|
6
|
+
const ai_1 = require("ai");
|
|
7
|
+
const ResourceModelSchema_js_1 = require("../Schemas/ResourceModelSchema.js");
|
|
6
8
|
const BaseResourceGeneratorStrategy_js_1 = require("./Abstracts/BaseResourceGeneratorStrategy.js");
|
|
7
9
|
// #endregion
|
|
8
10
|
/**
|
|
@@ -12,82 +14,55 @@ const BaseResourceGeneratorStrategy_js_1 = require("./Abstracts/BaseResourceGene
|
|
|
12
14
|
*/
|
|
13
15
|
class GeminiResourceGeneratorStrategy extends BaseResourceGeneratorStrategy_js_1.BaseResourceGeneratorStrategy {
|
|
14
16
|
// #region Fields
|
|
15
|
-
|
|
16
|
-
_model;
|
|
17
|
+
_googleProvider;
|
|
17
18
|
// #endregion
|
|
18
19
|
// #region Constructor
|
|
19
20
|
/**
|
|
20
|
-
* Constructs a new instance of the `GeminiResourceGeneratorStrategy` class
|
|
21
|
+
* Constructs a new instance of the `{@link GeminiResourceGeneratorStrategy}` class
|
|
21
22
|
*
|
|
22
|
-
* @param fileSystem The service to handle file operations
|
|
23
|
-
* @param options The configuration options for the strategy
|
|
23
|
+
* @param fileSystem The service to handle file operations
|
|
24
|
+
* @param options The configuration options for the strategy
|
|
24
25
|
*/
|
|
25
26
|
constructor(fileSystem, options) {
|
|
26
27
|
super(fileSystem, options);
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
model: this.config.model,
|
|
30
|
-
generationConfig: {
|
|
31
|
-
temperature: this.config.temperature,
|
|
32
|
-
responseMimeType: 'application/json',
|
|
33
|
-
responseSchema: {
|
|
34
|
-
type: generative_ai_1.SchemaType.ARRAY,
|
|
35
|
-
items: {
|
|
36
|
-
type: generative_ai_1.SchemaType.OBJECT,
|
|
37
|
-
properties: {
|
|
38
|
-
key: {
|
|
39
|
-
type: generative_ai_1.SchemaType.STRING,
|
|
40
|
-
description: 'The key of the transform model'
|
|
41
|
-
},
|
|
42
|
-
value: {
|
|
43
|
-
type: generative_ai_1.SchemaType.STRING,
|
|
44
|
-
description: 'The value of the transform model'
|
|
45
|
-
},
|
|
46
|
-
comment: {
|
|
47
|
-
type: generative_ai_1.SchemaType.STRING,
|
|
48
|
-
description: 'The comment of the transform model'
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
required: ['key', 'value', 'comment']
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
28
|
+
this._googleProvider = (0, google_1.createGoogleGenerativeAI)({
|
|
29
|
+
apiKey: this.config.apiKey
|
|
55
30
|
});
|
|
56
31
|
}
|
|
57
32
|
// #endregion
|
|
58
33
|
// #region Methods
|
|
59
34
|
/**
|
|
60
|
-
* Translates a resource to the specified locale
|
|
35
|
+
* Translates a resource to the specified locale
|
|
61
36
|
*
|
|
62
37
|
* @protected
|
|
63
38
|
* @override
|
|
64
|
-
* @param prompt The prompt to translate
|
|
39
|
+
* @param prompt The prompt to translate
|
|
65
40
|
* @returns The translated resource
|
|
66
41
|
*/
|
|
67
42
|
async processResource(prompt) {
|
|
68
43
|
try {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
44
|
+
const result = await (0, ai_1.generateText)({
|
|
45
|
+
model: this._googleProvider(this.config.model),
|
|
46
|
+
providerOptions: {
|
|
47
|
+
google: { structuredOutputs: true }
|
|
48
|
+
},
|
|
49
|
+
output: ai_1.Output.array({
|
|
50
|
+
element: (0, ai_1.jsonSchema)(ResourceModelSchema_js_1.RESOURCE_MODEL_SCHEMA),
|
|
51
|
+
name: 'ResourceModel',
|
|
52
|
+
description: 'A translated key-value resource model with key, value, and comment.'
|
|
53
|
+
}),
|
|
54
|
+
system: prompt.system,
|
|
55
|
+
prompt: `
|
|
56
|
+
${prompt.assistant}
|
|
57
|
+
${prompt.content}
|
|
58
|
+
${Array.isArray(this.config.instructions) ? this.config.instructions.join('\n') : this.config.instructions}
|
|
72
59
|
`.trim(),
|
|
73
|
-
|
|
74
|
-
{
|
|
75
|
-
role: 'assistant',
|
|
76
|
-
parts: [
|
|
77
|
-
{
|
|
78
|
-
text: `
|
|
79
|
-
${prompt.assistant} ${prompt.content}
|
|
80
|
-
${Array.isArray(this.config.instructions) ? this.config.instructions.join('\n') : this.config.instructions}
|
|
81
|
-
`.trim()
|
|
82
|
-
}
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
]
|
|
60
|
+
temperature: this.config.temperature,
|
|
86
61
|
});
|
|
87
|
-
return
|
|
62
|
+
return JSON.stringify(result.output);
|
|
88
63
|
}
|
|
89
64
|
catch (error) {
|
|
90
|
-
throw new Error(`[GeminiResourceGeneratorStrategy]: ${error.message}`);
|
|
65
|
+
throw new Error(`[GeminiResourceGeneratorStrategy]: ${error instanceof Error ? error.message : String(error)}`);
|
|
91
66
|
}
|
|
92
67
|
}
|
|
93
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GeminiResourceGeneratorStrategy.js","sourceRoot":"","sources":["../../../src/Generator/Strategies/GeminiResourceGeneratorStrategy.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;
|
|
1
|
+
{"version":3,"file":"GeminiResourceGeneratorStrategy.js","sourceRoot":"","sources":["../../../src/Generator/Strategies/GeminiResourceGeneratorStrategy.ts"],"names":[],"mappings":";AAAA,kBAAkB;;;AAElB,2CAA0D;AAG1D,2BAAsD;AACtD,8EAA0E;AAC1E,mGAA6F;AAG7F,aAAa;AAEb;;;;GAIG;AACH,MAAa,+BAAgC,SAAQ,gEAA6B;IAE9E,iBAAiB;IAEA,eAAe,CAA8C;IAE9E,aAAa;IAEb,sBAAsB;IAEtB;;;;;OAKG;IACH,YAAmB,UAAuB,EAAE,OAAyC;QACjF,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE3B,IAAI,CAAC,eAAe,GAAG,IAAA,iCAAwB,EAAC;YAC5C,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;SAC7B,CAAC,CAAC;IACP,CAAC;IAED,aAAa;IAEb,kBAAkB;IAElB;;;;;;;OAOG;IACgB,KAAK,CAAC,eAAe,CAAC,MAIxC;QACG,IAAI,CAAC;YACD,MAAM,MAAM,GAAG,MAAM,IAAA,iBAAY,EAAC;gBAC9B,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC9C,eAAe,EAAE;oBACb,MAAM,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE;iBACtC;gBACD,MAAM,EAAE,WAAM,CAAC,KAAK,CAAC;oBACjB,OAAO,EAAE,IAAA,eAAU,EAAiB,8CAAqB,CAAC;oBAC1D,IAAI,EAAE,eAAe;oBACrB,WAAW,EAAE,qEAAqE;iBACrF,CAAC;gBACF,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM,EAAE;sBACF,MAAM,CAAC,SAAS;sBAChB,MAAM,CAAC,OAAO;sBACd,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY;iBAC7G,CAAC,IAAI,EAAE;gBACR,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;aACvC,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACzC,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,sCAAsC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACpH,CAAC;IACL,CAAC;CAIJ;AArED,0EAqEC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breadstone-tools/localizator-ai",
|
|
3
3
|
"description": "Localizator ai library",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.230",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "andre.wehlert <awehlert@breadstone.de> (https://www.breadstone.de)",
|
|
7
7
|
"repository": {
|
|
@@ -13,10 +13,11 @@
|
|
|
13
13
|
"module": "./Index.js",
|
|
14
14
|
"types": "./Index.d.ts",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"
|
|
20
|
-
"
|
|
16
|
+
"@ai-sdk/google": "3.0.49",
|
|
17
|
+
"@ai-sdk/openai": "3.0.45",
|
|
18
|
+
"@breadstone-infrastructure/utilities": "^0.0.230",
|
|
19
|
+
"@breadstone-tools/localizator-core": "^0.0.230",
|
|
20
|
+
"ai": "6.0.124",
|
|
21
|
+
"cheerio": "^1.2.0"
|
|
21
22
|
}
|
|
22
23
|
}
|