mirror of
https://github.com/princeton-nlp/tree-of-thought-llm
synced 2024-11-21 15:47:51 +00:00
Add env handle
This commit is contained in:
parent
4bc4c1b317
commit
c355235dba
11
models.py
11
models.py
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user