@lilaquadrat/studio 9.22.0 → 9.23.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.
- package/lib/cjs/src/prompts/textGeneration.js +87 -0
- package/lib/cjs/src/prompts/textGeneration.js.map +1 -1
- package/lib/cjs/src/prompts/textGenerationMulti.js +78 -45
- package/lib/cjs/src/prompts/textGenerationMulti.js.map +1 -1
- package/lib/cjs/src/services/ai.service.d.ts +4 -3
- package/lib/cjs/src/services/ai.service.js +30 -37
- package/lib/cjs/src/services/ai.service.js.map +1 -1
- package/lib/cjs/src/services/spamAnalasys.service.d.ts +4 -4
- package/lib/cjs/src/services/spamAnalasys.service.js +36 -44
- package/lib/cjs/src/services/spamAnalasys.service.js.map +1 -1
- package/package.json +2 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable max-len */
|
|
3
4
|
function textGeneration(input, element, context) {
|
|
4
5
|
const inputKeyExplanations = {
|
|
5
6
|
headline: 'headline: main title. will be ## in the context',
|
|
@@ -7,6 +8,92 @@ function textGeneration(input, element, context) {
|
|
|
7
8
|
intro: 'intro: introductory text will be #### in the context',
|
|
8
9
|
text: 'text: array of paragraphs',
|
|
9
10
|
};
|
|
11
|
+
return `You are an AI text generation assistant integrated with an enterprise CMS. Your primary goal is to generate text for a single page ("site") of a website using structured JSON input, exact contextual fields, and—most crucially—strict adherence to the provided "instructions." All your outputs and processing must be governed first and foremost by the "instructions" field, with contextual influences applied only as permitted or guided by those instructions.
|
|
12
|
+
|
|
13
|
+
Use the input JSON provided to you, which has the following structure:
|
|
14
|
+
|
|
15
|
+
{
|
|
16
|
+
"input": "${input}"
|
|
17
|
+
"context": {
|
|
18
|
+
"demographic": "Target audience for the page",
|
|
19
|
+
"tone": "Desired tone (e.g., friendly, professional)",
|
|
20
|
+
"project": "Description of the overall project",
|
|
21
|
+
"site": "Information about the current site/page",
|
|
22
|
+
"parent": "Context of the parent page, if any",
|
|
23
|
+
"siblings": "Context from sibling elements/pages",
|
|
24
|
+
"direct": "Direct context for current content/module",
|
|
25
|
+
"environment": "Description of the display environment and usage",
|
|
26
|
+
"content": "Markdown content for the site"
|
|
27
|
+
},
|
|
28
|
+
"instructions": "Any specific instructions for generating or shaping the text"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
the input is a ${inputKeyExplanations[element]}
|
|
32
|
+
|
|
33
|
+
# Detailed Task
|
|
34
|
+
|
|
35
|
+
- The "instructions" field is the absolute authority for shaping, directing, and constraining all generated content. You must follow it exactly; override context or default approaches if the instructions require it.
|
|
36
|
+
- Use the "context" fields to inform additional writing details, applying the following weighted influences (higher means more important), but only as permitted by the instructions:
|
|
37
|
+
- project: 0.4
|
|
38
|
+
- site: 0.48
|
|
39
|
+
- parent: 0.48
|
|
40
|
+
- siblings: 0.64
|
|
41
|
+
- direct: 0.8
|
|
42
|
+
- environment: 0.8
|
|
43
|
+
- content: 0.32
|
|
44
|
+
- demographic: 0.6
|
|
45
|
+
- tone: 0.6
|
|
46
|
+
- Every key in the "input" object must receive a unique, relevant value (do not duplicate content across fields), and the text should only reflect the context to the extent allowed by the instructions.
|
|
47
|
+
- Your output **must** precisely match the input JSON structure, with no additional keys, extra fields, or markup. Produce only the required JSON.
|
|
48
|
+
- Never ask questions, seek clarification, or provide explanations. Only generate and output content as directed by instructions.
|
|
49
|
+
- No markup (Markdown, HTML, or formatting syntax) is allowed in outputs—plain text only.
|
|
50
|
+
- Persist in internally verifying compliance with the instructions above all else before writing your final JSON response.
|
|
51
|
+
|
|
52
|
+
# Steps
|
|
53
|
+
|
|
54
|
+
1. Thoroughly read and analyze the "instructions" field; determine any required structure, style, ordering, or output format mandates.
|
|
55
|
+
2. Reread each context field and apply only those elements which the instructions specify, or where not otherwise constrained, weigh them according to the context weights above.
|
|
56
|
+
3. For each "input" key (including "intro" and every "text" string), carefully plan and compose content that fully implements the instructions, referencing additional context as allowed.
|
|
57
|
+
4. Confirm no duplication between any "input" keys. All outputs must be non-redundant and unique.
|
|
58
|
+
5. Internally review your response for absolute adherence to the instructions, overriding context weightings or defaults if needed.
|
|
59
|
+
6. Output only the updated JSON with your generated field values.
|
|
60
|
+
|
|
61
|
+
# Output Format
|
|
62
|
+
|
|
63
|
+
Output must be the completed JSON object, strictly matching the input in structure and property names. Do not add, remove, or reorder fields. No extra text, commentary, explanations, or markup of any kind should ever be output. Plain text values only.
|
|
64
|
+
|
|
65
|
+
# Example
|
|
66
|
+
|
|
67
|
+
**Input (for context, this will be sent to you):**
|
|
68
|
+
{
|
|
69
|
+
"input": "${input}"
|
|
70
|
+
"context": {
|
|
71
|
+
"demographic": "University students",
|
|
72
|
+
"tone": "Enthusiastic and clear",
|
|
73
|
+
"project": "An educational resources portal for biology students",
|
|
74
|
+
"site": "Homepage for the biology resources section",
|
|
75
|
+
"parent": "Main portal landing page",
|
|
76
|
+
"siblings": "Mathematics and chemistry resource pages",
|
|
77
|
+
"direct": "Highlighting latest biology tutorials and guides",
|
|
78
|
+
"environment": "Displayed in a mobile-friendly web app",
|
|
79
|
+
"content": "Collection of resources, articles, and video guides"
|
|
80
|
+
},
|
|
81
|
+
"instructions": "Explain the section's purpose in the intro, then provide two distinct welcoming paragraphs that introduce resources and encourage navigation."
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
**Expected Output:**
|
|
85
|
+
{
|
|
86
|
+
"input": "${input}"
|
|
87
|
+
}
|
|
88
|
+
*(Actual outputs should match in length, substance, and adherence to the instructions; always ensure they follow the specific guidance provided.)*
|
|
89
|
+
|
|
90
|
+
# Notes
|
|
91
|
+
|
|
92
|
+
- The "instructions" field must govern and take precedence in all cases. Never ignore, sideline, or deprioritize details within "instructions"; always double-check that outputs meet them fully.
|
|
93
|
+
- All text must be unique, plain text, and adhere precisely to the instructions and output format constraints.
|
|
94
|
+
- Never explain, comment, or output context or process steps—output only the specified JSON fields and values.
|
|
95
|
+
|
|
96
|
+
**Reminder: Strictly follow the "instructions" for content, style, and scope. Output only the structured JSON—no extra text, explanations, or markup.**`;
|
|
10
97
|
return `you are an text assistant. you are part of a enterprise cms. you are creating text for a single site of a website.
|
|
11
98
|
|
|
12
99
|
i will provide an json in this format:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textGeneration.js","sourceRoot":"","sources":["../../../../src/prompts/textGeneration.ts"],"names":[],"mappings":";;AAAA,SAAwB,cAAc,CAAC,KAAU,EAAE,OAAe,EAAE,OAAY;IAE9E,MAAM,oBAAoB,GAA2B;QACnD,QAAQ,EAAE,iDAAiD;QAC3D,OAAO,EAAE,mEAAmE;QAC5E,KAAK,EAAE,sDAAsD;QAC7D,IAAI,EAAE,2BAA2B;KAClC,CAAC;IAEF,OAAO;;;;gBAIO,KAAK;;;;;;;;;;;;;;;iBAeJ,oBAAoB,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC7C,CAAC;AAEF,CAAC;
|
|
1
|
+
{"version":3,"file":"textGeneration.js","sourceRoot":"","sources":["../../../../src/prompts/textGeneration.ts"],"names":[],"mappings":";;AAAA,4BAA4B;AAC5B,SAAwB,cAAc,CAAC,KAAU,EAAE,OAAe,EAAE,OAAY;IAE9E,MAAM,oBAAoB,GAA2B;QACnD,QAAQ,EAAE,iDAAiD;QAC3D,OAAO,EAAE,mEAAmE;QAC5E,KAAK,EAAE,sDAAsD;QAC7D,IAAI,EAAE,2BAA2B;KAClC,CAAC;IAEF,OAAO;;;;;cAKK,KAAK;;;;;;;;;;;;;;;iBAeF,oBAAoB,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsChC,KAAK;;;;;;;;;;;;;;;;;cAiBL,KAAK;;;;;;;;;;wJAUqI,CAAA;IAEtJ,OAAO;;;;gBAIO,KAAK;;;;;;;;;;;;;;;iBAeJ,oBAAoB,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC7C,CAAC;AAEF,CAAC;AAtJD,iCAsJC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable max-len */
|
|
3
4
|
function textGenerationMulti(input, context) {
|
|
4
5
|
const inputKeyExplanations = {
|
|
5
6
|
headline: 'headline: main title. will be ## in the context',
|
|
@@ -11,58 +12,90 @@ function textGenerationMulti(input, context) {
|
|
|
11
12
|
.filter(key => inputKeyExplanations[key])
|
|
12
13
|
.map(key => ` ${inputKeyExplanations[key]}`)
|
|
13
14
|
.join('\n');
|
|
14
|
-
return `
|
|
15
|
+
return `You are an AI text generation assistant integrated with an enterprise CMS. Your primary goal is to generate text for a single page ("site") of a website using structured JSON input, exact contextual fields, and—most crucially—strict adherence to the provided "instructions." All your outputs and processing must be governed first and foremost by the "instructions" field, with contextual influences applied only as permitted or guided by those instructions.
|
|
16
|
+
|
|
17
|
+
Use the input JSON provided to you, which has the following structure:
|
|
15
18
|
|
|
16
|
-
i will provide an json in this format:
|
|
17
19
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
20
|
+
"input": ${JSON.stringify(input, null, 2)},
|
|
21
|
+
"context": {
|
|
22
|
+
"demographic": "Target audience for the page",
|
|
23
|
+
"tone": "Desired tone (e.g., friendly, professional)",
|
|
24
|
+
"project": "Description of the overall project",
|
|
25
|
+
"site": "Information about the current site/page",
|
|
26
|
+
"parent": "Context of the parent page, if any",
|
|
27
|
+
"siblings": "Context from sibling elements/pages",
|
|
28
|
+
"direct": "Direct context for current content/module",
|
|
29
|
+
"environment": "Description of the display environment and usage",
|
|
30
|
+
"content": "Markdown content for the site"
|
|
31
|
+
},
|
|
32
|
+
"instructions": "Any specific instructions for generating or shaping the text"
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
${explanations ? `Explanation of input keys:\n${explanations}\n\n` : ''}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
${explanations ? `Explanation of input keys:\n${explanations}\n\n` : ''}# Detailed Task
|
|
36
|
+
|
|
37
|
+
- The "instructions" field is the absolute authority for shaping, directing, and constraining all generated content. You must follow it exactly; override context or default approaches if the instructions require it.
|
|
38
|
+
- Use the "context" fields to inform additional writing details, applying the following weighted influences (higher means more important), but only as permitted by the instructions:
|
|
39
|
+
- project: 0.4
|
|
40
|
+
- site: 0.48
|
|
41
|
+
- parent: 0.48
|
|
42
|
+
- siblings: 0.64
|
|
43
|
+
- direct: 0.8
|
|
44
|
+
- environment: 0.8
|
|
45
|
+
- content: 0.32
|
|
46
|
+
- demographic: 0.6
|
|
47
|
+
- tone: 0.6
|
|
48
|
+
- Every key in the "input" object must receive a unique, relevant value (do not duplicate content across fields), and the text should only reflect the context to the extent allowed by the instructions.
|
|
49
|
+
- Your output **must** precisely match the input JSON structure, with no additional keys, extra fields, or markup. Produce only the required JSON.
|
|
50
|
+
- Never ask questions, seek clarification, or provide explanations. Only generate and output content as directed by instructions.
|
|
51
|
+
- No markup (Markdown, HTML, or formatting syntax) is allowed in outputs—plain text only.
|
|
52
|
+
- Persist in internally verifying compliance with the instructions above all else before writing your final JSON response.
|
|
53
|
+
|
|
54
|
+
# Steps
|
|
55
|
+
|
|
56
|
+
1. Thoroughly read and analyze the "instructions" field; determine any required structure, style, ordering, or output format mandates.
|
|
57
|
+
2. Reread each context field and apply only those elements which the instructions specify, or where not otherwise constrained, weigh them according to the context weights above.
|
|
58
|
+
3. For each "input" key (including "intro" and every "text" string), carefully plan and compose content that fully implements the instructions, referencing additional context as allowed.
|
|
59
|
+
4. Confirm no duplication between any "input" keys. All outputs must be non-redundant and unique.
|
|
60
|
+
5. Internally review your response for absolute adherence to the instructions, overriding context weightings or defaults if needed.
|
|
61
|
+
6. Output only the updated JSON with your generated field values.
|
|
62
|
+
|
|
63
|
+
# Output Format
|
|
64
|
+
|
|
65
|
+
Output must be the completed JSON object, strictly matching the input in structure and property names. Do not add, remove, or reorder fields. No extra text, commentary, explanations, or markup of any kind should ever be output. Plain text values only.
|
|
66
|
+
|
|
67
|
+
# Example
|
|
68
|
+
|
|
69
|
+
**Input (for context, this will be sent to you):**
|
|
70
|
+
{
|
|
71
|
+
"input": ${JSON.stringify(input, null, 2)},
|
|
72
|
+
"context": {
|
|
73
|
+
"demographic": "University students",
|
|
74
|
+
"tone": "Enthusiastic and clear",
|
|
75
|
+
"project": "An educational resources portal for biology students",
|
|
76
|
+
"site": "Homepage for the biology resources section",
|
|
77
|
+
"parent": "Main portal landing page",
|
|
78
|
+
"siblings": "Mathematics and chemistry resource pages",
|
|
79
|
+
"direct": "Highlighting latest biology tutorials and guides",
|
|
80
|
+
"environment": "Displayed in a mobile-friendly web app",
|
|
81
|
+
"content": "Collection of resources, articles, and video guides"
|
|
82
|
+
},
|
|
83
|
+
"instructions": "Explain the section's purpose in the intro, then provide two distinct welcoming paragraphs that introduce resources and encourage navigation."
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
**Expected Output:**
|
|
87
|
+
{
|
|
88
|
+
"input": ${JSON.stringify(input, null, 2)}
|
|
89
|
+
}
|
|
90
|
+
*(Actual outputs should match in length, substance, and adherence to the instructions; always ensure they follow the specific guidance provided.)*
|
|
42
91
|
|
|
43
|
-
|
|
44
|
-
demographic and tone are provided by the user to help you understand the target audience and tone of the text.
|
|
92
|
+
# Notes
|
|
45
93
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
parent: 0.48
|
|
50
|
-
siblings: 0.64
|
|
51
|
-
direct: 0.8
|
|
52
|
-
content: 0.32
|
|
53
|
-
demographic: 0.6
|
|
54
|
-
environment: 0.8
|
|
55
|
-
tone: 0.6
|
|
94
|
+
- The "instructions" field must govern and take precedence in all cases. Never ignore, sideline, or deprioritize details within "instructions"; always double-check that outputs meet them fully.
|
|
95
|
+
- All text must be unique, plain text, and adhere precisely to the instructions and output format constraints.
|
|
96
|
+
- Never explain, comment, or output context or process steps—output only the specified JSON fields and values.
|
|
56
97
|
|
|
57
|
-
|
|
58
|
-
RULE: every key in the input json has to be affected
|
|
59
|
-
RULE: each key has to have unique text, no duplicates
|
|
60
|
-
RULE: the weighted context has to be used to produce the text and
|
|
61
|
-
RULE: output has to match the input json, no additional keys allowed
|
|
62
|
-
RULE: only output the input json, no context or anything else
|
|
63
|
-
RULE: dont even ask for something. just produce some ouput
|
|
64
|
-
RULE: only text outputs, no markup of any kind
|
|
65
|
-
`;
|
|
98
|
+
**Reminder: Strictly follow the "instructions" for content, style, and scope. Output only the structured JSON—no extra text, explanations, or markup.**`;
|
|
66
99
|
}
|
|
67
100
|
exports.default = textGenerationMulti;
|
|
68
101
|
//# sourceMappingURL=textGenerationMulti.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"textGenerationMulti.js","sourceRoot":"","sources":["../../../../src/prompts/textGenerationMulti.ts"],"names":[],"mappings":";;AAAA,SAAwB,mBAAmB,CAAC,KAAU,EAAE,OAAY;IAElE,MAAM,oBAAoB,GAA2B;QACnD,QAAQ,EAAE,iDAAiD;QAC3D,OAAO,EAAE,mEAAmE;QAC5E,KAAK,EAAE,sDAAsD;QAC7D,IAAI,EAAE,2BAA2B;KAClC,CAAC;IAEF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;SACpC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;SACxC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,oBAAoB,CAAC,GAAG,CAAC,EAAE,CAAC;SAC9C,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO
|
|
1
|
+
{"version":3,"file":"textGenerationMulti.js","sourceRoot":"","sources":["../../../../src/prompts/textGenerationMulti.ts"],"names":[],"mappings":";;AAAA,4BAA4B;AAC5B,SAAwB,mBAAmB,CAAC,KAAU,EAAE,OAAY;IAElE,MAAM,oBAAoB,GAA2B;QACnD,QAAQ,EAAE,iDAAiD;QAC3D,OAAO,EAAE,mEAAmE;QAC5E,KAAK,EAAE,sDAAsD;QAC7D,IAAI,EAAE,2BAA2B;KAClC,CAAC;IAEF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;SACpC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;SACxC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,oBAAoB,CAAC,GAAG,CAAC,EAAE,CAAC;SAC9C,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO;;;;;aAKI,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;;;;;;;;;;;;;;EAezC,YAAY,CAAC,CAAC,CAAC,+BAA+B,YAAY,MAAM,CAAC,CAAC,CAAC,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAoC1D,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;;;;;;;;;;;;;;;;aAiB9B,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;;;;;;;;;;wJAU6G,CAAC;AAEzJ,CAAC;AAnGD,sCAmGC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { UserAppOptionsRequired } from '@lilaquadrat/interfaces';
|
|
2
|
-
import
|
|
2
|
+
import { GoogleGenAI } from '@google/genai';
|
|
3
3
|
export declare class Ai {
|
|
4
|
-
provider:
|
|
5
|
-
|
|
4
|
+
provider: GoogleGenAI;
|
|
5
|
+
model: string;
|
|
6
|
+
constructor(key: string, model: string);
|
|
6
7
|
tokenUsage(date: string | undefined, options: UserAppOptionsRequired): Promise<import("bson").Document>;
|
|
7
8
|
generateTextForProject(input: Object, instructions: string, element: string | undefined, context: {
|
|
8
9
|
project?: string;
|
|
@@ -4,20 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Ai = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const logging_model_1 = __importDefault(require("../models/logging.model"));
|
|
7
|
+
const textGeneration_js_1 = __importDefault(require("../prompts/textGeneration.js"));
|
|
8
|
+
const textGenerationMulti_js_1 = __importDefault(require("../prompts/textGenerationMulti.js"));
|
|
9
|
+
const project_model_js_1 = __importDefault(require("../models/project.model.js"));
|
|
10
|
+
const logging_service_js_1 = __importDefault(require("./logging.service.js"));
|
|
11
|
+
const logging_model_js_1 = __importDefault(require("../models/logging.model.js"));
|
|
13
12
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
13
|
+
const genai_1 = require("@google/genai");
|
|
14
14
|
class Ai {
|
|
15
|
-
constructor(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
15
|
+
constructor(key, model) {
|
|
16
|
+
this.provider = new genai_1.GoogleGenAI({
|
|
17
|
+
apiKey: key,
|
|
18
|
+
});
|
|
19
|
+
this.model = model;
|
|
21
20
|
}
|
|
22
21
|
async tokenUsage(date, options) {
|
|
23
22
|
if (date) {
|
|
@@ -25,7 +24,7 @@ class Ai {
|
|
|
25
24
|
const useDate = (0, dayjs_1.default)().set('year', +dateSplit[1]).set('month', +dateSplit[0] - 1);
|
|
26
25
|
console.log('useDate', useDate, useDate.startOf('month').toDate(), useDate.endOf('month').toDate());
|
|
27
26
|
}
|
|
28
|
-
const response = await
|
|
27
|
+
const response = await logging_model_js_1.default.db.aggregate([
|
|
29
28
|
{
|
|
30
29
|
$match: {
|
|
31
30
|
type: 'ai',
|
|
@@ -69,37 +68,31 @@ class Ai {
|
|
|
69
68
|
return { input: 0, output: 0, calls: 0 };
|
|
70
69
|
}
|
|
71
70
|
async generateTextForProject(input, instructions, element, context, options) {
|
|
72
|
-
const projectContext = await
|
|
71
|
+
const projectContext = await project_model_js_1.default.db.findOne({ company: options.company, id: options.project }, { projection: { aiDescription: 1, aiTone: 1 } });
|
|
73
72
|
return this.generateText(input, instructions, element, { ...context, project: projectContext?.aiDescription, tone: projectContext?.aiTone }, options);
|
|
74
73
|
}
|
|
75
74
|
async generateText(input, instructions, element, context, options) {
|
|
76
|
-
const content = options.type === 'single' ? (0,
|
|
77
|
-
const response = await this.provider.
|
|
78
|
-
model:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
role: 'system',
|
|
84
|
-
content,
|
|
75
|
+
const content = options.type === 'single' ? (0, textGeneration_js_1.default)(input, element, context) : (0, textGenerationMulti_js_1.default)(input, context);
|
|
76
|
+
const response = await this.provider.models.generateContent({
|
|
77
|
+
model: this.model,
|
|
78
|
+
config: {
|
|
79
|
+
systemInstruction: content,
|
|
80
|
+
thinkingConfig: {
|
|
81
|
+
thinkingLevel: genai_1.ThinkingLevel.LOW,
|
|
85
82
|
},
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
}, {
|
|
96
|
-
timeout: 30000,
|
|
83
|
+
responseMimeType: 'application/json'
|
|
84
|
+
},
|
|
85
|
+
contents: JSON.stringify({
|
|
86
|
+
input,
|
|
87
|
+
instructions,
|
|
88
|
+
context,
|
|
89
|
+
}),
|
|
97
90
|
});
|
|
98
|
-
await
|
|
99
|
-
const responseData = JSON.parse(response.
|
|
91
|
+
await logging_service_js_1.default.add({ input: { input, instructions, context }, response }, { type: 'ai', company: options.company, project: options.project, app: options.app, user: options.user });
|
|
92
|
+
const responseData = JSON.parse(response.text);
|
|
100
93
|
return { output: responseData.input };
|
|
101
94
|
}
|
|
102
95
|
}
|
|
103
96
|
exports.Ai = Ai;
|
|
104
|
-
exports.default = new Ai(
|
|
97
|
+
exports.default = new Ai(process.env.GOOGLE_API_KEY, process.env.AI_MODEL);
|
|
105
98
|
//# sourceMappingURL=ai.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai.service.js","sourceRoot":"","sources":["../../../../src/services/ai.service.ts"],"names":[],"mappings":";;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"ai.service.js","sourceRoot":"","sources":["../../../../src/services/ai.service.ts"],"names":[],"mappings":";;;;;;AACA,qFAA0D;AAC1D,+FAAoE;AACpE,kFAAsD;AACtD,8EAAkD;AAClD,kFAAsD;AAEtD,kDAA0B;AAC1B,yCAA2D;AAE3D,MAAa,EAAE;IAMb,YAAY,GAAW,EAAE,KAAa;QAEpC,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAW,CAAC;YAC9B,MAAM,EAAE,GAAG;SACZ,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAErB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,IAAwB,EAAE,OAA+B;QAExE,IAAI,IAAI,EAAE,CAAC;YAET,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAClC,MAAM,OAAO,GAAG,IAAA,eAAK,GAAE,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAEnF,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CA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,CAAC,GAAG;iBACjC;gBACD,gBAAgB,EAAE,kBAAkB;aACrC;YACD,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC;gBACvB,KAAK;gBACL,YAAY;gBACZ,OAAO;aACR,CAAC;SACH,CAAC,CAAA;QAEF,MAAM,4BAAc,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAE1L,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAK,CAAC,CAAC;QAEhD,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,KAAK,EAAE,CAAC;IAExC,CAAC;CAEF;AAvHD,gBAuHC;AACD,kBAAe,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,cAAwB,EAAE,OAAO,CAAC,GAAG,CAAC,QAAkB,CAAC,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CustomerPersonWithEmail } from '@lilaquadrat/interfaces';
|
|
2
|
-
import
|
|
2
|
+
import { GoogleGenAI } from '@google/genai';
|
|
3
3
|
export declare class SpamAnalasys {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
constructor(
|
|
4
|
+
provider: GoogleGenAI;
|
|
5
|
+
model: string;
|
|
6
|
+
constructor(key: string, model: string);
|
|
7
7
|
checkEmailDns(email: string): Promise<boolean>;
|
|
8
8
|
getDomainFromEMail(email: string): string | null;
|
|
9
9
|
check(person: CustomerPersonWithEmail, message: string): Promise<{
|
|
@@ -5,14 +5,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.SpamAnalasys = void 0;
|
|
7
7
|
const dns_1 = __importDefault(require("dns"));
|
|
8
|
-
const
|
|
8
|
+
const logger_js_1 = __importDefault(require("../logger.js"));
|
|
9
|
+
const genai_1 = require("@google/genai");
|
|
9
10
|
const dns = dns_1.default.promises;
|
|
10
11
|
class SpamAnalasys {
|
|
11
|
-
constructor(
|
|
12
|
-
if (
|
|
13
|
-
this.
|
|
12
|
+
constructor(key, model) {
|
|
13
|
+
if (key) {
|
|
14
|
+
this.provider = new genai_1.GoogleGenAI({
|
|
15
|
+
apiKey: key,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
logger_js_1.default.warn('NO_API_KEY');
|
|
14
20
|
}
|
|
15
|
-
this.
|
|
21
|
+
this.model = model;
|
|
16
22
|
}
|
|
17
23
|
async checkEmailDns(email) {
|
|
18
24
|
const domain = this.getDomainFromEMail(email);
|
|
@@ -49,52 +55,38 @@ class SpamAnalasys {
|
|
|
49
55
|
: null;
|
|
50
56
|
}
|
|
51
57
|
async check(person, message) {
|
|
52
|
-
const
|
|
53
|
-
model:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
{
|
|
57
|
-
role: 'system',
|
|
58
|
-
content: `i will provide the data as a json in this format:
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
"name": "LASTNAME",
|
|
62
|
-
"prename": "FIRSTNAME",
|
|
63
|
-
"message": "MESSAGE"
|
|
64
|
-
}
|
|
58
|
+
const response = await this.provider.models.generateContent({
|
|
59
|
+
model: this.model,
|
|
60
|
+
config: {
|
|
61
|
+
systemInstruction: `You are a strict B2B Lead Validation Agent. You will receive a JSON object: {name, prename, message}.
|
|
65
62
|
|
|
66
|
-
|
|
63
|
+
Evaluate the input based on two distinct criteria:
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
1. Identity Validation:
|
|
66
|
+
- Fail if 'name' or 'prename' are empty, clearly fake (e.g., "test", "admin", "123"), contain URLs, or are obvious gibberish.
|
|
70
67
|
|
|
71
|
-
|
|
68
|
+
2. Intent Validation:
|
|
69
|
+
- Pass only if the 'message' indicates a clear, human business intent (inquiry, support, sales, partnership).
|
|
70
|
+
- Fail if the message is promotional spam (SEO/Crypto), incoherent, automated, or lacks semantic meaning.
|
|
72
71
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
{
|
|
80
|
-
"useful": BOOLEAN,
|
|
81
|
-
"explanation": "EXPLANATION"
|
|
82
|
-
}`,
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
role: 'user',
|
|
86
|
-
content: JSON.stringify({
|
|
87
|
-
name: person.name,
|
|
88
|
-
prename: person.prename,
|
|
89
|
-
message,
|
|
90
|
-
}),
|
|
72
|
+
Output Instruction:
|
|
73
|
+
Return exactly one JSON object: {useful: BOOLEAN, explanation: STRING}.
|
|
74
|
+
- 'useful': true only if BOTH criteria pass.
|
|
75
|
+
- 'explanation': A concise, single-sentence justification.`,
|
|
76
|
+
thinkingConfig: {
|
|
77
|
+
thinkingLevel: genai_1.ThinkingLevel.MEDIUM,
|
|
91
78
|
},
|
|
92
|
-
|
|
79
|
+
responseMimeType: 'application/json'
|
|
80
|
+
},
|
|
81
|
+
contents: JSON.stringify({
|
|
82
|
+
name: person.name,
|
|
83
|
+
prename: person.prename,
|
|
84
|
+
message,
|
|
85
|
+
})
|
|
93
86
|
});
|
|
94
|
-
|
|
95
|
-
return response;
|
|
87
|
+
return JSON.parse(response.text);
|
|
96
88
|
}
|
|
97
89
|
}
|
|
98
90
|
exports.SpamAnalasys = SpamAnalasys;
|
|
99
|
-
exports.default = new SpamAnalasys(process.env.
|
|
91
|
+
exports.default = new SpamAnalasys(process.env.GOOGLE_API_KEY, process.env.AI_MODEL);
|
|
100
92
|
//# sourceMappingURL=spamAnalasys.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spamAnalasys.service.js","sourceRoot":"","sources":["../../../../src/services/spamAnalasys.service.ts"],"names":[],"mappings":";;;;;;AAEA,8CAA+B;AAC/B,
|
|
1
|
+
{"version":3,"file":"spamAnalasys.service.js","sourceRoot":"","sources":["../../../../src/services/spamAnalasys.service.ts"],"names":[],"mappings":";;;;;;AAEA,8CAA+B;AAC/B,6DAAkC;AAClC,yCAA2D;AAE3D,MAAM,GAAG,GAAG,aAAY,CAAC,QAAQ,CAAC;AAElC,MAAa,YAAY;IAMvB,YAAY,GAAW,EAAE,KAAa;QAEpC,IAAI,GAAG,EAAE,CAAC;YAER,IAAI,CAAC,QAAQ,GAAG,IAAI,mBAAW,CAAC;gBAC9B,MAAM,EAAE,GAAG;aACZ,CAAC,CAAC;QAEL,CAAC;aAAM,CAAC;YAEN,mBAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAE5B,CAAC;QAED,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAErB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,KAAa;QAE/B,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC9C,IAAI,OAAmB,CAAC;QACxB,IAAI,EAA2B,CAAC;QAChC,IAAI,GAAuB,CAAC;QAE5B,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAE1B,IAAI,CAAC;YAEH,OAAO,GAAG,MAAM,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACvC,EAAE,GAAG,MAAM,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAEf,OAAO,KAAK,CAAC;QAEf,CAAC;QAED,IAAI,CAAC,EAAE,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAE7B,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAEzB,MAAM,CAAC,GAAG,CAAC,CAA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GAAG,CAAC,QAAkB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lilaquadrat/studio",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.23.0",
|
|
4
4
|
"description": "classes and tools for STUDIO",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://lilaquadrat.de",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"@azure/storage-blob": "^12.17.0",
|
|
75
75
|
"@azure/storage-file-share": "^12.17.0",
|
|
76
76
|
"@azure/storage-queue": "^12.28.1",
|
|
77
|
+
"@google/genai": "^1.42.0",
|
|
77
78
|
"@lilaquadrat/interfaces": "^1.36.0",
|
|
78
79
|
"@root/acme": "^3.1.0",
|
|
79
80
|
"@root/csr": "^0.8.1",
|
|
@@ -91,13 +92,11 @@
|
|
|
91
92
|
"handlebars": "^4.7.6",
|
|
92
93
|
"i18n-iso-countries": "^7.13.0",
|
|
93
94
|
"mime-types": "^2.1.32",
|
|
94
|
-
"minio": "^8.0.6",
|
|
95
95
|
"mongo-connection-string": "^0.1.5",
|
|
96
96
|
"mongodb": "^6.16.0",
|
|
97
97
|
"multer": "^1.4.5-lts.1",
|
|
98
98
|
"node-fetch": "^2",
|
|
99
99
|
"object-path": "^0.11.8",
|
|
100
|
-
"openai": "^6.16.0",
|
|
101
100
|
"optional-require": "^1.1.0",
|
|
102
101
|
"prettyjson": "^1.2.1",
|
|
103
102
|
"stripe": "^17.7.0",
|