Add env handle

This commit is contained in:
yhyu13 2023-05-24 23:08:10 +08:00
parent 4bc4c1b317
commit c355235dba
1 changed files with 11 additions and 0 deletions

View File

@ -4,6 +4,17 @@ import backoff
completion_tokens = prompt_tokens = 0
api_key = os.getenv("OPENAI_API_KEY", "")
if api_key != "":
openai.api_key = api_key
else:
print("Warning: OPENAI_API_KEY is not set")
api_base = os.getenv("OPENAI_API_BASE", "")
if api_base != "":
print("Warning: OPENAI_API_BASE is set to {}".format(api_base))
openai.api_base = api_base
@backoff.on_exception(backoff.expo, openai.error.OpenAIError)
def completions_with_backoff(**kwargs):
return openai.ChatCompletion.create(**kwargs)