Spaces:
Build error
Build error
Commit ·
ab7953b
1
Parent(s): 96acbd9
better agent submition
Browse files84 unmodified lines8586878889909130 unmodified lines12212312412512612712812913013113213384 unmodified linesreturn {"Task ID": task_id, "Question": question_text, "Submitted Answer": "SKIPPED"}, Nonetry:submitted_answer = await agent.aquery(question_text)return {"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer}, {"task_id": task_id, "submitted_answer": submitted_answer}except Exception as e:print(f"Error running agent on task {task_id}: {e}")return {"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"}, None30 unmodified linesapi_url = DEFAULT_API_URLsubmit_url = f"{api_url}/submit"agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": cached_answers}print(f"Submitting {len(cached_answers)} answers to: {submit_url}")try:response = requests.post(submit_url, json=submission_data, timeout=60)response.raise_for_status()result_data = response.json()final_status = (f"Submission Successful!\n"f"User: {result_data.get('username')}\n"84 unmodified lines8586878889909192939430 unmodified lines12512612712812913013113213313413513613713813914014114214314414514614714814915015115284 unmodified linesreturn {"Task ID": task_id, "Question": question_text, "Submitted Answer": "SKIPPED"}, Nonetry:submitted_answer = await agent.aquery(question_text)# Ensure consistent data types for payloadsafe_task_id = str(task_id)safe_answer = str(submitted_answer)return {"Task ID": safe_task_id, "Question": question_text, "Submitted Answer": safe_answer}, {"task_id": safe_task_id, "submitted_answer": safe_answer}except Exception as e:print(f"Error running agent on task {task_id}: {e}")return {"Task ID": task_id, "Question": question_text, "Submitted Answer": f"AGENT ERROR: {e}"}, None30 unmodified linesapi_url = DEFAULT_API_URLsubmit_url = f"{api_url}/submit"agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"# Detailed logging for the submission payload (only first 3 answers to avoid clutter)preview_answers = cached_answers[:3] if cached_answers else []print("\n--- Submission Payload Preview ---")print(f"Username: {username.strip()}")print(f"Agent Code: {agent_code}")print(f"Total Answers: {len(cached_answers)}")print(f"First Answers Sample: {preview_answers}")print("----------------------------------\n")submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": cached_answers}print(f"Submitting {len(cached_answers)} answers to: {submit_url}")try:response = requests.post(submit_url, json=submission_data, timeout=60)response.raise_for_status()print(f"Submit endpoint status code: {response.status_code}")print(f"Raw response text: {response.text[:500]}")# Attempt to parse JSON regardless of status for troubleshootingtry:result_data = response.json()except Exception as json_err:print(f"Error parsing JSON response: {json_err}")raisefinal_status = (f"Submission Successful!\n"f"User: {result_data.get('username')}\n"
app.py+21-2