mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
fix(core): Ignore missing secrets on deserialization (#30252)
This commit is contained in:
parent
ebea5e014d
commit
e9c1765967
@ -98,8 +98,7 @@ class Reviver:
|
||||
else:
|
||||
if self.secrets_from_env and key in os.environ and os.environ[key]:
|
||||
return os.environ[key]
|
||||
msg = f'Missing key "{key}" in load(secrets_map)'
|
||||
raise KeyError(msg)
|
||||
return None
|
||||
|
||||
if (
|
||||
value.get("lc") == 1
|
||||
|
@ -167,3 +167,13 @@ def test_load_llmchain_with_non_serializable_arg() -> None:
|
||||
chain_obj = dumpd(chain)
|
||||
with pytest.raises(NotImplementedError):
|
||||
load(chain_obj, secrets_map={"OPENAI_API_KEY": "hello"})
|
||||
|
||||
|
||||
@pytest.mark.requires("openai", "langchain_openai")
|
||||
def test_loads_with_missing_secrets() -> None:
|
||||
import openai
|
||||
|
||||
llm_string = '{"lc": 1, "type": "constructor", "id": ["langchain", "llms", "openai", "OpenAI"], "kwargs": {"model_name": "davinci", "temperature": 0.5, "max_tokens": 256, "top_p": 0.8, "n": 1, "best_of": 1, "openai_api_key": {"lc": 1, "type": "secret", "id": ["OPENAI_API_KEY"]}, "batch_size": 20, "max_retries": 2, "disallowed_special": "all"}, "name": "OpenAI"}' # noqa: E501
|
||||
# Should throw on instantiation, not deserialization
|
||||
with pytest.raises(openai.OpenAIError):
|
||||
loads(llm_string)
|
||||
|
Loading…
Reference in New Issue
Block a user