@digipair/skill-chatbot 0.1.5 → 0.1.7
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
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
|
}),
|
@@ -40931,7 +40928,7 @@ let ChatbotService = class ChatbotService {
|
|
40931
40928
|
}
|
40932
40929
|
return results;
|
40933
40930
|
}
|
40934
|
-
async updateSummary(baseUrl, session, messages, options) {
|
40931
|
+
async updateSummary(baseUrl, prompt, session, messages, options) {
|
40935
40932
|
const [summary] = await this.searchDocuments(baseUrl, session, `is_parent = true and userQuery() order by date desc limit 1`, {
|
40936
40933
|
query: 'role:"system"'
|
40937
40934
|
});
|
@@ -40942,15 +40939,6 @@ let ChatbotService = class ChatbotService {
|
|
40942
40939
|
});
|
40943
40940
|
const history1 = messages.sort((a, b)=>a - b).map(({ role, content })=>`${role}: ${content}`).join('\n');
|
40944
40941
|
const date = messages.reduce((acc, { date })=>Math.max(acc, date), 0);
|
40945
|
-
const prompt = `
|
40946
|
-
Résumé de l'historique la conversation:
|
40947
|
-
${summary.content}
|
40948
|
-
|
40949
|
-
Nouveaux messages:
|
40950
|
-
${history1}
|
40951
|
-
|
40952
|
-
Résumer dans un texte court, précis et concis l'historique de la conversation en prenant en compte les nouveaux messages.
|
40953
|
-
`;
|
40954
40942
|
const chain = RunnableSequence.from([
|
40955
40943
|
PromptTemplate.fromTemplate(prompt),
|
40956
40944
|
model
|
@@ -40972,12 +40960,12 @@ let ChatbotService = class ChatbotService {
|
|
40972
40960
|
document
|
40973
40961
|
]);
|
40974
40962
|
}
|
40975
|
-
async updateHistory(baseUrl, session, memory, options) {
|
40963
|
+
async updateHistory(baseUrl, promptSummary, session, memory, options) {
|
40976
40964
|
// add new messages
|
40977
40965
|
const documents = await this.prepareHistory(memory);
|
40978
40966
|
await this.pushDocuments(baseUrl, session, documents);
|
40979
40967
|
// update summary
|
40980
|
-
await this.updateSummary(baseUrl, session, memory, options);
|
40968
|
+
await this.updateSummary(baseUrl, promptSummary, session, memory, options);
|
40981
40969
|
}
|
40982
40970
|
async history(params, _pins, context) {
|
40983
40971
|
var _context_private;
|
@@ -41056,7 +41044,14 @@ let ChatbotService = class ChatbotService {
|
|
41056
41044
|
var _context_private, _context_private1, _input_boost;
|
41057
41045
|
const session = `${context.request.digipair}-${context.request.body.userId}`;
|
41058
41046
|
var _context_private_OLLAMA_SERVER, _context_private_VESPA_SERVER;
|
41059
|
-
const { modelName = 'mistral', temperature = 0, baseUrlOllama = (_context_private_OLLAMA_SERVER = (_context_private = context.private) == null ? void 0 : _context_private.OLLAMA_SERVER) != null ? _context_private_OLLAMA_SERVER : OLLAMA_SERVER, baseUrlVespa = (_context_private_VESPA_SERVER = (_context_private1 = context.private) == null ? void 0 : _context_private1.VESPA_SERVER) != null ? _context_private_VESPA_SERVER : VESPA_SERVER,
|
41047
|
+
const { modelName = 'mistral', temperature = 0, baseUrlOllama = (_context_private_OLLAMA_SERVER = (_context_private = context.private) == null ? void 0 : _context_private.OLLAMA_SERVER) != null ? _context_private_OLLAMA_SERVER : OLLAMA_SERVER, baseUrlVespa = (_context_private_VESPA_SERVER = (_context_private1 = context.private) == null ? void 0 : _context_private1.VESPA_SERVER) != null ? _context_private_VESPA_SERVER : VESPA_SERVER, promptSummary = `
|
41048
|
+
Résumé de l'historique la conversation:
|
41049
|
+
{summary}
|
41050
|
+
|
41051
|
+
Nouveaux messages:
|
41052
|
+
{history}
|
41053
|
+
|
41054
|
+
Résumer dans un texte court, précis et concis l'historique de la conversation en prenant en compte les nouveaux messages.`, assistant, command, sources, logs } = params;
|
41060
41055
|
const input = context.request.body;
|
41061
41056
|
const date = Date.now();
|
41062
41057
|
var _input_inputs;
|
@@ -41094,7 +41089,7 @@ let ChatbotService = class ChatbotService {
|
|
41094
41089
|
date: date + index
|
41095
41090
|
}));
|
41096
41091
|
// Asynchronous history update
|
41097
|
-
this.updateHistory(baseUrlVespa, session, memory, {
|
41092
|
+
this.updateHistory(baseUrlVespa, promptSummary, session, memory, {
|
41098
41093
|
modelName,
|
41099
41094
|
temperature,
|
41100
41095
|
baseUrl: baseUrlOllama
|
@@ -41111,6 +41106,9 @@ let ChatbotService = class ChatbotService {
|
|
41111
41106
|
const result = await executePinsList(pinsSettingsList, context);
|
41112
41107
|
return result;
|
41113
41108
|
}
|
41109
|
+
constructor(){
|
41110
|
+
this.embeddingsModel = null;
|
41111
|
+
}
|
41114
41112
|
};
|
41115
41113
|
const history = (params, pinsSettingsList, context)=>new ChatbotService().history(params, pinsSettingsList, context);
|
41116
41114
|
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
|
}),
|
@@ -40909,7 +40906,7 @@ let ChatbotService = class ChatbotService {
|
|
40909
40906
|
}
|
40910
40907
|
return results;
|
40911
40908
|
}
|
40912
|
-
async updateSummary(baseUrl, session, messages, options) {
|
40909
|
+
async updateSummary(baseUrl, prompt, session, messages, options) {
|
40913
40910
|
const [summary] = await this.searchDocuments(baseUrl, session, `is_parent = true and userQuery() order by date desc limit 1`, {
|
40914
40911
|
query: 'role:"system"'
|
40915
40912
|
});
|
@@ -40920,15 +40917,6 @@ let ChatbotService = class ChatbotService {
|
|
40920
40917
|
});
|
40921
40918
|
const history1 = messages.sort((a, b)=>a - b).map(({ role, content })=>`${role}: ${content}`).join('\n');
|
40922
40919
|
const date = messages.reduce((acc, { date })=>Math.max(acc, date), 0);
|
40923
|
-
const prompt = `
|
40924
|
-
Résumé de l'historique la conversation:
|
40925
|
-
${summary.content}
|
40926
|
-
|
40927
|
-
Nouveaux messages:
|
40928
|
-
${history1}
|
40929
|
-
|
40930
|
-
Résumer dans un texte court, précis et concis l'historique de la conversation en prenant en compte les nouveaux messages.
|
40931
|
-
`;
|
40932
40920
|
const chain = RunnableSequence.from([
|
40933
40921
|
PromptTemplate.fromTemplate(prompt),
|
40934
40922
|
model
|
@@ -40950,12 +40938,12 @@ let ChatbotService = class ChatbotService {
|
|
40950
40938
|
document
|
40951
40939
|
]);
|
40952
40940
|
}
|
40953
|
-
async updateHistory(baseUrl, session, memory, options) {
|
40941
|
+
async updateHistory(baseUrl, promptSummary, session, memory, options) {
|
40954
40942
|
// add new messages
|
40955
40943
|
const documents = await this.prepareHistory(memory);
|
40956
40944
|
await this.pushDocuments(baseUrl, session, documents);
|
40957
40945
|
// update summary
|
40958
|
-
await this.updateSummary(baseUrl, session, memory, options);
|
40946
|
+
await this.updateSummary(baseUrl, promptSummary, session, memory, options);
|
40959
40947
|
}
|
40960
40948
|
async history(params, _pins, context) {
|
40961
40949
|
var _context_private;
|
@@ -41034,7 +41022,14 @@ let ChatbotService = class ChatbotService {
|
|
41034
41022
|
var _context_private, _context_private1, _input_boost;
|
41035
41023
|
const session = `${context.request.digipair}-${context.request.body.userId}`;
|
41036
41024
|
var _context_private_OLLAMA_SERVER, _context_private_VESPA_SERVER;
|
41037
|
-
const { modelName = 'mistral', temperature = 0, baseUrlOllama = (_context_private_OLLAMA_SERVER = (_context_private = context.private) == null ? void 0 : _context_private.OLLAMA_SERVER) != null ? _context_private_OLLAMA_SERVER : OLLAMA_SERVER, baseUrlVespa = (_context_private_VESPA_SERVER = (_context_private1 = context.private) == null ? void 0 : _context_private1.VESPA_SERVER) != null ? _context_private_VESPA_SERVER : VESPA_SERVER,
|
41025
|
+
const { modelName = 'mistral', temperature = 0, baseUrlOllama = (_context_private_OLLAMA_SERVER = (_context_private = context.private) == null ? void 0 : _context_private.OLLAMA_SERVER) != null ? _context_private_OLLAMA_SERVER : OLLAMA_SERVER, baseUrlVespa = (_context_private_VESPA_SERVER = (_context_private1 = context.private) == null ? void 0 : _context_private1.VESPA_SERVER) != null ? _context_private_VESPA_SERVER : VESPA_SERVER, promptSummary = `
|
41026
|
+
Résumé de l'historique la conversation:
|
41027
|
+
{summary}
|
41028
|
+
|
41029
|
+
Nouveaux messages:
|
41030
|
+
{history}
|
41031
|
+
|
41032
|
+
Résumer dans un texte court, précis et concis l'historique de la conversation en prenant en compte les nouveaux messages.`, assistant, command, sources, logs } = params;
|
41038
41033
|
const input = context.request.body;
|
41039
41034
|
const date = Date.now();
|
41040
41035
|
var _input_inputs;
|
@@ -41072,7 +41067,7 @@ let ChatbotService = class ChatbotService {
|
|
41072
41067
|
date: date + index
|
41073
41068
|
}));
|
41074
41069
|
// Asynchronous history update
|
41075
|
-
this.updateHistory(baseUrlVespa, session, memory, {
|
41070
|
+
this.updateHistory(baseUrlVespa, promptSummary, session, memory, {
|
41076
41071
|
modelName,
|
41077
41072
|
temperature,
|
41078
41073
|
baseUrl: baseUrlOllama
|
@@ -41089,6 +41084,9 @@ let ChatbotService = class ChatbotService {
|
|
41089
41084
|
const result = await executePinsList(pinsSettingsList, context);
|
41090
41085
|
return result;
|
41091
41086
|
}
|
41087
|
+
constructor(){
|
41088
|
+
this.embeddingsModel = null;
|
41089
|
+
}
|
41092
41090
|
};
|
41093
41091
|
const history = (params, pinsSettingsList, context)=>new ChatbotService().history(params, pinsSettingsList, context);
|
41094
41092
|
const find = (params, pinsSettingsList, context)=>new ChatbotService().find(params, pinsSettingsList, context);
|
package/package.json
CHANGED
File without changes
|
File without changes
|