@postalsys/email-ai-tools 1.3.1 → 1.3.2
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/index.js +1 -1
- package/lib/generate-embeddings.js +11 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { generateSummary, DEFAULT_SYSTEM_PROMPT, DEFAULT_USER_PROMPT } = require('./lib/generate-summary');
|
|
4
4
|
const riskAnalysis = require('./lib/risk-analysis');
|
|
5
|
-
const generateEmbeddings = require('./lib/generate-embeddings');
|
|
5
|
+
const { generateEmbeddings } = require('./lib/generate-embeddings');
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
generateSummary,
|
|
@@ -122,19 +122,26 @@ class Embedder {
|
|
|
122
122
|
return res.join(' ');
|
|
123
123
|
})
|
|
124
124
|
.filter(val => val)
|
|
125
|
-
.join('
|
|
125
|
+
.join(' ; ');
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
getChunks() {
|
|
129
129
|
let headerLines = [];
|
|
130
130
|
for (let [key, value] of this.addressHeaders.entries()) {
|
|
131
|
-
headerLines.push(`${key}: ${value}`);
|
|
131
|
+
headerLines.push(`${key}: ${value.replace(/\s/g, ' ')}`);
|
|
132
132
|
}
|
|
133
133
|
if (this.subject) {
|
|
134
134
|
headerLines.push(`subject: ${this.subject}`);
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
if (this.message.attachments?.length) {
|
|
138
|
+
let attachments = this.message.attachments.map(attachment => attachment.filename?.replace(/\s/g, ' ').trim()).filter(val => val);
|
|
139
|
+
if (attachments.length) {
|
|
140
|
+
headerLines.push(`attachments: ${attachments.join(' ; ')}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
let prompt = `${headerLines.join('\n')}\n\n`;
|
|
138
145
|
|
|
139
146
|
let prefixTokens = tokenizer.encode(prompt);
|
|
140
147
|
// If prefix is very large, then use larger chunks, so that each chunk contains at least 200 tokens of text
|
|
@@ -144,7 +151,7 @@ class Embedder {
|
|
|
144
151
|
|
|
145
152
|
let textChunks = [];
|
|
146
153
|
if (this.text) {
|
|
147
|
-
let textTokens = tokenizer.encode(this.text);
|
|
154
|
+
let textTokens = tokenizer.encode(this.text.replace(/[\r\n]+/g, '\n'));
|
|
148
155
|
|
|
149
156
|
let pos = 0;
|
|
150
157
|
while (pos < textTokens.bpe.length) {
|