Spaces:
Sleeping
Sleeping
Set Provider
Browse files18 unmodified lines19202122232418 unmodified lines43444546474842 unmodified lines91929394959624 unmodified lines1211221231241251261271281291301311321331341351362 unmodified lines1391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851866 unmodified lines19319419519618 unmodified linesdef __init__(self):model = InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct",)self._c_agent = CodeAgent(model=model,18 unmodified linesdef __init__(self):model = InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct",)self._w_agent = CodeAgent(model=model,42 unmodified linestemperature=0.2,model_id="deepseek-ai/DeepSeek-R1", # it is possible that this model may be overloadedcustom_role_conversions=None,)agent_web = WebAgent().agentagent_coding = CodingAgent().agent24 unmodified linesTry to solve the task as an Agent using the information"""print(f"Agent received question (first 50 chars): {taskItem.question[:50]}...")additional_context = ""# Check if a file is present by validating the file_name is not emptyif taskItem.file_name and taskItem.file_name.strip():print(f"Agent received file: {taskItem.file_name}")dl_file= self._download_file(taskItem.file_name)additional_context = f"The question has some additional context from a file that needed to be downloaded. here is the contents of the file\n FILE_CONTENTS: {dl_file}\n"prompt = self._PROMPT.format(question=taskItem.question, additional_context=additional_context)print(f"Agent prompt {prompt}")answer = self._manager_agent.run(prompt)# check the answer is FinalStep2 unmodified lines# print(f"Agent returning fixed answer: {answer}")return answer # type: ignoredef _download_file(self, file_name: str) -> str:"""Download the file from the given task_id and return its contents as a string."""print(f"Downloading file for task: {file_name}")try:# Construct the API URL - assuming file_name is the task_idapi_url = f"{self._api_url}/files/{file_name}" # Replace with actual base URL# Download the fileresponse = requests.get(api_url)response.raise_for_status() # Raises an HTTPError for bad responses# Create a temporary filewith tempfile.NamedTemporaryFile(mode='w+b', delete=False) as temp_file:temp_file.write(response.content)temp_file_path = temp_file.nametry:# Try to read as text with UTF-8 encoding firstwith open(temp_file_path, 'r', encoding='utf-8') as f:content = f.read()except UnicodeDecodeError:# If UTF-8 fails, try with latin-1try:with open(temp_file_path, 'r', encoding='latin-1') as f:content = f.read()except Exception:# If all text encodings fail, return binary infowith open(temp_file_path, 'rb') as f:binary_content = f.read()content = f"Binary file content (Size: {len(binary_content)} bytes)"finally:# Clean up the temporary fileos.unlink(temp_file_path)print(f"File downloaded and processed successfully for task: {file_name}")return contentexcept requests.HTTPError as e:if e.response.status_code == 404:error_msg = f"No file found for task ID: {file_name}"6 unmodified linesexcept Exception as e:error_msg = f"Error downloading/processing file for task {file_name}: {e}"print(error_msg)return error_msg18 unmodified lines1920212223242518 unmodified lines4445464748495042 unmodified lines9394959697989924 unmodified lines1241251261271281291301311321331341351361371381391401412 unmodified lines1441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921936 unmodified lines20020120220318 unmodified linesdef __init__(self):model = InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct",provider="huggingface",)self._c_agent = CodeAgent(model=model,18 unmodified linesdef __init__(self):model = InferenceClientModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct",provider="huggingface",)self._w_agent = CodeAgent(model=model,42 unmodified linestemperature=0.2,model_id="deepseek-ai/DeepSeek-R1", # it is possible that this model may be overloadedcustom_role_conversions=None,provider="huggingface",)agent_web = WebAgent().agentagent_coding = CodingAgent().agent24 unmodified linesTry to solve the task as an Agent using the information"""print(f"Agent received question (first 50 chars): {taskItem.question[:50]}...")additional_context = ""# Check if a file is present by validating the file_name is not emptyif taskItem.file_name and taskItem.file_name.strip():print(f"Agent received file: {taskItem.file_name}")dl_file = self._download_file(taskItem.file_name)additional_context = f"The question has some additional context from a file that needed to be downloaded. here is the contents of the file\n FILE_CONTENTS: {dl_file}\n"prompt = self._PROMPT.format(question=taskItem.question, additional_context=additional_context)print(f"Agent prompt {prompt}")answer = self._manager_agent.run(prompt)# check the answer is FinalStep2 unmodified lines# print(f"Agent returning fixed answer: {answer}")return answer # type: ignoredef _download_file(self, file_name: str) -> str:"""Download the file from the given task_id and return its contents as a string."""print(f"Downloading file for task: {file_name}")try:# Construct the API URL - assuming file_name is the task_idapi_url = (f"{self._api_url}/files/{file_name}" # Replace with actual base URL)# Download the fileresponse = requests.get(api_url)response.raise_for_status() # Raises an HTTPError for bad responses# Create a temporary filewith tempfile.NamedTemporaryFile(mode="w+b", delete=False) as temp_file:temp_file.write(response.content)temp_file_path = temp_file.nametry:# Try to read as text with UTF-8 encoding firstwith open(temp_file_path, "r", encoding="utf-8") as f:content = f.read()except UnicodeDecodeError:# If UTF-8 fails, try with latin-1try:with open(temp_file_path, "r", encoding="latin-1") as f:content = f.read()except Exception:# If all text encodings fail, return binary infowith open(temp_file_path, "rb") as f:binary_content = f.read()content = f"Binary file content (Size: {len(binary_content)} bytes)"finally:# Clean up the temporary fileos.unlink(temp_file_path)print(f"File downloaded and processed successfully for task: {file_name}")return contentexcept requests.HTTPError as e:if e.response.status_code == 404:error_msg = f"No file found for task ID: {file_name}"6 unmodified linesexcept Exception as e:error_msg = f"Error downloading/processing file for task {file_name}: {e}"print(error_msg)return error_msg
agent.py+25-18