From 251d27cf339a0b98fb4a12af36be8fe253eb1471 Mon Sep 17 00:00:00 2001 From: Bryce Willey Date: Tue, 9 Jan 2024 15:01:09 -0500 Subject: [PATCH] If no openai key, don't try to make an OpenAI obj Avoids errors in logs like: ``` Import of docassemble.ALToolbox.llms failed. OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable ``` --- docassemble/ALToolbox/llms.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docassemble/ALToolbox/llms.py b/docassemble/ALToolbox/llms.py index 0bea213..d126eb0 100644 --- a/docassemble/ALToolbox/llms.py +++ b/docassemble/ALToolbox/llms.py @@ -27,9 +27,11 @@ if os.getenv("OPENAI_API_KEY"): client: Optional[OpenAI] = OpenAI() -else: +elif get_config("open ai"): api_key = get_config("open ai", {}).get("key") client = OpenAI(api_key=api_key) +else: + client = None always_reserved_names = set( docassemble.base.util.__all__