Mubarak3000 commited on
Commit
7d410a6
·
1 Parent(s): f67d6ce

Updated model

Browse files
Files changed (1) hide show
  1. app.py +16 -12
app.py CHANGED
@@ -14,7 +14,7 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
14
  # --- Basic Agent Definition ---
15
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
16
  class BasicAgent:
17
- def __init__(self, model="gpt-4-turbo", temperature=0.2):
18
  self.model = model
19
  self.temperature = temperature
20
  print("OpenAIAgent initialized.")
@@ -26,17 +26,22 @@ class BasicAgent:
26
  model=self.model,
27
  temperature=self.temperature,
28
  messages=[
29
- {"role": "system", "content": "You are a helpful AI assistant answering science and reasoning questions accurately."},
30
  {"role": "user", "content": question}
31
  ]
32
  )
33
  answer = response['choices'][0]['message']['content'].strip()
34
- print(f"Answer: {answer}")
35
  return answer
36
  except Exception as e:
37
  print(f"Error calling OpenAI API: {e}")
38
  return f"ERROR: {e}"
39
 
 
 
 
 
 
40
  def generate_answers(agent, tasks):
41
  answers = []
42
 
@@ -44,22 +49,21 @@ def generate_answers(agent, tasks):
44
  task_id = task.get("task_id", "")
45
  question = task.get("question", "").lower()
46
 
47
- # Skip unsupported question types
48
  if any(x in question for x in ["youtube.com", "audio", "video", ".mp3", ".mp4"]):
49
- print(f"Skipping task {task_id}: Unsupported media content.")
50
  continue
51
 
52
- # Call the agent on the question
53
- response = agent(task["question"])
54
-
55
- # Handle fallback or API error
56
- if response.startswith("ERROR"):
57
- print(f"Skipping task {task_id} due to error.")
58
  continue
59
 
 
 
 
60
  answers.append({
61
  "task_id": task_id,
62
- "submitted_answer": response
63
  })
64
 
65
  return answers
 
14
  # --- Basic Agent Definition ---
15
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
16
  class BasicAgent:
17
+ def __init__(self, model="gpt-4", temperature=0.2):
18
  self.model = model
19
  self.temperature = temperature
20
  print("OpenAIAgent initialized.")
 
26
  model=self.model,
27
  temperature=self.temperature,
28
  messages=[
29
+ {"role": "system", "content": "You are a helpful AI assistant. Answer with only the correct option letter (A, B, C, or D)."},
30
  {"role": "user", "content": question}
31
  ]
32
  )
33
  answer = response['choices'][0]['message']['content'].strip()
34
+ print(f"Raw Answer: {answer}")
35
  return answer
36
  except Exception as e:
37
  print(f"Error calling OpenAI API: {e}")
38
  return f"ERROR: {e}"
39
 
40
+ def extract_option_letter(text):
41
+ """Extract just A/B/C/D from the answer string."""
42
+ match = re.search(r'\b([A-D])\b', text.upper())
43
+ return match.group(1) if match else "INVALID"
44
+
45
  def generate_answers(agent, tasks):
46
  answers = []
47
 
 
49
  task_id = task.get("task_id", "")
50
  question = task.get("question", "").lower()
51
 
52
+ # Skip media questions
53
  if any(x in question for x in ["youtube.com", "audio", "video", ".mp3", ".mp4"]):
54
+ print(f"Skipping task {task_id}: Unsupported media.")
55
  continue
56
 
57
+ raw_response = agent(task["question"])
58
+ if raw_response.startswith("ERROR"):
 
 
 
 
59
  continue
60
 
61
+ # Extract only the answer letter (A, B, C, D)
62
+ final_answer = extract_option_letter(raw_response)
63
+
64
  answers.append({
65
  "task_id": task_id,
66
+ "submitted_answer": final_answer
67
  })
68
 
69
  return answers