Update app.py
Browse files15 unmodified lines16171819192021221 unmodified line24252627272829303132333435363738394041424344452930464748495051525334545556575849 unmodified lines108109110901111121139394951141159711611711811910110212012112212312412 unmodified lines13713813912114014114214315 unmodified lines
class BasicAgent: def __init__(self): api_key = os.getenv("OPENAI_API_KEY") # ← 这里自动读取环境变量 api_key = os.getenv("OPENAI_API_KEY") # ← Read enviroment variables in space. if not api_key: raise ValueError("OPENAI_API_KEY not set in environment variables!") model = LiteLLMModel(1 unmodified line api_key=api_key ) self.agent = CodeAgent(model=model, tools=my_tool_list, max_steps=3) self.agent_name = "Celum" self.agent = CodeAgent( model=model, tools=my_tool_list, max_steps=3, system_prompt=( "You are Celum,an AI with advanced interaction capabilities." "Now you're taking an exam to test your abilitiy in solving real-word problems . " "For every question, output ONLY the answer in the exact format required. " "NO explanation, NO markdown, NO extra words, NO formatting." "For numeric questions, output ONLY the number. " "For list questions, output ONLY the list in the requested format. " "If the question asks for a single word, output ONLY the word. " "If you cannot answer, output ONLY: unknown. " "DO NOT add any explanation or context—only output the answer exactly." ) )
def __call__(self, question: str) -> str: print(f"Agent received question: {question[:80]}...") def __call__(self, question: str, idx=None, total=None) -> str: if idx is not None and total is not None: print(f"{self.agent_name} is answering NO. {idx+1}/{total} : {question[:80]}...") else: print(f"{self.agent_name} received question: {question[:80]}...") try: return self.agent.run(question) except Exception as e: return f"[Agent Error: {e}]" return f"[{self.agent_name} Error: {e}]"
def run_and_submit_all( profile: gr.OAuthProfile | None): """49 unmodified lines results_log = [] answers_payload = [] print(f"Running agent on {len(questions_data)} questions...") for item in questions_data: for idx, item in enumerate([questions_data[:1]): task_id = item.get("task_id") question_text = item.get("question") if not task_id or question_text is None: print(f"Skipping item with missing task_id or question: {item}") continue print(f"===== [Celum is answering No. {idx+1}/{len(questions_data)} ] =====") try: submitted_answer = agent(question_text) submitted_answer = agent(question_text, idx, len(questions_data)) answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer}) results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer}) except Exception as e: print(f"Error running agent on task {task_id}: {e}") results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"}) print(f"[Celum Error at Q{idx+1}]: {e}") results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"})
if not answers_payload: print("Agent did not produce any answers to submit.")12 unmodified lines result_data = response.json() final_status = ( f"Submission Successful!\n" f"User: {result_data.get('username')}\n" f"AI: {result_data.get('self.agent_name')}\n" f"Overall Score: {result_data.get('score', 'N/A')}% " f"({result_data.get('correct_count', '?')}/{result_data.get('total_attempted', '?')} correct)\n" f"Message: {result_data.get('message', 'No message received.')}"app.py+32-13