Skip to content

Commit

Permalink
✅ Add OPENAI_API_KEY check and set it if not present
Browse files Browse the repository at this point in the history
  • Loading branch information
Leolty committed Dec 29, 2023
1 parent 0747803 commit b7d2bf9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion agent/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import openai
import os
import time
import tiktoken
import timeout_decorator
Expand All @@ -15,10 +16,18 @@ def __init__(self, model_name: str, provider: str = 'openai'):
self.model = AutoModelForCausalLM.from_pretrained(model_name)
elif provider == 'openai':
self.tokenizer = tiktoken.encoding_for_model(model_name)

API_KEY = os.getenv("OPENAI_API_KEY", None)

if API_KEY is None:
raise ValueError("OPENAI_API_KEY not set, please run `export OPENAI_API_KEY=<your key>` to ser it")
else:
openai.api_key = API_KEY

elif provider == "vllm":
self.model = LLM(model_name, gpu_memory_utilization=0.9)
self.tokenizer = self.model.get_tokenizer()


def query(self, prompt: str, **kwargs) -> Union[str, list]:
if self.provider == 'openai':
Expand Down

0 comments on commit b7d2bf9

Please sign in to comment.