@digipair/skill-chatbot 0.1.5 → 0.1.6
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.cjs2.js +13 -13
- package/index.esm2.js +13 -13
- package/package.json +1 -1
package/index.cjs2.js
CHANGED
@@ -40867,14 +40867,10 @@ let ChatbotService = class ChatbotService {
|
|
40867
40867
|
}));
|
40868
40868
|
});
|
40869
40869
|
const chunks = await Promise.all(chunksPromises);
|
40870
|
-
const
|
40870
|
+
const documents = [
|
40871
40871
|
...parents,
|
40872
40872
|
...chunks.flat()
|
40873
40873
|
];
|
40874
|
-
const embeddings = await this.embeddings(result.map((document)=>document.content));
|
40875
|
-
const documents = result.map((document, index)=>_extends({}, document, {
|
40876
|
-
content_embedding: embeddings[index]
|
40877
|
-
}));
|
40878
40874
|
return [
|
40879
40875
|
...history1.filter(({ role })=>role === 'system').map((document)=>{
|
40880
40876
|
const uuid = v4();
|
@@ -40888,22 +40884,23 @@ let ChatbotService = class ChatbotService {
|
|
40888
40884
|
];
|
40889
40885
|
}
|
40890
40886
|
async embedding(text) {
|
40891
|
-
|
40892
|
-
|
40893
|
-
|
40894
|
-
|
40895
|
-
|
40896
|
-
|
40897
|
-
|
40898
|
-
return Promise.all(texts.map((text)=>this.embedding(text)));
|
40887
|
+
if (!this.embeddingsModel) {
|
40888
|
+
const { HuggingFaceTransformersEmbeddings } = await eval(`import('@langchain/community/embeddings/hf_transformers')`);
|
40889
|
+
this.embeddingsModel = new HuggingFaceTransformersEmbeddings({
|
40890
|
+
modelName: 'Xenova/multilingual-e5-large'
|
40891
|
+
});
|
40892
|
+
}
|
40893
|
+
return await this.embeddingsModel.embedQuery(text);
|
40899
40894
|
}
|
40900
40895
|
async pushDocuments(baseUrl, session, documents) {
|
40901
40896
|
const results = [];
|
40902
40897
|
for (const document of documents){
|
40898
|
+
const content_embedding = document.role === 'system' ? undefined : await this.embedding(document.content);
|
40903
40899
|
const response = await fetch(`${baseUrl}/document/v1/Digipair_default/history/docid/${document.uuid}`, {
|
40904
40900
|
method: 'POST',
|
40905
40901
|
body: JSON.stringify({
|
40906
40902
|
fields: _extends({}, document, {
|
40903
|
+
content_embedding,
|
40907
40904
|
session
|
40908
40905
|
})
|
40909
40906
|
}),
|
@@ -41111,6 +41108,9 @@ let ChatbotService = class ChatbotService {
|
|
41111
41108
|
const result = await executePinsList(pinsSettingsList, context);
|
41112
41109
|
return result;
|
41113
41110
|
}
|
41111
|
+
constructor(){
|
41112
|
+
this.embeddingsModel = null;
|
41113
|
+
}
|
41114
41114
|
};
|
41115
41115
|
const history = (params, pinsSettingsList, context)=>new ChatbotService().history(params, pinsSettingsList, context);
|
41116
41116
|
const find = (params, pinsSettingsList, context)=>new ChatbotService().find(params, pinsSettingsList, context);
|
package/index.esm2.js
CHANGED
@@ -40845,14 +40845,10 @@ let ChatbotService = class ChatbotService {
|
|
40845
40845
|
}));
|
40846
40846
|
});
|
40847
40847
|
const chunks = await Promise.all(chunksPromises);
|
40848
|
-
const
|
40848
|
+
const documents = [
|
40849
40849
|
...parents,
|
40850
40850
|
...chunks.flat()
|
40851
40851
|
];
|
40852
|
-
const embeddings = await this.embeddings(result.map((document)=>document.content));
|
40853
|
-
const documents = result.map((document, index)=>_extends({}, document, {
|
40854
|
-
content_embedding: embeddings[index]
|
40855
|
-
}));
|
40856
40852
|
return [
|
40857
40853
|
...history1.filter(({ role })=>role === 'system').map((document)=>{
|
40858
40854
|
const uuid = v4();
|
@@ -40866,22 +40862,23 @@ let ChatbotService = class ChatbotService {
|
|
40866
40862
|
];
|
40867
40863
|
}
|
40868
40864
|
async embedding(text) {
|
40869
|
-
|
40870
|
-
|
40871
|
-
|
40872
|
-
|
40873
|
-
|
40874
|
-
|
40875
|
-
|
40876
|
-
return Promise.all(texts.map((text)=>this.embedding(text)));
|
40865
|
+
if (!this.embeddingsModel) {
|
40866
|
+
const { HuggingFaceTransformersEmbeddings } = await eval(`import('@langchain/community/embeddings/hf_transformers')`);
|
40867
|
+
this.embeddingsModel = new HuggingFaceTransformersEmbeddings({
|
40868
|
+
modelName: 'Xenova/multilingual-e5-large'
|
40869
|
+
});
|
40870
|
+
}
|
40871
|
+
return await this.embeddingsModel.embedQuery(text);
|
40877
40872
|
}
|
40878
40873
|
async pushDocuments(baseUrl, session, documents) {
|
40879
40874
|
const results = [];
|
40880
40875
|
for (const document of documents){
|
40876
|
+
const content_embedding = document.role === 'system' ? undefined : await this.embedding(document.content);
|
40881
40877
|
const response = await fetch(`${baseUrl}/document/v1/Digipair_default/history/docid/${document.uuid}`, {
|
40882
40878
|
method: 'POST',
|
40883
40879
|
body: JSON.stringify({
|
40884
40880
|
fields: _extends({}, document, {
|
40881
|
+
content_embedding,
|
40885
40882
|
session
|
40886
40883
|
})
|
40887
40884
|
}),
|
@@ -41089,6 +41086,9 @@ let ChatbotService = class ChatbotService {
|
|
41089
41086
|
const result = await executePinsList(pinsSettingsList, context);
|
41090
41087
|
return result;
|
41091
41088
|
}
|
41089
|
+
constructor(){
|
41090
|
+
this.embeddingsModel = null;
|
41091
|
+
}
|
41092
41092
|
};
|
41093
41093
|
const history = (params, pinsSettingsList, context)=>new ChatbotService().history(params, pinsSettingsList, context);
|
41094
41094
|
const find = (params, pinsSettingsList, context)=>new ChatbotService().find(params, pinsSettingsList, context);
|