Refactored and moved all keys and configuration into .env files and provided samples
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
import { OpenAIEmbeddings, AzureOpenAIEmbeddings } from "@langchain/openai";
|
||||
|
||||
const query = process.argv[2] || "What is CX Automation?";
|
||||
const company = process.argv[3] || "default";
|
||||
|
||||
// the RAG widget uses the OpenAIEmbeddings class but the config will not work because you cannot pass in the api-version param. DO NOT USE
|
||||
// const embedding = new OpenAIEmbeddings({
|
||||
@@ -34,11 +35,25 @@ function getSourceId(document) {
|
||||
if (document.metadata) {
|
||||
const mergedMetadata = Object.values(document.metadata).join("");
|
||||
const metatDataObj = JSON.parse(mergedMetadata);
|
||||
return metatDataObj.source;
|
||||
} else return undefined;
|
||||
}
|
||||
|
||||
const resultDocuments = await store.similaritySearch(query);
|
||||
if ("sourceURL" in metatDataObj) {
|
||||
return metatDataObj.sourceURL;
|
||||
}
|
||||
if ("source" in metatDataObj) {
|
||||
return metatDataObj.source;
|
||||
}
|
||||
if ("source_id" in metatDataObj) {
|
||||
return metatDataObj.source_id;
|
||||
}
|
||||
if ("sourceName" in metatDataObj) {
|
||||
return metatDataObj.sourceName;
|
||||
}
|
||||
} else return "no source found";
|
||||
}
|
||||
const filter = {
|
||||
filterExpression: `search.in(company, '${company}')`,
|
||||
};
|
||||
const resultDocuments = await store.similaritySearch(query, 20, filter);
|
||||
const sources = resultDocuments.map((doc) => ({
|
||||
source_id: getSourceId(doc),
|
||||
text: doc.pageContent,
|
||||
|
||||
Reference in New Issue
Block a user