Skip to content

Commit 4ec3840

Browse files
committed
fix(ai): possibilité d'avoir plusieurs fichiers sources pour le RAG
1 parent 7a8d237 commit 4ec3840

3 files changed

Lines changed: 32 additions & 13 deletions

File tree

app/js/ai/rag/engine.mjs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { yaml } from "../../markdown/custom/yaml.mjs";
22
import { handleURL } from "../../utils/urls.mjs";
33
import { createVector } from "../../utils/nlp.mjs";
44
import { localRAGinformations } from "./sources.mjs";
5+
import {
6+
fetchContent,
7+
fetchContentFromMultipleSources,
8+
} from "../../core/chatbot/helpers/fetch.mjs";
59

610
function prepareRAGdata(informations, separator) {
711
if (separator) {
@@ -51,17 +55,32 @@ function createVectorRAGinformations(informations) {
5155
}
5256
}
5357

54-
export function getRAGcontent(informations) {
58+
export async function getRAGcontent(informations) {
5559
if (informations) {
56-
if (informations.includes("http")) {
57-
const urlRAGfile = handleURL(informations, { useCorsProxy: true });
58-
fetch(urlRAGfile)
59-
.then((response) => response.text())
60-
.then((data) => {
61-
RAGcontent = prepareRAGdata(data, yaml.useLLM.RAGseparator);
62-
const RAGvectors = createVectorRAGinformations(RAGcontent);
63-
return RAGvectors;
64-
});
60+
const isArray = Array.isArray(informations);
61+
if (isArray || informations.includes("http")) {
62+
let sourceRAG;
63+
if (isArray) {
64+
sourceRAG = informations.map((element) =>
65+
handleURL(element, { useCorsProxy: true }),
66+
);
67+
} else {
68+
sourceRAG = handleURL(informations, { useCorsProxy: true });
69+
}
70+
try {
71+
const data = isArray
72+
? await fetchContentFromMultipleSources(sourceRAG)
73+
: await fetchContent(sourceRAG);
74+
RAGcontent = prepareRAGdata(data, yaml.useLLM.RAGseparator);
75+
const RAGvectors = createVectorRAGinformations(RAGcontent);
76+
return RAGvectors;
77+
} catch (error) {
78+
console.error(
79+
"Erreur lors du fetch ou du traitement des données RAG :",
80+
error,
81+
);
82+
return null;
83+
}
6584
} else {
6685
let RAGinformations;
6786
if (informations.toString().includes("useFile")) {

app/script.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/script.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)