AashitaK commited on
Commit
6e8964d
·
verified ·
1 Parent(s): b4c9fd2

Update openai_api.py

Browse files
Files changed (1) hide show
  1. openai_api.py +9 -6
openai_api.py CHANGED
@@ -2,14 +2,16 @@ import os
2
  from openai import OpenAI
3
  from file_utils import load_file
4
 
5
- # Initialize the OpenAI client using the API keys
6
- client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
7
 
8
- # Load the prompt from a file
9
- metaprompt_filepath = "meta_prompt.txt"
10
- META_PROMPT = load_file(metaprompt_filepath)
 
 
 
11
 
12
- COMPLETIONS_MODEL = "gpt-4o-mini"# "gpt-3.5-turbo-instruct" used earlier .
13
  EMBEDDING_MODEL = "text-embedding-3-large" # "text-embedding-3-small"
14
 
15
  def get_embedding(text: str, model: str=EMBEDDING_MODEL) -> list[float]:
@@ -20,6 +22,7 @@ def get_embedding(text: str, model: str=EMBEDDING_MODEL) -> list[float]:
20
  )
21
  return result.data[0].embedding
22
 
 
23
 
24
  def get_response(messages: list[dict], model: str=COMPLETIONS_MODEL,
25
  temperature=0, max_completion_tokens=800) -> str:
 
2
  from openai import OpenAI
3
  from file_utils import load_file
4
 
5
+ # Ensure you set your API token in your environment variables or pass it directly
6
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") # Make sure it's set in your environment
7
 
8
+ if OPENAI_API_KEY is None:
9
+ raise ValueError("Hugging Face API token is missing. Set it as an environment variable: OPENAI_API_KEY")
10
+
11
+
12
+ # Initialize the OpenAI client using the API keys
13
+ client = OpenAI(api_key=OPENAI_API_KEY)
14
 
 
15
  EMBEDDING_MODEL = "text-embedding-3-large" # "text-embedding-3-small"
16
 
17
  def get_embedding(text: str, model: str=EMBEDDING_MODEL) -> list[float]:
 
22
  )
23
  return result.data[0].embedding
24
 
25
+ COMPLETIONS_MODEL = "gpt-4o-mini"# "gpt-3.5-turbo-instruct" used earlier .
26
 
27
  def get_response(messages: list[dict], model: str=COMPLETIONS_MODEL,
28
  temperature=0, max_completion_tokens=800) -> str: