GoodLuckChuck commited on
Commit
8335aa3
·
verified ·
1 Parent(s): cfcd7e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -12
app.py CHANGED
@@ -11,20 +11,15 @@ API_BASE_URL = "https://agents-course-unit4-scoring.hf.space"
11
  HEADERS = {"Content-Type": "application/json", "accept": "application/json"}
12
 
13
  # --- OpenAI Client Configuration ---
14
- # For Hugging Face Spaces, the API key will be loaded from Secrets.
15
  OPENAI_API_KEY_VALUE = os.environ.get("OPENAI_API_KEY")
16
-
17
- # This 'load_dotenv()' is mainly for local convenience.
18
- # In HF Spaces, if the secret OPENAI_API_KEY is set, the above line will get it.
19
  if not OPENAI_API_KEY_VALUE:
20
  print("OPENAI_API_KEY not found in environment variables. Attempting to load from a local .env file (if present)...")
21
- load_dotenv() # Looks for .env in the current directory (root of your Space)
22
  OPENAI_API_KEY_VALUE = os.environ.get("OPENAI_API_KEY")
23
 
24
  if not OPENAI_API_KEY_VALUE:
25
  print("CRITICAL ERROR: OPENAI_API_KEY is not set.")
26
  print("Please ensure it's defined as a Secret in your Hugging Face Space settings.")
27
- # In a real app, you might raise an error or exit if the key is crucial
28
  client = None
29
  else:
30
  try:
@@ -34,13 +29,10 @@ else:
34
  print(f"Error initializing OpenAI client: {e}")
35
  client = None
36
 
37
- # ... (rest of your script: LLM_MODEL, GAIA_FINAL_ANSWER_SYSTEM_PROMPT, Pydantic models, Tool functions, AIAgent class, API interaction functions like api_get_questions, api_download_file, api_submit_answers should remain as per my previous correct versions) ...
38
-
39
- # Update model to use ChatGPT
40
- LLM_MODEL = "gpt-3.5-turbo" # Using ChatGPT model
41
 
42
- # --- Step 4: GAIA System Prompt for Final Answer Formatting ---
43
- GAIA_FINAL_ANSWER_SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."""
44
 
45
  # --- Step 3: Pydantic Models for Tool Inputs ---
46
  class WebSearchInput(BaseModel):
 
11
  HEADERS = {"Content-Type": "application/json", "accept": "application/json"}
12
 
13
  # --- OpenAI Client Configuration ---
 
14
  OPENAI_API_KEY_VALUE = os.environ.get("OPENAI_API_KEY")
 
 
 
15
  if not OPENAI_API_KEY_VALUE:
16
  print("OPENAI_API_KEY not found in environment variables. Attempting to load from a local .env file (if present)...")
17
+ load_dotenv()
18
  OPENAI_API_KEY_VALUE = os.environ.get("OPENAI_API_KEY")
19
 
20
  if not OPENAI_API_KEY_VALUE:
21
  print("CRITICAL ERROR: OPENAI_API_KEY is not set.")
22
  print("Please ensure it's defined as a Secret in your Hugging Face Space settings.")
 
23
  client = None
24
  else:
25
  try:
 
29
  print(f"Error initializing OpenAI client: {e}")
30
  client = None
31
 
32
+ LLM_MODEL = "gpt-3.5-turbo"
 
 
 
33
 
34
+ # --- GAIA System Prompt ---
35
+ GAIA_FINAL_ANSWER_SYSTEM_PROMPT = """You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units s
36
 
37
  # --- Step 3: Pydantic Models for Tool Inputs ---
38
  class WebSearchInput(BaseModel):