@lyxa.ai/core 1.4.278 → 1.4.279
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/libraries/transliteration/interfaces/common-transliteration.d.ts +1 -1
- package/dist/libraries/transliteration/interfaces/common-transliteration.js.map +1 -1
- package/dist/libraries/transliteration/providers/openai-provider.d.ts +1 -1
- package/dist/libraries/transliteration/providers/openai-provider.js +4 -6
- package/dist/libraries/transliteration/providers/openai-provider.js.map +1 -1
- package/dist/libraries/transliteration/transliteration-service.d.ts +1 -1
- package/dist/libraries/transliteration/transliteration-service.js +2 -3
- package/dist/libraries/transliteration/transliteration-service.js.map +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ export interface AICompletionOptions {
|
|
|
4
4
|
}
|
|
5
5
|
export interface IAICompletionProvider {
|
|
6
6
|
prompt(text: string, options?: AICompletionOptions): Promise<string>;
|
|
7
|
-
|
|
7
|
+
generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult>;
|
|
8
8
|
}
|
|
9
9
|
export interface TextVariantConfig {
|
|
10
10
|
isArabic?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-transliteration.js","sourceRoot":"/","sources":["libraries/transliteration/interfaces/common-transliteration.ts"],"names":[],"mappings":"","sourcesContent":["export interface AICompletionOptions {\n\tinstructions?: string;\n\ttemperature?: number;\n}\n\nexport interface IAICompletionProvider {\n\tprompt(text: string, options?: AICompletionOptions): Promise<string>;\n\
|
|
1
|
+
{"version":3,"file":"common-transliteration.js","sourceRoot":"/","sources":["libraries/transliteration/interfaces/common-transliteration.ts"],"names":[],"mappings":"","sourcesContent":["export interface AICompletionOptions {\n\tinstructions?: string;\n\ttemperature?: number;\n}\n\nexport interface IAICompletionProvider {\n\tprompt(text: string, options?: AICompletionOptions): Promise<string>;\n\tgeneratePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult>;\n}\n\nexport interface TextVariantConfig {\n\tisArabic?: boolean; // Arabic translation, Arabic script\n\tisArabizi?: boolean; // Arabic word, Latin script (e.g. \"zaytoon\")\n\tisArabicTransliteration?: boolean; // original word, spelled phonetically in Arabic script (e.g. \"أوليف\")\n}\n\nexport interface TextVariantResult {\n\toriginal: string;\n\tarabic?: string[];\n\tarabizi?: string[];\n\tarabicTransliteration?: string[];\t\n}"]}
|
|
@@ -4,7 +4,7 @@ export declare class OpenAICompletionProvider implements IAICompletionProvider {
|
|
|
4
4
|
private readonly model;
|
|
5
5
|
constructor(apiKey: string | undefined, model?: string);
|
|
6
6
|
prompt(text: string, options?: AICompletionOptions): Promise<string>;
|
|
7
|
-
|
|
7
|
+
generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult>;
|
|
8
8
|
private buildVariantRequest;
|
|
9
9
|
private buildJsonSchema;
|
|
10
10
|
}
|
|
@@ -16,21 +16,19 @@ class OpenAICompletionProvider {
|
|
|
16
16
|
this.model = model;
|
|
17
17
|
}
|
|
18
18
|
async prompt(text, options) {
|
|
19
|
-
console.log({ text, options });
|
|
20
19
|
const response = await this.client.responses.create({
|
|
21
20
|
model: this.model,
|
|
22
21
|
instructions: options?.instructions,
|
|
23
22
|
input: text,
|
|
24
23
|
});
|
|
25
|
-
console.log("prompt: ", response);
|
|
26
24
|
return response.output_text ?? '';
|
|
27
25
|
}
|
|
28
|
-
async
|
|
26
|
+
async generatePromptVariants(text, config) {
|
|
27
|
+
console.log({ text, config });
|
|
29
28
|
const { fields, instructions } = this.buildVariantRequest(config);
|
|
30
29
|
if (fields.length === 0) {
|
|
31
30
|
return { original: text };
|
|
32
31
|
}
|
|
33
|
-
console.log({ text, config });
|
|
34
32
|
const response = await this.client.responses.create({
|
|
35
33
|
model: this.model,
|
|
36
34
|
instructions,
|
|
@@ -44,8 +42,9 @@ class OpenAICompletionProvider {
|
|
|
44
42
|
},
|
|
45
43
|
},
|
|
46
44
|
});
|
|
45
|
+
console.log('generateTextVariants: ', { response });
|
|
47
46
|
const parsedResult = JSON.parse(response.output_text ?? '{}');
|
|
48
|
-
console.log(
|
|
47
|
+
console.log('generateTextVariants: ', { parsedResult });
|
|
49
48
|
return { original: text, ...parsedResult };
|
|
50
49
|
}
|
|
51
50
|
buildVariantRequest(config) {
|
|
@@ -67,7 +66,6 @@ class OpenAICompletionProvider {
|
|
|
67
66
|
...fields.map(f => `- ${f}: ${fieldDescriptions[f]}`),
|
|
68
67
|
'Return strict JSON matching the schema. No extra commentary, no extra fields.',
|
|
69
68
|
].join('\n');
|
|
70
|
-
console.log({ instructions });
|
|
71
69
|
return { fields, instructions };
|
|
72
70
|
}
|
|
73
71
|
buildJsonSchema(fields) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-provider.js","sourceRoot":"/","sources":["libraries/transliteration/providers/openai-provider.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;
|
|
1
|
+
{"version":3,"file":"openai-provider.js","sourceRoot":"/","sources":["libraries/transliteration/providers/openai-provider.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAQ5B,MAAa,wBAAwB;IACnB,MAAM,CAAS;IACf,KAAK,CAAS;IAE/B,YAAY,MAA0B,EAAE,QAAgB,SAAS;QAChE,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACrF,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,OAA6B;QACvD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;YACnD,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,YAAY,EAAE,OAAO,EAAE,YAAY;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uJAAuJ;SACxJ,CAAC;QAEF,MAAM,MAAM,GAAgC,EAAE,CAAC;QAC/C,IAAI,MAAM,CAAC,QAAQ;YAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3C,IAAI,MAAM,CAAC,SAAS;YAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,MAAM,CAAC,uBAAuB;YAAE,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAEzE,MAAM,YAAY,GAAG;YACpB,8EAA8E;YAC9E,kFAAkF;YAClF,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,iBAAiB,CAAC,CAAiD,CAAC,EAAE,CAAC;YACrG,+EAA+E;SAC/E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;IACjC,CAAC;IAEO,eAAe,CAAC,MAAmC;QAC1D,MAAM,UAAU,GAAwB,EAAE,CAAC;QAC3C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC5B,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC;QAClE,CAAC;QAED,OAAO;YACN,IAAI,EAAE,QAAQ;YACd,UAAU;YACV,QAAQ,EAAE,MAAM;YAChB,oBAAoB,EAAE,KAAK;SAC3B,CAAC;IACH,CAAC;CACD;AA3FD,4DA2FC","sourcesContent":["import OpenAI from 'openai';\nimport {\n\tAICompletionOptions,\n\tIAICompletionProvider,\n\tTextVariantConfig,\n\tTextVariantResult,\n} from '../interfaces/common-transliteration';\n\nexport class OpenAICompletionProvider implements IAICompletionProvider {\n\tprivate readonly client: OpenAI;\n\tprivate readonly model: string;\n\n\tconstructor(apiKey: string | undefined, model: string = 'gpt-5.5') {\n\t\tif (!apiKey) {\n\t\t\tthrow new Error('OPENAI_API_KEY is required to construct OpenAICompletionProvider');\n\t\t}\n\t\tthis.client = new OpenAI({ apiKey });\n\t\tthis.model = model;\n\t}\n\n\tasync prompt(text: string, options?: AICompletionOptions): Promise<string> {\n\t\tconst response = await this.client.responses.create({\n\t\t\tmodel: this.model,\n\t\t\tinstructions: options?.instructions,\n\t\t\tinput: text,\n\t\t});\n\t\treturn response.output_text ?? '';\n\t}\n\n\tasync generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult> {\n\t\tconsole.log({ text, config})\n\t\tconst { fields, instructions } = this.buildVariantRequest(config);\n\n\t\tif (fields.length === 0) {\n\t\t\treturn { original: text };\n\t\t}\n\n\t\tconst response = await this.client.responses.create({\n\t\t\tmodel: this.model,\n\t\t\tinstructions,\n\t\t\tinput: text,\n\t\t\ttext: {\n\t\t\t\tformat: {\n\t\t\t\t\ttype: 'json_schema',\n\t\t\t\t\tname: 'text_variants',\n\t\t\t\t\tschema: this.buildJsonSchema(fields),\n\t\t\t\t\tstrict: true,\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\tconsole.log('generateTextVariants: ', { response })\n\t\tconst parsedResult = JSON.parse(response.output_text ?? '{}');\n\t\tconsole.log('generateTextVariants: ', { parsedResult })\n\t\treturn { original: text, ...parsedResult };\n\t}\n\n\t// ── Helpers ──────────────────────────────────────────────────────\n\n\tprivate buildVariantRequest(config: TextVariantConfig): {\n\t\tfields: (keyof TextVariantResult)[];\n\t\tinstructions: string;\n\t} {\n\t\tconst fieldDescriptions: Record<Exclude<keyof TextVariantResult, 'original'>, string> = {\n\t\t\tarabic:\n\t\t\t\t'The Arabic translation of the word/phrase, written in Arabic script (e.g. \"زيتون\" for \"olive\"). Provide 1-3 common variants if applicable.',\n\t\t\tarabizi:\n\t\t\t\t'The Arabic word\\'s meaning, written phonetically in Latin script/numerals — i.e. Arabizi (e.g. \"zaytoon\"). Provide 1-3 common spelling variants.',\n\t\t\tarabicTransliteration:\n\t\t\t\t'The original word spelled phonetically in Arabic script, NOT translated (e.g. \"أوليف\" for \"olive\"). Useful when there is no native Arabic equivalent.',\n\t\t};\n\n\t\tconst fields: (keyof TextVariantResult)[] = [];\n\t\tif (config.isArabic) fields.push('arabic');\n\t\tif (config.isArabizi) fields.push('arabizi');\n\t\tif (config.isArabicTransliteration) fields.push('arabicTransliteration');\n\n\t\tconst instructions = [\n\t\t\t'You generate search-name variants for a food delivery app product/shop name.',\n\t\t\t'For the given input text, return ONLY the following fields as arrays of strings:',\n\t\t\t...fields.map(f => `- ${f}: ${fieldDescriptions[f as Exclude<keyof TextVariantResult, 'original'>]}`),\n\t\t\t'Return strict JSON matching the schema. No extra commentary, no extra fields.',\n\t\t].join('\\n');\n\n\t\treturn { fields, instructions };\n\t}\n\n\tprivate buildJsonSchema(fields: (keyof TextVariantResult)[]) {\n\t\tconst properties: Record<string, any> = {};\n\t\tfor (const field of fields) {\n\t\t\tproperties[field] = { type: 'array', items: { type: 'string' } };\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'object',\n\t\t\tproperties,\n\t\t\trequired: fields,\n\t\t\tadditionalProperties: false,\n\t\t};\n\t}\n}\n"]}
|
|
@@ -9,6 +9,6 @@ export declare class TransliterationService {
|
|
|
9
9
|
private readonly factories;
|
|
10
10
|
constructor(provider: TransliterationProvider);
|
|
11
11
|
translateToArabizi(text: string): Promise<string>;
|
|
12
|
-
|
|
12
|
+
generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult>;
|
|
13
13
|
private getProvider;
|
|
14
14
|
}
|
|
@@ -15,7 +15,6 @@ class TransliterationService {
|
|
|
15
15
|
factories = {
|
|
16
16
|
[TransliterationProvider.OPENAI]: async () => {
|
|
17
17
|
const apiKey = await (0, __1.getLibraries)().getSecretsService().getKey('OPENAI_API_KEY');
|
|
18
|
-
console.log({ apiKey });
|
|
19
18
|
if (!apiKey) {
|
|
20
19
|
throw (0, error_common_1.badRequestError)(`No API key found for provider ${TransliterationProvider.OPENAI}`);
|
|
21
20
|
}
|
|
@@ -34,9 +33,9 @@ class TransliterationService {
|
|
|
34
33
|
instructions: 'You are a translation assistant. Translate the given text to Arabizi.',
|
|
35
34
|
});
|
|
36
35
|
}
|
|
37
|
-
async
|
|
36
|
+
async generatePromptVariants(text, config) {
|
|
38
37
|
const provider = await this.getProvider();
|
|
39
|
-
return provider.
|
|
38
|
+
return provider.generatePromptVariants(text, config);
|
|
40
39
|
}
|
|
41
40
|
async getProvider() {
|
|
42
41
|
if (!this.providerInstance) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transliteration-service.js","sourceRoot":"/","sources":["libraries/transliteration/transliteration-service.ts"],"names":[],"mappings":";;;AAAA,6BAAqC;AACrC,+DAA+D;AAM/D,iEAAuE;AAEvE,IAAY,uBAGX;AAHD,WAAY,uBAAuB;IAClC,4CAAiB,CAAA;IACjB,4CAAiB,CAAA;AAClB,CAAC,EAHW,uBAAuB,uCAAvB,uBAAuB,QAGlC;AAID,MAAa,sBAAsB;
|
|
1
|
+
{"version":3,"file":"transliteration-service.js","sourceRoot":"/","sources":["libraries/transliteration/transliteration-service.ts"],"names":[],"mappings":";;;AAAA,6BAAqC;AACrC,+DAA+D;AAM/D,iEAAuE;AAEvE,IAAY,uBAGX;AAHD,WAAY,uBAAuB;IAClC,4CAAiB,CAAA;IACjB,4CAAiB,CAAA;AAClB,CAAC,EAHW,uBAAuB,uCAAvB,uBAAuB,QAGlC;AAID,MAAa,sBAAsB;IAgBL;IAfrB,gBAAgB,GAAiC,IAAI,CAAC;IAE7C,SAAS,GAAqD;QAC9E,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,EAAE;YAC5C,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAY,GAAE,CAAC,iBAAiB,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;YACjF,IAAI,CAAC,MAAM,EAAE,CAAC;gBACb,MAAM,IAAA,8BAAe,EAAC,iC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ities/error-common';\nimport {\n\tIAICompletionProvider,\n\tTextVariantConfig,\n\tTextVariantResult,\n} from './interfaces/common-transliteration';\nimport { OpenAICompletionProvider } from './providers/openai-provider';\n\nexport enum TransliterationProvider {\n\tOPENAI = 'openai',\n\tGEMINI = 'gemini',\n}\n\ntype ProviderFactory = () => Promise<IAICompletionProvider>;\n\nexport class TransliterationService {\n\tprivate providerInstance: IAICompletionProvider | null = null;\n\n\tprivate readonly factories: Record<TransliterationProvider, ProviderFactory> = {\n\t\t[TransliterationProvider.OPENAI]: async () => {\n\t\t\tconst apiKey = await getLibraries().getSecretsService().getKey('OPENAI_API_KEY');\t\t\t\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow badRequestError(`No API key found for provider ${TransliterationProvider.OPENAI}`);\n\t\t\t}\n\t\t\treturn new OpenAICompletionProvider(apiKey, 'gpt-5.5');\n\t\t},\n\t\t[TransliterationProvider.GEMINI]: async () => {\n\t\t\tthrow badRequestError(`Provider ${TransliterationProvider.GEMINI} is not implemented yet`);\n\t\t},\n\t};\n\n\tconstructor(private readonly provider: TransliterationProvider) {}\n\n\tasync translateToArabizi(text: string): Promise<string> {\n\t\tconst provider = await this.getProvider();\n\t\treturn provider.prompt(text, {\n\t\t\tinstructions: 'You are a translation assistant. Translate the given text to Arabizi.',\n\t\t});\n\t}\n\n\tasync generatePromptVariants(text: string, config: TextVariantConfig): Promise<TextVariantResult> {\n\t\tconst provider = await this.getProvider();\n\t\treturn provider.generatePromptVariants(text, config);\n\t}\n\n\tprivate async getProvider(): Promise<IAICompletionProvider> {\n\t\tif (!this.providerInstance) {\n\t\t\tconst factory = this.factories[this.provider];\n\t\t\tif (!factory) {\n\t\t\t\tthrow badRequestError(`Unsupported transliteration provider: ${this.provider}`);\n\t\t\t}\n\t\t\tthis.providerInstance = await factory();\n\t\t}\n\t\treturn this.providerInstance;\n\t}\n}\n"]}
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED