From 33dd197483e0c24fc192ce15572883675321e90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 19 Aug 2023 10:19:29 +0200 Subject: [PATCH 1/2] Use correct env var name for AI key --- embeddings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/embeddings.js b/embeddings.js index 69f81d8..e94d45c 100644 --- a/embeddings.js +++ b/embeddings.js @@ -45,6 +45,7 @@ export const search_index = FaissStore.fromDocuments( export const getChain = (res) => { return loadQAStuffChain( new OpenAIChat({ + openAIApiKey: process.env['_APP_ASSISTANT_OPENAI_API_KEY'] ?? undefined, temperature: 0.6, max_tokens: 1000, streaming: true, From e32a9343d0907d2a3cd714b902aa3c3d3e363e03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 19 Aug 2023 11:08:26 +0200 Subject: [PATCH 2/2] Add API key to constructor --- embeddings.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/embeddings.js b/embeddings.js index e94d45c..518829f 100644 --- a/embeddings.js +++ b/embeddings.js @@ -8,6 +8,8 @@ import { OpenAIChat } from "langchain/llms/openai"; import { Document } from "langchain/document"; import { CharacterTextSplitter } from "langchain/text_splitter"; +const apiKey = process.env['_APP_ASSISTANT_OPENAI_API_KEY'] ?? undefined; + async function chunk_sources(sources) { const source_chunks = []; const splitter = new CharacterTextSplitter({ @@ -40,12 +42,14 @@ const sources = globSync("docs/*.json").map((filename) => { export const search_index = FaissStore.fromDocuments( await chunk_sources(sources), - new OpenAIEmbeddings() + new OpenAIEmbeddings({ + openAIApiKey: apiKey + }) ); export const getChain = (res) => { return loadQAStuffChain( new OpenAIChat({ - openAIApiKey: process.env['_APP_ASSISTANT_OPENAI_API_KEY'] ?? undefined, + openAIApiKey: apiKey, temperature: 0.6, max_tokens: 1000, streaming: true,