Use api_key keyword argument to set the openai_api_key parameter for GPT

This commit is contained in:
Saba 2023-06-04 00:57:00 -07:00
parent 7af8a56434
commit 6508379d7b

View file

@ -41,7 +41,9 @@ max_prompt_size = {"gpt-3.5-turbo": 4096, "gpt-4": 8192}
) )
def completion_with_backoff(**kwargs): def completion_with_backoff(**kwargs):
prompt = kwargs.pop("prompt") prompt = kwargs.pop("prompt")
if "openai_api_key" not in kwargs: if "api_key" in kwargs:
kwargs["openai_api_key"] = kwargs.get("api_key")
elif "openai_api_key" not in kwargs:
kwargs["openai_api_key"] = os.getenv("OPENAI_API_KEY") kwargs["openai_api_key"] = os.getenv("OPENAI_API_KEY")
llm = OpenAI(**kwargs, request_timeout=10, max_retries=1) llm = OpenAI(**kwargs, request_timeout=10, max_retries=1)
return llm(prompt) return llm(prompt)