Omnitopia commited on
Commit
7ae14df
·
verified ·
1 Parent(s): 48ef67d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -13
app.py CHANGED
@@ -16,7 +16,7 @@ from my_tools import my_tool_list
16
 
17
  class BasicAgent:
18
  def __init__(self):
19
- api_key = os.getenv("OPENAI_API_KEY") # ← 这里自动读取环境变量
20
  if not api_key:
21
  raise ValueError("OPENAI_API_KEY not set in environment variables!")
22
  model = LiteLLMModel(
@@ -24,14 +24,35 @@ class BasicAgent:
24
  api_key=api_key
25
  )
26
 
27
- self.agent = CodeAgent(model=model, tools=my_tool_list, max_steps=3)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
- def __call__(self, question: str) -> str:
30
- print(f"Agent received question: {question[:80]}...")
 
 
 
31
  try:
32
  return self.agent.run(question)
33
  except Exception as e:
34
- return f"[Agent Error: {e}]"
 
35
 
36
  def run_and_submit_all( profile: gr.OAuthProfile | None):
37
  """
@@ -87,19 +108,17 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
87
  results_log = []
88
  answers_payload = []
89
  print(f"Running agent on {len(questions_data)} questions...")
90
- for item in questions_data:
91
  task_id = item.get("task_id")
92
  question_text = item.get("question")
93
- if not task_id or question_text is None:
94
- print(f"Skipping item with missing task_id or question: {item}")
95
- continue
96
  try:
97
- submitted_answer = agent(question_text)
98
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
99
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
100
  except Exception as e:
101
- print(f"Error running agent on task {task_id}: {e}")
102
- results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
103
 
104
  if not answers_payload:
105
  print("Agent did not produce any answers to submit.")
@@ -118,7 +137,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
118
  result_data = response.json()
119
  final_status = (
120
  f"Submission Successful!\n"
121
- f"User: {result_data.get('username')}\n"
122
  f"Overall Score: {result_data.get('score', 'N/A')}% "
123
  f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
124
  f"Message: {result_data.get('message', 'No message received.')}"
 
16
 
17
  class BasicAgent:
18
  def __init__(self):
19
+ api_key = os.getenv("OPENAI_API_KEY") # ← Read enviroment variables in space.
20
  if not api_key:
21
  raise ValueError("OPENAI_API_KEY not set in environment variables!")
22
  model = LiteLLMModel(
 
24
  api_key=api_key
25
  )
26
 
27
+ self.agent_name = "Celum"
28
+ self.agent = CodeAgent(
29
+ model=model,
30
+ tools=my_tool_list,
31
+ max_steps=3,
32
+ system_prompt=(
33
+ "You are Celum,an AI with advanced interaction capabilities."
34
+ "Now you're taking an exam to test your abilitiy in solving real-word problems . "
35
+ "For every question, output ONLY the answer in the exact format required. "
36
+ "NO explanation, NO markdown, NO extra words, NO formatting."
37
+ "For numeric questions, output ONLY the number. "
38
+ "For list questions, output ONLY the list in the requested format. "
39
+ "If the question asks for a single word, output ONLY the word. "
40
+ "If you cannot answer, output ONLY: unknown. "
41
+ "DO NOT add any explanation or context—only output the answer exactly."
42
+ )
43
+ )
44
+
45
 
46
+ def __call__(self, question: str, idx=None, total=None) -> str:
47
+ if idx is not None and total is not None:
48
+ print(f"{self.agent_name} is answering NO. {idx+1}/{total} : {question[:80]}...")
49
+ else:
50
+ print(f"{self.agent_name} received question: {question[:80]}...")
51
  try:
52
  return self.agent.run(question)
53
  except Exception as e:
54
+ return f"[{self.agent_name} Error: {e}]"
55
+
56
 
57
  def run_and_submit_all( profile: gr.OAuthProfile | None):
58
  """
 
108
  results_log = []
109
  answers_payload = []
110
  print(f"Running agent on {len(questions_data)} questions...")
111
+ for idx, item in enumerate([questions_data[:1]):
112
  task_id = item.get("task_id")
113
  question_text = item.get("question")
114
+ print(f"===== [Celum is answering No. {idx+1}/{len(questions_data)} ] =====")
 
 
115
  try:
116
+ submitted_answer = agent(question_text, idx, len(questions_data))
117
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
118
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
119
  except Exception as e:
120
+ print(f"[Celum Error at Q{idx+1}]: {e}")
121
+ results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
122
 
123
  if not answers_payload:
124
  print("Agent did not produce any answers to submit.")
 
137
  result_data = response.json()
138
  final_status = (
139
  f"Submission Successful!\n"
140
+ f"AI: {result_data.get('self.agent_name')}\n"
141
  f"Overall Score: {result_data.get('score', 'N/A')}% "
142
  f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n"
143
  f"Message: {result_data.get('message', 'No message received.')}"