(args, task_num, logger)
| 185 | |
| 186 | # Example user input console, to play through a game. |
| 187 | def 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') |
no test coverage detected