(args: argparse.Namespace)
| 245 | |
| 246 | |
| 247 | def construct_agent(args: argparse.Namespace) -> Agent: |
| 248 | llm_config = construct_llm_config(args) |
| 249 | |
| 250 | agent: Agent |
| 251 | if args.agent_type == "teacher_forcing": |
| 252 | agent = TeacherForcingAgent() |
| 253 | elif args.agent_type == "prompt": |
| 254 | with open(args.instruction_path) as f: |
| 255 | constructor_type = json.load(f)["meta_data"]["prompt_constructor"] |
| 256 | if llm_config.provider in {'llama'}: |
| 257 | tokenizer = tiktoken.encoding_for_model('gpt-4') |
| 258 | else: tokenizer = tiktoken.encoding_for_model(llm_config.model) |
| 259 | prompt_constructor = eval(constructor_type)( |
| 260 | args.instruction_path, lm_config=llm_config, tokenizer=tokenizer |
| 261 | ) |
| 262 | agent = PromptAgent( |
| 263 | action_set_tag=args.action_set_tag, |
| 264 | lm_config=llm_config, |
| 265 | prompt_constructor=prompt_constructor, |
| 266 | ) |
| 267 | else: |
| 268 | raise NotImplementedError( |
| 269 | f"agent type {args.agent_type} not implemented" |
| 270 | ) |
| 271 | return agent |
no test coverage detected