(message)
| 43 | } |
| 44 | // 10. Define search engine function |
| 45 | async function searchEngineForSources(message) { |
| 46 | console.log(`3. Initializing Search Engine Process`); |
| 47 | // 11. Initialize BraveSearch |
| 48 | const loader = new BraveSearch({ apiKey: process.env.BRAVE_SEARCH_API_KEY }); |
| 49 | // 12. Rephrase the message |
| 50 | const rephrasedMessage = await rephraseInput(message); |
| 51 | console.log(`6. Rephrased message and got documents from BraveSearch`); |
| 52 | // 13. Get documents from BraveSearch |
| 53 | const docs = await loader.call(rephrasedMessage, { count: numberOfPagesToScan }); |
| 54 | // 14. Normalize data |
| 55 | const normalizedData = normalizeData(docs); |
| 56 | // 15. Process and vectorize the content |
| 57 | return await Promise.all(normalizedData.map(fetchAndProcess)); |
| 58 | } |
| 59 | // 16. Normalize data |
| 60 | function normalizeData(docs) { |
| 61 | return JSON.parse(docs) |
no test coverage detected