From 40ec3ed52b04e4475173f93c0bceb33ee76b5981 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Thu, 5 Dec 2024 09:04:33 -0800 Subject: [PATCH] feat(core): Attempt to automatically read Deno env vars (#7321) --- langchain-core/src/utils/env.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/langchain-core/src/utils/env.ts b/langchain-core/src/utils/env.ts index 15639cb471a3..3b8d5153847a 100644 --- a/langchain-core/src/utils/env.ts +++ b/langchain-core/src/utils/env.ts @@ -5,6 +5,9 @@ declare global { version: { deno: string; }; + env: { + get: (name: string) => string | undefined; + }; } | undefined; } @@ -78,10 +81,14 @@ export function getEnvironmentVariable(name: string): string | undefined { // Certain Deno setups will throw an error if you try to access environment variables // https://github.com/langchain-ai/langchainjs/issues/1412 try { - return typeof process !== "undefined" - ? // eslint-disable-next-line no-process-env - process.env?.[name] - : undefined; + if (typeof process !== "undefined") { + // eslint-disable-next-line no-process-env + return process.env?.[name]; + } else if (isDeno()) { + return Deno?.env.get(name); + } else { + return undefined; + } } catch (e) { return undefined; }