AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Use explicit API keys when querying openai rather than import time manipulation of the package attributes (#3241)
James Collinsf96293973765
diff --git a/autogpt/api_manager.py b/autogpt/api_manager.pyindex 16975bae45..ace64fbdaf 100644--- a/autogpt/api_manager.py+++ b/autogpt/api_manager.py@@ -7,7 +7,6 @@ from autogpt.logs import loggerfrom autogpt.modelsinfo import COSTScfg = Config()-openai.api_key = cfg.openai_api_keyprint_total_cost = cfg.debug_mode@@ -50,6 +49,7 @@ class ApiManager:messages=messages,temperature=temperature,max_tokens=max_tokens,+ api_key=cfg.openai_api_key,)else:response = openai.ChatCompletion.create(@@ -57,6 +57,7 @@ class ApiManager:messages=messages,temperature=temperature,max_tokens=max_tokens,+ api_key=cfg.openai_api_key,)if self.debug:logger.debug(f"Response: {response}")diff --git a/autogpt/commands/image_gen.py b/autogpt/commands/image_gen.pyindex 834432c591..9ed0f44b32 100644--- a/autogpt/commands/image_gen.py+++ b/autogpt/commands/image_gen.py@@ -87,7 +87,6 @@ def generate_image_with_dalle(prompt: str, filename: str, size: int) -> str:Returns:str: The filename of the image"""- openai.api_key = CFG.openai_api_key# Check for supported image sizesif size not in [256, 512, 1024]:@@ -102,6 +101,7 @@ def generate_image_with_dalle(prompt: str, filename: str, size: int) -> str:n=1,size=f"{size}x{size}",response_format="b64_json",+ api_key=CFG.openai_api_key,)print(f"Image Generated for prompt:{prompt}")diff --git a/autogpt/config/config.py b/autogpt/config/config.pyindex 9de7fe70fc..66f0253e22 100644--- a/autogpt/config/config.py+++ b/autogpt/config/config.py@@ -128,8 +128,6 @@ class Config(metaclass=Singleton):# Note that indexes must be created on db 0 in redis, this is not configurable.self.memory_backend = os.getenv("MEMORY_BACKEND", "local")- # Initialize the OpenAI API client- openai.api_key = self.openai_api_keyself.plugins_dir = os.getenv("PLUGINS_DIR", "plugins")self.plugins: List[AutoGPTPluginTemplate] = []diff --git a/autogpt/llm_utils.py b/autogpt/llm_utils.pyindex f2fd9a81bc..7b565edd8f 100644--- a/autogpt/llm_utils.py+++ b/autogpt/llm_utils.py@@ -14,7 +14,6 @@ from autogpt.logs import loggerfrom autogpt.types.openai import MessageCFG = Config()-openai.api_key = CFG.openai_api_keydef retry_openai_api(@@ -248,5 +247,8 @@ def create_embedding(Returns:openai.Embedding: The embedding object."""-- return openai.Embedding.create(input=[text], **kwargs)+ return openai.Embedding.create(+ input=[text],+ api_key=CFG.openai_api_key,+ **kwargs,+ )