@@ -2,6 +2,10 @@ import { yaml } from "../../markdown/custom/yaml.mjs";
22import { handleURL } from "../../utils/urls.mjs" ;
33import { createVector } from "../../utils/nlp.mjs" ;
44import { localRAGinformations } from "./sources.mjs" ;
5+ import {
6+ fetchContent ,
7+ fetchContentFromMultipleSources ,
8+ } from "../../core/chatbot/helpers/fetch.mjs" ;
59
610function 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" ) ) {
0 commit comments