You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/baseai/src/utils/memory/generate-openai-embeddings.ts
+18-2Lines changed: 18 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,32 @@
1
1
import*aspfrom'@clack/prompts';
2
2
import{getEncoding}from'js-tiktoken';
3
3
importOpenAIfrom'openai';
4
+
import{loadConfig}from'../config/config-handler';
5
+
import{cyan}from'../formatting';
4
6
import{MEMORYSETS}from'./constants';
5
7
6
8
exportconstgetOpenAIEmbeddings=async(
7
9
chunks: string[]
8
10
): Promise<OpenAI.Embeddings.Embedding[]>=>{
9
-
constopenAiKey=process.env.OPENAI_API_KEY;
11
+
constconfig=awaitloadConfig();
12
+
constconfigEnv=config?.env;
13
+
14
+
constgetEnv=(key: string): string|undefined=>{
15
+
letvalue: string|undefined;
16
+
if(configEnv&&keyinconfigEnv){
17
+
value=configEnv[keyaskeyoftypeofconfigEnv];
18
+
}else{
19
+
value=process.env[key];
20
+
}
21
+
22
+
returnvalue;
23
+
};
24
+
25
+
constopenAiKey=getEnv('OPENAI_API_KEY');
10
26
11
27
if(!openAiKey){
12
28
p.cancel(
13
-
'OpenAI key not found. Please set the OPENAI_API_KEY environment variable. Only required locally, in production, add it to your keysets https://langbase.com/docs/features/keysets'
29
+
`Environment variable ${cyan(`OPENAI_API_KEY`)} is not set or empty. Only needed in local dev environment. \nNote: In production, add it to your keysets https://langbase.com/docs/features/keysets\n`
0 commit comments