Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Attempt to automatically read Deno env vars #7321

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading