Skip to content

Commit

Permalink
feat(core): Attempt to automatically read Deno env vars (#7321)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Dec 5, 2024
1 parent da149c5 commit 40ec3ed
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions langchain-core/src/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ declare global {
version: {
deno: string;
};
env: {
get: (name: string) => string | undefined;
};
}
| undefined;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 40ec3ed

Please sign in to comment.