mirror of https://github.com/hwchase17/langchain
Harrison/cleanup env check (#144)
parent
a4b502d92f
commit
b504cd739f
@ -0,0 +1,17 @@
|
|||||||
|
"""Generic utility functions."""
|
||||||
|
import os
|
||||||
|
from typing import Any, Dict
|
||||||
|
|
||||||
|
|
||||||
|
def get_from_dict_or_env(data: Dict[str, Any], key: str, env_key: str) -> str:
|
||||||
|
"""Get a value from a dictionary or an environment variable."""
|
||||||
|
if key in data and data[key]:
|
||||||
|
return data[key]
|
||||||
|
elif env_key in os.environ and os.environ[env_key]:
|
||||||
|
return os.environ[env_key]
|
||||||
|
else:
|
||||||
|
raise ValueError(
|
||||||
|
f"Did not find {key}, please add an environment variable"
|
||||||
|
f" `{env_key}` which contains it, or pass"
|
||||||
|
f" `{key}` as a named parameter."
|
||||||
|
)
|
Loading…
Reference in New Issue