Refactored and moved all keys and configuration into .env files and provided samples
This commit is contained in:
16
retriever/.env.sample
Normal file
16
retriever/.env.sample
Normal file
@@ -0,0 +1,16 @@
|
||||
# Azure AI Search connection settings
|
||||
AZURE_AISEARCH_ENDPOINT=https://iva-demo-vector-service.search.windows.net
|
||||
AZURE_AISEARCH_KEY=your-azure-search-key
|
||||
AZURE_AISEARCH_INDEX_NAME=iva-vector-demo
|
||||
|
||||
# If you're using Azure OpenAI API, you'll need to set these variables
|
||||
AZURE_OPENAI_API_KEY=your-azure-openai-key
|
||||
AZURE_OPENAI_API_INSTANCE_NAME=iva-open-ai
|
||||
AZURE_OPENAI_API_DEPLOYMENT_NAME=text-embedding-3-small
|
||||
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=
|
||||
AZURE_OPENAI_API_VERSION=2024-08-01-preview
|
||||
|
||||
# Or you can use the OpenAI API directly
|
||||
OPENAI_API_KEY=
|
||||
DEBUG=true
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "node --env-file=.env index.js \"What is Verint?\""
|
||||
"test": "node --env-file=.env index.js \"What is Verint?\" \"Verint\""
|
||||
},
|
||||
"author": "",
|
||||
"license": "MIT",
|
||||
|
||||
Reference in New Issue
Block a user