MCPcopy Create free account
hub / github.com/THUDM/AgentTuning / eval

Function eval

eval_heldout/science-world/eval.py:187–368  ·  view source on GitHub ↗
(args, task_num, logger)

Source from the content-addressed store, hash-verified

185
186# Example user input console, to play through a game.
187def eval(args, task_num, logger):
188
189 # Initialize environment
190 # env = ScienceWorldEnv("", args["jar_path"], envStepLimit = args["env_step_limit"], threadNum = 0)
191 env = ScienceWorldEnv("", args["jar_path"], envStepLimit = args["env_step_limit"])
192 taskNames = env.getTaskNames()
193 taskName = taskNames[task_num]
194 env.load(taskName, 0, args['simplification_str'])
195 variations = load_variation(env, args, task_num, logger)
196 filenameOutPrefixSeed = get_file_name(args, task_num)
197
198 # Load init prompt
199 with open(args["prompt_file"], 'r') as f:
200 d = json.load(f)
201
202 # Load encoding tool to count token numbers
203 token_model = args["model_name"] if 'gpt' in args["model_name"] else 'gpt-4'
204 encoding = tiktoken.encoding_for_model(token_model)
205 # plans = get_plans(args)
206
207 scores = []
208
209 for variation in variations:
210
211 # train_data = []
212 env.load(taskName, variation, args["simplification_str"], generateGoldPath=True)
213 task_description = env.taskdescription()[18:]
214 recent_actions = ["look around"]
215
216 obs, info = env.reset()
217
218 done = False
219 score = 0.0
220 last_score = 0.0
221 step = 0
222
223 # The env has an internal step count, some actions like look around are free
224 # however, the t5 model only generates the action "look around", which will result in a dead loop below
225 # so the max_steps here is only used to avoid the model generating the same action forever
226 max_steps = args["env_step_limit"] * 2
227
228
229 if 'gpt' in args["model_name"]:
230 conv = get_conversation_template(args["model_name"])
231 conv.set_system_message("You are a helpful, respectful and honest assistant.")
232 elif 'openchat' in args["model_name"]:
233 conv = Conversation(
234 name="openchat",
235 roles=("GPT4 User", "GPT4 Assistant"),
236 messages=[],
237 offset=0,
238 sep_style=SeparatorStyle.ADD_COLON_SINGLE,
239 sep="<|end_of_turn|>",
240 )
241 elif 'vicuna' in args["model_name"]:
242 conv = get_conversation_template('vicuna')
243 elif 'llama' in args["model_name"]:
244 conv = get_conversation_template('llama-2')

Callers 11

extract_answer_hfFunction · 0.85
extract_answerFunction · 0.85
accMethod · 0.85
workerFunction · 0.85
mainFunction · 0.85
launchAirportCodeFunction · 0.85
setAirportCodeFunction · 0.85
trackAllFormValuesFunction · 0.85
aa_Utilities_DialogFunction · 0.85
construct_agentFunction · 0.85
__call__Method · 0.85

Calls 15

load_variationFunction · 0.90
findValidActionNewFunction · 0.90
is_action_failedFunction · 0.90
get_file_nameFunction · 0.85
process_examplesFunction · 0.85
llm_tgiFunction · 0.85
encodeMethod · 0.80
cleanFunction · 0.70
get_promptFunction · 0.70
llm_gptFunction · 0.70
loadMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected