1+ import fcntl
12import logging
23import os
34import re
45import shutil
56import string
67from dataclasses import dataclass
7- from math import exp
88from pathlib import Path
99from typing import Any , Literal
1010
1111import datasets
1212from pdf2image import convert_from_path
1313from pydantic import Field
14- from tapeagents .core import Action , Observation , Step , StopStep , Thought
14+ from tapeagents .core import Action , Observation , StopStep , Thought
1515from tapeagents .environment import ContainerExecutor , StatefulTool , Tool
1616from tapeagents .steps import ImageObservation
1717from tapeagents .tools .browser import Browser
@@ -78,7 +78,7 @@ def make_env(self, exp_dir: str | Path, action_mapping=None) -> GaiaGym:
7878 exp_dir = str (exp_dir )
7979 logger .info (f"Init gaia env with directory { exp_dir } " )
8080 os .environ ["TAPEAGENTS_SQLITE_DB" ] = os .path .join (exp_dir , "tapedata.sqlite" )
81- self . init_code_sandbox (exp_dir )
81+ init_code_sandbox (exp_dir )
8282 tools = [
8383 WebSearch (),
8484 VideoReader (exp_path = exp_dir ),
@@ -88,34 +88,40 @@ def make_env(self, exp_dir: str | Path, action_mapping=None) -> GaiaGym:
8888 env = GaiaGym (tools = tools , task = self .task , exp_dir = exp_dir )
8989 return env
9090
91- def init_code_sandbox (self , exp_dir : str ) -> None :
92- # Use a common code directory for all tasks in the experiment, which is mounted in the container
93- root_exp_dir = Path (exp_dir ).parent
94- code_path = os .path .join (root_exp_dir , "shared_code" )
95- os .makedirs (code_path , exist_ok = True )
9691
97- container_name = "gaia_code_shared"
98- os .environ ["COMPUTER_CONTAINER_NAME" ] = container_name
92+ def init_code_sandbox (exp_dir : str ) -> None :
93+ # Use a common code directory for all tasks in the experiment, which is mounted in the container
94+ root_exp_dir = Path (exp_dir ).parent
95+ code_path = os .path .join (root_exp_dir , "shared_code" )
96+ os .makedirs (code_path , exist_ok = True )
9997
100- # symlink task code to the shared code directory
101- task_code_path = os .path .join (exp_dir , "code" )
102- if not os .path .exists (task_code_path ):
103- os .symlink (code_path , task_code_path )
98+ container_name = "gaia_code_shared"
99+ os .environ ["COMPUTER_CONTAINER_NAME" ] = container_name
104100
101+ # symlink task code to the shared code directory
102+ task_code_path = os .path .join (exp_dir , "code" )
103+ if not os .path .exists (task_code_path ):
104+ os .symlink (code_path , task_code_path )
105+
106+ try :
105107 ContainerExecutor (container_name = container_name , work_dir = code_path , no_deps = True )
108+ except Exception as e :
109+ logger .warning (f"Failed to initialize container executor: { e } " )
106110
107111
108112class GaiaBenchmark (AbstractBenchmark ):
109113 name : str = "gaia"
110114 split : Literal ["test" , "validation" ]
111115 level : Literal ["1" , "2" , "3" , "all" ] = "all"
112- env_args_list : list [GaiaGymArgs ] = None
113- dataset : dict = Field ( default_factory = dict )
116+ env_args_list : list [GaiaGymArgs ] = None # type: ignore
117+ dataset : dict = None # type: ignore
114118
115119 def model_post_init (self , __context : Any ) -> None :
116120 if not self .dataset :
117121 self .dataset = datasets .load_dataset (
118- "gaia-benchmark/GAIA" , "2023_all" , trust_remote_code = True
122+ path = "gaia-benchmark/GAIA" ,
123+ name = "2023_all" ,
124+ trust_remote_code = True ,
119125 ) # type: ignore
120126 self .env_args_list = []
121127 number = 0
@@ -134,7 +140,7 @@ class ExtractedFacts(Thought):
134140 Thought that contains the list of facts extracted from the document
135141 """
136142
137- kind : Literal ["extracted_facts_thought" ] = "extracted_facts_thought"
143+ kind : Literal ["extracted_facts_thought" ] = "extracted_facts_thought" # type: ignore
138144 extracted_facts : list [str ] | dict [str , Any ] | str = Field (
139145 description = "facts extracted from the observation"
140146 )
0 commit comments