@terai/translator 0.0.0-dev-20240302221955 → 0.0.0-dev-20240607213452
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.
|
@@ -9,14 +9,14 @@ var createChatGptTranslator = (openaiOptions) => {
|
|
|
9
9
|
}) => {
|
|
10
10
|
const messagesJson = JSON.stringify(dictionary);
|
|
11
11
|
const response = await openai.chat.completions.create({
|
|
12
|
-
model: "gpt-3.5-turbo",
|
|
12
|
+
model: "gpt-3.5-turbo-0125",
|
|
13
13
|
messages: [
|
|
14
14
|
{
|
|
15
15
|
role: "system",
|
|
16
16
|
content: [
|
|
17
|
-
|
|
17
|
+
// 'Act like a professional translator',
|
|
18
18
|
`You will be provided with a JSON in locale: ${projectLocale}, and your task is to translate it to locale: ${locale}.`,
|
|
19
|
-
|
|
19
|
+
// 'Keep the same structure and keys, just translate the values.',
|
|
20
20
|
'Do not translate any escaped characters or "${var}" ocurrences, just keep them as they are'
|
|
21
21
|
].join(".\n")
|
|
22
22
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/translators/chat-gpt.ts","../../src/translators/google-cloud.ts"],"names":[],"mappings":";AACA,OAAO,YAAoC;AAKpC,IAAM,0BAA0B,CAAC,kBAAiC;AACxE,QAAM,SAAS,IAAI,OAAO,aAAa;AAEvC,QAAM,aAAyB,OAAO;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,EACD,MAAM;AACL,UAAM,eAAe,KAAK,UAAU,UAAU;AAE9C,UAAM,WAAW,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MACrD,OAAO;AAAA,MACP,UAAU;AAAA,QACT;AAAA,UACC,MAAM;AAAA,UACN,SAAS;AAAA
|
|
1
|
+
{"version":3,"sources":["../../src/translators/chat-gpt.ts","../../src/translators/google-cloud.ts"],"names":[],"mappings":";AACA,OAAO,YAAoC;AAKpC,IAAM,0BAA0B,CAAC,kBAAiC;AACxE,QAAM,SAAS,IAAI,OAAO,aAAa;AAEvC,QAAM,aAAyB,OAAO;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,EACD,MAAM;AACL,UAAM,eAAe,KAAK,UAAU,UAAU;AAE9C,UAAM,WAAW,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MACrD,OAAO;AAAA,MACP,UAAU;AAAA,QACT;AAAA,UACC,MAAM;AAAA,UACN,SAAS;AAAA;AAAA,YAER,+CAA+C,aAAa,iDAAiD,MAAM;AAAA;AAAA,YAEnH;AAAA,UACD,EAAE,KAAK,KAAK;AAAA,QACb;AAAA,QACA;AAAA,UACC,MAAM;AAAA,UACN,SAAS;AAAA,QACV;AAAA,MACD;AAAA,MACA,aAAa;AAAA,MACb,mBAAmB;AAAA,MACnB,kBAAkB;AAAA,IACnB,CAAC;AAED,WAAO,KAAK;AAAA,MACX,UAAU,UAAU,CAAC,GAAG,SAAS,WAAW;AAAA,IAC7C;AAAA,EACD;AAEA,SAAO;AACR;;;AC3CA,SAAS,UAAU;AAKZ,IAAM,8BAA8B,CAAC,YAAgC;AAC3E,QAAM,YAAY,IAAI,GAAG,UAAU,OAAO;AAE1C,QAAM,aAAyB,OAAO,EAAE,YAAY,OAAO,MAAM;AAChE,UAAM,mBAA+B,CAAC;AAEtC,UAAM,QAAQ;AAAA,MACb,OAAO,KAAK,UAAU,EAAE,IAAI,OAAO,QAAQ;AAC1C,cAAM,QAAQ,WAAW,GAAG;AAE5B,cAAM,CAAC,WAAW,IAAI,MAAM,UAAU,UAAU,OAAO,MAAM;AAE7D,yBAAiB,GAAG,IAAI;AAAA,MACzB,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,EACR;AAEA,SAAO;AACR","sourcesContent":["// Dependencies\nimport OpenAI, { type ClientOptions } from 'openai'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createChatGptTranslator = (openaiOptions: ClientOptions) => {\n\tconst openai = new OpenAI(openaiOptions)\n\n\tconst translator: Translator = async ({\n\t\tdictionary,\n\t\tprojectLocale,\n\t\tlocale\n\t}) => {\n\t\tconst messagesJson = JSON.stringify(dictionary)\n\n\t\tconst response = await openai.chat.completions.create({\n\t\t\tmodel: 'gpt-3.5-turbo-0125',\n\t\t\tmessages: [\n\t\t\t\t{\n\t\t\t\t\trole: 'system',\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t// 'Act like a professional translator',\n\t\t\t\t\t\t`You will be provided with a JSON in locale: ${projectLocale}, and your task is to translate it to locale: ${locale}.`,\n\t\t\t\t\t\t// 'Keep the same structure and keys, just translate the values.',\n\t\t\t\t\t\t'Do not translate any escaped characters or \"${var}\" ocurrences, just keep them as they are'\n\t\t\t\t\t].join('.\\n')\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\trole: 'user',\n\t\t\t\t\tcontent: messagesJson\n\t\t\t\t}\n\t\t\t],\n\t\t\ttemperature: 0.4,\n\t\t\tfrequency_penalty: -2.0,\n\t\t\tpresence_penalty: -2.0\n\t\t})\n\n\t\treturn JSON.parse(\n\t\t\tresponse?.choices?.[0]?.message?.content || '{}'\n\t\t) as Dictionary\n\t}\n\n\treturn translator\n}\n","// Dependencies\nimport { v2 } from '@google-cloud/translate'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createGoogleCloudTranslator = (options: v2.TranslateConfig) => {\n\tconst translate = new v2.Translate(options)\n\n\tconst translator: Translator = async ({ dictionary, locale }) => {\n\t\tconst translatedOutput: Dictionary = {}\n\n\t\tawait Promise.all(\n\t\t\tObject.keys(dictionary).map(async (key) => {\n\t\t\t\tconst value = dictionary[key]\n\n\t\t\t\tconst [translation] = await translate.translate(value, locale)\n\n\t\t\t\ttranslatedOutput[key] = translation\n\t\t\t})\n\t\t)\n\n\t\treturn translatedOutput\n\t}\n\n\treturn translator\n}\n"]}
|
|
@@ -9,14 +9,14 @@ var createChatGptTranslator = (openaiOptions) => {
|
|
|
9
9
|
}) => {
|
|
10
10
|
const messagesJson = JSON.stringify(dictionary);
|
|
11
11
|
const response = await openai.chat.completions.create({
|
|
12
|
-
model: "gpt-3.5-turbo",
|
|
12
|
+
model: "gpt-3.5-turbo-0125",
|
|
13
13
|
messages: [
|
|
14
14
|
{
|
|
15
15
|
role: "system",
|
|
16
16
|
content: [
|
|
17
|
-
|
|
17
|
+
// 'Act like a professional translator',
|
|
18
18
|
`You will be provided with a JSON in locale: ${projectLocale}, and your task is to translate it to locale: ${locale}.`,
|
|
19
|
-
|
|
19
|
+
// 'Keep the same structure and keys, just translate the values.',
|
|
20
20
|
'Do not translate any escaped characters or "${var}" ocurrences, just keep them as they are'
|
|
21
21
|
].join(".\n")
|
|
22
22
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/translators/chat-gpt.ts","../../src/translators/google-cloud.ts"],"sourcesContent":["// Dependencies\nimport OpenAI, { type ClientOptions } from 'openai'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createChatGptTranslator = (openaiOptions: ClientOptions) => {\n\tconst openai = new OpenAI(openaiOptions)\n\n\tconst translator: Translator = async ({\n\t\tdictionary,\n\t\tprojectLocale,\n\t\tlocale\n\t}) => {\n\t\tconst messagesJson = JSON.stringify(dictionary)\n\n\t\tconst response = await openai.chat.completions.create({\n\t\t\tmodel: 'gpt-3.5-turbo',\n\t\t\tmessages: [\n\t\t\t\t{\n\t\t\t\t\trole: 'system',\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t'Act like a professional translator',\n\t\t\t\t\t\t`You will be provided with a JSON in locale: ${projectLocale}, and your task is to translate it to locale: ${locale}.`,\n\t\t\t\t\t\t'Keep the same structure and keys, just translate the values.',\n\t\t\t\t\t\t'Do not translate any escaped characters or \"${var}\" ocurrences, just keep them as they are'\n\t\t\t\t\t].join('.\\n')\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\trole: 'user',\n\t\t\t\t\tcontent: messagesJson\n\t\t\t\t}\n\t\t\t],\n\t\t\ttemperature: 0.4,\n\t\t\tfrequency_penalty: -2.0,\n\t\t\tpresence_penalty: -2.0\n\t\t})\n\n\t\treturn JSON.parse(\n\t\t\tresponse?.choices?.[0]?.message?.content || '{}'\n\t\t) as Dictionary\n\t}\n\n\treturn translator\n}\n","// Dependencies\nimport { v2 } from '@google-cloud/translate'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createGoogleCloudTranslator = (options: v2.TranslateConfig) => {\n\tconst translate = new v2.Translate(options)\n\n\tconst translator: Translator = async ({ dictionary, locale }) => {\n\t\tconst translatedOutput: Dictionary = {}\n\n\t\tawait Promise.all(\n\t\t\tObject.keys(dictionary).map(async (key) => {\n\t\t\t\tconst value = dictionary[key]\n\n\t\t\t\tconst [translation] = await translate.translate(value, locale)\n\n\t\t\t\ttranslatedOutput[key] = translation\n\t\t\t})\n\t\t)\n\n\t\treturn translatedOutput\n\t}\n\n\treturn translator\n}\n"],"mappings":";AACA,OAAO,YAAoC;AAKpC,IAAM,0BAA0B,CAAC,kBAAiC;AACxE,QAAM,SAAS,IAAI,OAAO,aAAa;AAEvC,QAAM,aAAyB,OAAO;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,EACD,MAAM;AACL,UAAM,eAAe,KAAK,UAAU,UAAU;AAE9C,UAAM,WAAW,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MACrD,OAAO;AAAA,MACP,UAAU;AAAA,QACT;AAAA,UACC,MAAM;AAAA,UACN,SAAS;AAAA
|
|
1
|
+
{"version":3,"sources":["../../src/translators/chat-gpt.ts","../../src/translators/google-cloud.ts"],"sourcesContent":["// Dependencies\nimport OpenAI, { type ClientOptions } from 'openai'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createChatGptTranslator = (openaiOptions: ClientOptions) => {\n\tconst openai = new OpenAI(openaiOptions)\n\n\tconst translator: Translator = async ({\n\t\tdictionary,\n\t\tprojectLocale,\n\t\tlocale\n\t}) => {\n\t\tconst messagesJson = JSON.stringify(dictionary)\n\n\t\tconst response = await openai.chat.completions.create({\n\t\t\tmodel: 'gpt-3.5-turbo-0125',\n\t\t\tmessages: [\n\t\t\t\t{\n\t\t\t\t\trole: 'system',\n\t\t\t\t\tcontent: [\n\t\t\t\t\t\t// 'Act like a professional translator',\n\t\t\t\t\t\t`You will be provided with a JSON in locale: ${projectLocale}, and your task is to translate it to locale: ${locale}.`,\n\t\t\t\t\t\t// 'Keep the same structure and keys, just translate the values.',\n\t\t\t\t\t\t'Do not translate any escaped characters or \"${var}\" ocurrences, just keep them as they are'\n\t\t\t\t\t].join('.\\n')\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\trole: 'user',\n\t\t\t\t\tcontent: messagesJson\n\t\t\t\t}\n\t\t\t],\n\t\t\ttemperature: 0.4,\n\t\t\tfrequency_penalty: -2.0,\n\t\t\tpresence_penalty: -2.0\n\t\t})\n\n\t\treturn JSON.parse(\n\t\t\tresponse?.choices?.[0]?.message?.content || '{}'\n\t\t) as Dictionary\n\t}\n\n\treturn translator\n}\n","// Dependencies\nimport { v2 } from '@google-cloud/translate'\n\n// Types\nimport type { Dictionary, Translator } from '@terai/types'\n\nexport const createGoogleCloudTranslator = (options: v2.TranslateConfig) => {\n\tconst translate = new v2.Translate(options)\n\n\tconst translator: Translator = async ({ dictionary, locale }) => {\n\t\tconst translatedOutput: Dictionary = {}\n\n\t\tawait Promise.all(\n\t\t\tObject.keys(dictionary).map(async (key) => {\n\t\t\t\tconst value = dictionary[key]\n\n\t\t\t\tconst [translation] = await translate.translate(value, locale)\n\n\t\t\t\ttranslatedOutput[key] = translation\n\t\t\t})\n\t\t)\n\n\t\treturn translatedOutput\n\t}\n\n\treturn translator\n}\n"],"mappings":";AACA,OAAO,YAAoC;AAKpC,IAAM,0BAA0B,CAAC,kBAAiC;AACxE,QAAM,SAAS,IAAI,OAAO,aAAa;AAEvC,QAAM,aAAyB,OAAO;AAAA,IACrC;AAAA,IACA;AAAA,IACA;AAAA,EACD,MAAM;AACL,UAAM,eAAe,KAAK,UAAU,UAAU;AAE9C,UAAM,WAAW,MAAM,OAAO,KAAK,YAAY,OAAO;AAAA,MACrD,OAAO;AAAA,MACP,UAAU;AAAA,QACT;AAAA,UACC,MAAM;AAAA,UACN,SAAS;AAAA;AAAA,YAER,+CAA+C,aAAa,iDAAiD,MAAM;AAAA;AAAA,YAEnH;AAAA,UACD,EAAE,KAAK,KAAK;AAAA,QACb;AAAA,QACA;AAAA,UACC,MAAM;AAAA,UACN,SAAS;AAAA,QACV;AAAA,MACD;AAAA,MACA,aAAa;AAAA,MACb,mBAAmB;AAAA,MACnB,kBAAkB;AAAA,IACnB,CAAC;AAED,WAAO,KAAK;AAAA,MACX,UAAU,UAAU,CAAC,GAAG,SAAS,WAAW;AAAA,IAC7C;AAAA,EACD;AAEA,SAAO;AACR;;;AC3CA,SAAS,UAAU;AAKZ,IAAM,8BAA8B,CAAC,YAAgC;AAC3E,QAAM,YAAY,IAAI,GAAG,UAAU,OAAO;AAE1C,QAAM,aAAyB,OAAO,EAAE,YAAY,OAAO,MAAM;AAChE,UAAM,mBAA+B,CAAC;AAEtC,UAAM,QAAQ;AAAA,MACb,OAAO,KAAK,UAAU,EAAE,IAAI,OAAO,QAAQ;AAC1C,cAAM,QAAQ,WAAW,GAAG;AAE5B,cAAM,CAAC,WAAW,IAAI,MAAM,UAAU,UAAU,OAAO,MAAM;AAE7D,yBAAiB,GAAG,IAAI;AAAA,MACzB,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,EACR;AAEA,SAAO;AACR;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terai/translator",
|
|
3
3
|
"description": "terai core translator",
|
|
4
|
-
"version": "0.0.0-dev-
|
|
4
|
+
"version": "0.0.0-dev-20240607213452",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"openai": "^4"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@terai/runtime": "0.0.0-dev-
|
|
34
|
-
"@terai/types": "0.0.0-dev-
|
|
35
|
-
"@terai/utils": "0.0.0-dev-
|
|
33
|
+
"@terai/runtime": "0.0.0-dev-20240607213452",
|
|
34
|
+
"@terai/types": "0.0.0-dev-20240607213452",
|
|
35
|
+
"@terai/utils": "0.0.0-dev-20240607213452"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"dev": "tsup --format=esm,cjs --no-dts --watch",
|