Use explicit API keys when querying openai rather than import time manipulation of the package attributes (#3241)
parent
2619740daa
commit
f962939737
|
@ -7,7 +7,6 @@ from autogpt.logs import logger
|
|||
from autogpt.modelsinfo import COSTS
|
||||
|
||||
cfg = Config()
|
||||
openai.api_key = cfg.openai_api_key
|
||||
print_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}")
|
||||
|
|
|
@ -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 sizes
|
||||
if 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}")
|
||||
|
|
|
@ -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_key
|
||||
|
||||
self.plugins_dir = os.getenv("PLUGINS_DIR", "plugins")
|
||||
self.plugins: List[AutoGPTPluginTemplate] = []
|
||||
|
|
|
@ -14,7 +14,6 @@ from autogpt.logs import logger
|
|||
from autogpt.types.openai import Message
|
||||
|
||||
CFG = Config()
|
||||
openai.api_key = CFG.openai_api_key
|
||||
|
||||
|
||||
def 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,
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue