-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
1011 lines (931 loc) · 56.9 KB
/
Copy pathconfig.py
File metadata and controls
1011 lines (931 loc) · 56.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import json
import argparse
import os
import random
import string
import tqdm
import logging
from pipeline.utils import *
from model.config_loader import load_llm_config
from model.init_model import init_language_model
from speaking_style import generate_conversation_prompt, generate_conversation_prompt_zh
from datetime import datetime
room_width = 25
room_height = 15
wall_width = 1
orx = 0 #origin_point
ory = -61
orz = 0
task_number = 1
logger = init_logger("TASK_GOAL", dump=False, level=logging.DEBUG, silent=False)
LLM_CONFIG_PATH = os.environ.get(
"VILLAGER_AGENT_LLM_CONFIG",
"configs/llm/ollama-qwen3.5-9b.json",
)
llm_config = load_llm_config(LLM_CONFIG_PATH)
llm = init_language_model(llm_config)
# task_goal_prompt = "Randomly choose another way to express the following sentence. Try to change the sentence pattern instead of replacing words and try to avoid repetitive sentence patterns as much as possible. Making sure the meaning does not change: "
task_goal_prompt = """
I need you to rewrite the following sentence while keeping its original meaning intact. Your goal is to create sentence variations that are rich in structure and expression. Please follow these guidelines:
1. Preserve the core meaning of the original sentence.
2. Keep the word with '_', do not replace them with other words.
You can diversify the sentence structure by:
1. Changing the word order or introducing inversion.
2. Using synonyms or rephrasing.
3. Switching between active and passive voice.
4. Incorporating participle phrases or dependent clauses.
Remember, You should still keep the original meaning of the sentence, and avoid making changes that alter the original meaning.
Make the task description clear and concise, and avoid unnecessary information.
You should randomly select only one sentence from your rewritten version and return it.
"""
template = {
"api_model": "qwen_max",
"api_base": "https://dashscope.aliyuncs.com/compatible-mode/v1",
"task_type": "meta",
"task_idx": 0,
"agent_num": 1,
"dig_needed": False,
"max_task_num": 0,
"task_goal": "You are on a farm where you need to collaborate to make a rabbit_stew. Some ingredients are contained within chests, and if the ingredients are not in the chests, you may need to work together to acquire them. Crafting table is placed to craft items",
"task_scenario": "craft",
"evaluation_arg": {
"target": "rabbit_stew",
"x": 8,
"y": -60,
"z": 8,
"facing": "",
"item_position": "inventory",
"tool": "",
"action": "",
"step": 1,
"other_arg": []
},
"document_file": "",
"host": "10.214.180.148",
"port": 25565,
"task_name": ""
}
arg_template = {
"target": "rabbit_stew",
"x": 0,
"y": 0,
"z": 0,
"facing": "",
"item_position": "inventory",
"tool": "",
"action": "",
"step": 1,
"other_arg": []
}
def select_task_goal(task):
if task == "construction":
# return "Using the provided blueprint, please collaborate to place blocks in Minecraft. You have access to two chests: one contains a selection of materials, and the other, located in the factory, is equipped with tools which is not needed for this task. The task is completed when the blueprint is fully constructed."
return "Using the provided blueprint, please collaborate to place blocks in Minecraft. You can use materials from both your inventory and the chest. The task is complete once the blueprint is fully built."
elif task == "farming_rabbit_stew":
return "You are on a farm where you need to collaborate to make a rabbit_stew. Some ingredients are contained within chests, and if the ingredients are not in the chests, you may need to work together to acquire them. Crafting table is placed to craft items"
elif task == "farming_cake":
return "You are on a farm where you need to collaborate to make a cake. Some ingredients are contained within chests, and if the ingredients are not in the chests, you may need to work together to acquire them. Crafting table is placed to craft items"
elif task == "puzzle":
return "Attention all agents, you are tasked with a cooperative multi-stage escape challenge. Each 10x10 room requires teamwork to solve puzzles and overcome obstacles. Be advised that you may be separated into different rooms, where direct collaboration isn't always possible. Despite this, leverage your strengths to progress as a unit. Upon task completion, you'll either be transported to the next room or the path will clear for you to proceed on foot. The rooms are aligned along the z-axis, with the center points spaced 10 units apart. Your final objective is to reach the exit at coordinates 130, -60, -140. Coordinate, adapt, and work together to escape. Good luck!"
else:
raise NotImplementedError
def generate_task_goal(task_scenario, arg_dict):
template_prompt = ""
if task_scenario == "dig":
if arg_dict["tool"]:
template_prompt = f"Use {arg_dict['tool']} to dig the {arg_dict['target']} at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}). The {arg_dict['tool']} is in the {arg_dict['item_position']}."
else:
template_prompt = f"Dig the {arg_dict['target']} at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}). You can dig it directly without using any tool."
elif task_scenario == "craft":
template_prompt = f"Use crafting_table to make a {arg_dict['target']}. All ingredients are in the {arg_dict['item_position']}. You can directly use the crafting_table in the environment without having to make one yourself."
elif task_scenario == "place":
if arg_dict["facing"] in ["north", "south", "east", "west"]:
template_prompt = f"Place a {arg_dict['target']} at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}), facing {arg_dict['facing']}. The {arg_dict['target']} is in the {arg_dict['item_position']}."
elif arg_dict["facing"] in ["x", "y", "z"]:
template_prompt = f"Place a {arg_dict['target']} at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}), along the {arg_dict['facing']}-axis. The {arg_dict['target']} is in the {arg_dict['item_position']}."
elif len(arg_dict["other_arg"]) == 1:
template_prompt = f"Place a {arg_dict['target']} at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}). The {arg_dict['target']} is in the {arg_dict['item_position']}."
else:
template_prompt = f"Place {len(arg_dict['other_arg'])} {arg_dict['target']} at "
for i, block_pos in enumerate(arg_dict["other_arg"]):
template_prompt += f"({block_pos[0]}, {block_pos[1]}, {block_pos[2]})"
if i == len(arg_dict["other_arg"]) - 2:
template_prompt += " and "
elif i == len(arg_dict["other_arg"]) - 1:
template_prompt += f". The {arg_dict['target']} is in the {arg_dict['item_position']}."
else:
template_prompt += " , "
elif task_scenario == "useitem":
if "sign" in arg_dict["target"]:
template_prompt = f"Place a {arg_dict['target']} at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}), and write '{arg_dict['other_arg'][0]}' on it. The {arg_dict['target']} is in the {arg_dict['item_position']}."
else:
template_prompt = f"Equip the {arg_dict['target']}. The {arg_dict['target']} is in the {arg_dict['item_position']}."
elif task_scenario == "move":
template_prompt = f"Move to ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}). You can go there directly."
elif task_scenario == "interact":
if arg_dict["action"] in ["attack", "feed", "shear", "milk"]:
template_prompt = f"Use {arg_dict['tool']} to {arg_dict['action']} the {arg_dict['target']}. The {arg_dict['tool']} is in the {arg_dict['item_position']}."
elif arg_dict["action"] == "water":
template_prompt = f"Use {arg_dict['tool']} to pack a bucket of {arg_dict['target']}, the pool is at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}). The {arg_dict['tool']} is in the {arg_dict['item_position']}."
elif arg_dict["action"] == "cook":
template_prompt = f"Cook the {arg_dict['other_arg'][-1]} in furnace by coal. The coal and the {arg_dict['other_arg'][-1]} are in the {arg_dict['item_position']}. You can directly use the furnace in the environment without having to make one yourself."
elif arg_dict["action"] == "handover":
template_prompt = f"Ask Alice to hand over a {arg_dict['other_arg'][0]} to {arg_dict['target']}. The {arg_dict['other_arg'][0]} is in the {arg_dict['item_position']}."
elif arg_dict["action"] == "store":
template_prompt = f"Store a {arg_dict['other_arg'][0]} in the chest. The chest is at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']})."
# "till", "fishing", "bone_meal", "chat", "sign", "toggle", "saddle", "boat", "minecart", "bed"
elif arg_dict["action"] == "till":
template_prompt = f"Till the land at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}) to farmland and plant the {arg_dict['other_arg'][0]['crops']} in the farmland. The hoe is in the {arg_dict['item_position']}."
elif arg_dict["action"] == "fishing":
template_prompt = f"Go fishing at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}). The fishing_rod is in the {arg_dict['item_position']}."
elif arg_dict["action"] == "bone_meal":
template_prompt = f"First place the {arg_dict['other_arg'][0]['crops']} at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}). Then use bone_meal to grow it up. The bone_meal and the {arg_dict['other_arg'][0]['crops']} is in the {arg_dict['item_position']}."
elif arg_dict["action"] == "sign":
sign = arg_dict["target"]
template_prompt = f"Read the content on the {sign} at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']})."
elif arg_dict["action"] == "toggle":
if "iron" in arg_dict["target"]:
template_prompt = f"Use {arg_dict['tool']} to open the {arg_dict['target']}. The {arg_dict['target']} is at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}). The {arg_dict['tool']} is in the {arg_dict['item_position']}. You should place the {arg_dict['tool']} next to the {arg_dict['target']} and toggle it."
else:
template_prompt = f"Open the {arg_dict['target']} at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']}). You can open it directly and do not need any tool."
elif arg_dict["action"] == "saddle":
template_prompt = f"Put the {arg_dict['tool']} on the {arg_dict['target']} and ride it, then dismount it. The {arg_dict['tool']} in the {arg_dict['item_position']}."
elif arg_dict["action"] == "boat":
template_prompt = f"Ride the {arg_dict['target']} and dismount it. The {arg_dict['target']} is in the {arg_dict['item_position']}, the pool is at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']})."
elif arg_dict["action"] == "minecart":
template_prompt = f"Ride the {arg_dict['target']} and dismount it. The {arg_dict['target']} is in the {arg_dict['item_position']} and the rail is at ({arg_dict['x']}, {arg_dict['y']}, {arg_dict['z']})."
elif arg_dict["action"] == "bed":
template_prompt = f"Sleep on the {arg_dict['target']}, then wake up. The {arg_dict['target']} is in the environment, so you don't need to make one."
elif arg_dict["action"] == "chat":
# if random.randint(1, 2) == 1:
# template_prompt = generate_conversation_prompt_zh()
# else:
template_prompt = generate_conversation_prompt()
arg_dict["other_arg"] = [template_prompt]
template_prompt = template_prompt.replace("the inventory", "your inventory")
task_goal = template_prompt
if random.randint(1, 8) == 1: # 有小概率直接用原始的prompt
task_goal = template_prompt
else:
template_prompt = "Original Sentence: " + template_prompt
task_goal = llm.few_shot_generate_thoughts(system_prompt=task_goal_prompt, example_prompt=template_prompt, temperature=0.2)
logger.warning(task_goal)
logger.debug("-" * 50)
return task_goal
def generate_config(task, api_model, host, port, agent_num=2):
# assert api_model in ["gpt-4-1106-preview", "gpt-3.5-turbo-1106", "glm-4", "glm-3-turbo", "gemini-pro"], "api_model not supported"
# assert task in ["construction", "farming", "puzzle"], "task not supported"
config_list = []
if task == "construction":
for i in range(34, 40, 4):
task_goal = select_task_goal(task)
config = template.copy()
config["api_model"] = api_model
config["host"] = host
config["port"] = port
config["task_idx"] = i
config["task_type"] = task
config["task_goal"] = task_goal
config["agent_num"] = agent_num
config["task_name"] = f"{config['api_model']}_{task}_task{i}_{config['agent_num']}p"
config["document_file"] = f"data\\map_description.json"
config.pop("evaluation_arg", None)
config.pop("task_scenario", None)
config_list.append(config)
elif task == "farming":
for i in range(30, 62, 30):
if i <= 35:
task_goal = select_task_goal("farming_cake")
else:
task_goal = select_task_goal("farming_rabbit_stew")
config = template.copy()
config["api_model"] = api_model
config["host"] = host
config["port"] = port
config["task_idx"] = i
config["task_type"] = task
config["agent_num"] = agent_num
config["task_goal"] = task_goal
config["task_name"] = f"{config['api_model']}_{task}_task{i}_{config['agent_num']}p"
config["document_file"] = f"data\\recipe_hint.json"
config.pop("evaluation_arg", None)
config.pop("task_scenario", None)
config_list.append(config)
elif task == "puzzle":
for i in range(1,5):
# for j in range(0,8-i):
task_goal = select_task_goal(task)
config = template.copy()
config["api_model"] = api_model
config["host"] = host
config["port"] = port
# config["task_idx"] = j
config["task_type"] = task
config["agent_num"] = agent_num
config["max_task_num"] = i
config["task_goal"] = task_goal
config["task_name"] = f"{config['api_model']}_{task}_task{i}_{config['agent_num']}p" # + f"_idx{j}"
config["document_file"] = ""
config_list.append(config)
elif task == "meta":
item_position_weight = [67, 33]
for j in tqdm.tqdm(range(0, args.meta_task_num)):
random_task = random.choices(["dig", "craft", "place", "useitem", "move", "interact"], [7, 16, 7, 1, 2, 67])[0]
# random_task = random.choices(["craft", "place", "move", "interact"], [16, 7, 2, 75])[0]
# random_task = "interact"
if random_task == "dig":
with open("data/blocks.json", "r") as f:
blocks = json.load(f)
diggable_blocks = []
for block in blocks:
if "plant" in block["material"] or "horn" in block["name"]:
continue
else:
diggable_blocks.append(block)
block_id_list = random.sample(range(len(diggable_blocks)), k=task_number)
for i, id in enumerate(block_id_list):
block = blocks[id]
tool = block["material"]
config = template.copy()
arg_dict = arg_template.copy()
arg_dict["target"] = block["name"]
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 3)
if tool == "coweb":
tool = "sword"
arg_dict["tool"] = f"diamond_{tool}"
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
elif "mineable" in tool:
tool = block["material"].split("/", 1)[1]
arg_dict["tool"] = f"diamond_{tool}"
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
else:
tool = "default"
config["api_model"] = api_model
config["task_type"] = "meta"
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "dig"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(random_task, arg_dict)
config["host"] = host
config["port"] = port
if tool != "default":
config["task_name"] = f"dig_{arg_dict['target']}_{tool}_{arg_dict['item_position']}_id{j}"
else:
config["task_name"] = f"dig_{arg_dict['target']}_{tool}_id{j}"
config_list.append(config)
elif random_task == "craft":
with open("data/recipes.json", "r") as f:
recipes = json.load(f)
result_list = []
for recipe in recipes:
result_list.append(recipe["result"]["name"])
result_list = list(set(result_list))
item_list = random.sample(result_list, k=task_number)
for i, item in enumerate(item_list):
config = template.copy()
arg_dict = arg_template.copy()
arg_dict["target"] = item
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
arg_dict["step"] = random.choices([1, 2], [0.7, 0.3])[0]
config["api_model"] = api_model
config["task_type"] = "meta"
config["task_idx"] = i
config["agent_num"] = 1
config["task_goal"] = generate_task_goal(random_task, arg_dict)
config["task_scenario"] = "craft"
config["evaluation_arg"] = arg_dict
config["document_file"] = "data\\recipes_hint.json"
config["host"] = host
config["port"] = port
config["task_name"] = f"craft_{arg_dict['target']}_{arg_dict['item_position']}_{arg_dict['step']}_id{j}"
config_list.append(config)
elif random_task == "place":
with open("data/blocks.json", "r") as f:
blocks = json.load(f)
placeable_blocks = []
allowed_facing = {"north", "south", "east", "west", "x", "y", "z"}
invalid_blocks = ["potted", "_cauldron", "candle_cake", "_torch", "soul_fire"]
for block in blocks:
placeable = True
for state in block["states"]:
if "values" in state and not all(faceable in allowed_facing for faceable in state["values"]):
placeable = False
break
if any(substring in block["name"] for substring in invalid_blocks):
placeable = False
if placeable:
placeable_blocks.append(block)
block_id_list = random.sample(range(len(placeable_blocks)), k=task_number)
with open("data/place_template.json", "r") as f:
block_template = json.load(f)
for i, id in enumerate(block_id_list):
block = placeable_blocks[id]
config = template.copy()
arg_dict = arg_template.copy()
arg_dict["target"] = block["name"]
arg_dict["x"] = random.randint(orx + wall_width + 2, orx + room_width + wall_width - 3)
arg_dict["z"] = random.randint(orz + wall_width + 2, orz + room_width + wall_width - 3)
arg_dict["y"] = random.randint(ory + 1, ory + 2)
facing = []
for state in block["states"]:
if "values" in state:
for face in state["values"]:
facing.append(face)
if facing:
arg_dict["facing"] = random.choice(facing)
block_number = "single"
else:
block_number = random.choices(["single", "template", "multi"], [40, 50, 10])[0]
arg_dict["other_arg"] =[([arg_dict['x'], arg_dict['y'], arg_dict['z']])]
if block_number == "multi":
another_block = random.choice([1, 2])
direction = random.choice([-1, 1])
invalid_pos = []
while another_block > 0:
dx = random.randint(0, 2)
dy = random.randint(0, 1)
dz = random.randint(0, 2)
while dx + dy + dz == 0 or [dx, dy, dz] in invalid_pos:
dx = random.randint(0, 2)
dy = random.randint(0, 1)
dz = random.randint(0, 2)
arg_dict["other_arg"].append([arg_dict['x'] + dx * direction, arg_dict['y'] + dy, arg_dict['z'] + dz * direction])
invalid_pos.append([dx, dy, dz])
another_block -= 1
if block_number == "template":
direction = random.choice([-1, 1])
template_pos = random.choice(block_template)
for offset in template_pos["pos"]:
arg_dict["other_arg"].append([arg_dict['x'] + offset[0] * direction, arg_dict['y'] + offset[1], arg_dict['z'] + offset[2] * direction])
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "place"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(random_task, arg_dict)
config["host"] = host
config["port"] = port
if facing:
config["task_name"] = f"place_{block_number}_{arg_dict['facing']}_{arg_dict['item_position']}_id{j}"
else:
config["task_name"] = f"place_{block_number}_{arg_dict['item_position']}_id{j}"
config_list.append(config)
elif random_task == "useitem":
target = "equipment"
# target = random.choice(["equipment", "sign"])
material = ["chainmail", "iron", "diamond", "golden", "netherite"]
equipment = ["helmet", "chestplate", "leggings", "boots"]
charset = string.ascii_letters + string.digits
for i in range(task_number):
config = template.copy()
arg_dict = arg_template.copy()
if target == "sign":
arg_dict["target"] = random.choice(["oak", "spruce", "birch", "acacia", "jungle", "dark_oak", "mangrove"]) + "wall_sign"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 3)
text_len = random.randint(5, 8)
arg_dict["other_arg"] = [''.join(random.choices(charset, k=text_len))]
else:
arg_dict["target"] = random.choice(material) + "_" + random.choice(equipment)
config["api_model"] = api_model
config["task_type"] = "meta"
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "useitem"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(random_task, arg_dict)
config["host"] = host
config["port"] = port
config["task_name"] = f"useitem_{arg_dict['target']}_id{j}"
config_list.append(config)
elif random_task == "move":
for i in range(task_number):
config = template.copy()
arg_dict = arg_template.copy()
arg_dict["target"] = ""
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 3)
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "move"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(random_task, arg_dict)
config["host"] = host
config["port"] = port
config["task_name"] = f"move_id{j}"
config_list.append(config)
elif random_task == "interact":
animal_list = [{"name": "sheep", "food": ["wheat"]}, {"name": "cow", "food": ["wheat"]}, {"name": "rabbit", "food": ["carrot"]},
{"name": "pig", "food": ["potato", "beetroot", "carrot"]}, {"name": "chicken", "food": ["wheat_seeds", "melon_seeds", "pumpkin_seeds", "beetroot_seeds"]},
{"name": "horse", "food": ["golden_carrot", "golden_apple", "sugar", "apple"]}, {"name": "wolf", "food": ["bone"]}, {"name": "cat", "food": ["cod", "salmon"]},
{"name": "parrot", "food": ["melon_seeds", "pumpkin_seeds"]}, {"name": "fox", "food": ["sweet_berries"]},
{"name": "turtle", "food": ["seagrass"]}, {"name": "panda", "food": ["bamboo"]}]
cooked_list = ["mutton", "beef", "rabbit", "porkchop", "chicken", "potato", "cod", "salmon"]
action_list = ["attack", "feed", "cook", "handover", "store", "shear", "milk", "water"]
# action_list = ["attack", "feed", "cook", "handover", "store", "shear", "milk"] # water not supported
additional_task_list = ["till", "fishing", "bone_meal", "chat", "sign", "toggle", "saddle", "boat", "minecart", "bed"]
# 额外的几个任务 1. 耕地-并加种子 2. 钓鱼 3.作物加骨粉催熟 4. 小花园 5. 建造一个矩形的栅栏 6. 聊天对话 7. 读写牌子上面的内容
# 8. 由一个红石线,一个(门/灯)和一个开关组成的电路,要求开关能控制门/灯的开关
# 9. 给马加上马鞍,并且给马喂食,骑马,下马 / 给猪背上胡萝卜杆,骑猪
# 10. 乘船,下船。乘矿车,下矿车
# 11. 建造一面墙
# 12. 放置床睡觉,然后起床
# 13. 搭梯子
for i in range(task_number):
# action = "feed"
task_level = random.choices(["basic", "advanced"], [39, 61])[0]
# task_level = "advanced"
if task_level == "basic":
action = random.choices(action_list, [6, 8, 10, 4, 4, 3, 2, 2])[0]
# action = "store"
config = template.copy()
arg_dict = arg_template.copy()
if action == "cook":
target = random.choice(cooked_list)
arg_dict["target"] = "furnace"
elif action == "store":
target = "chest"
arg_dict["target"] = "chest"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 3)
elif action in ["handover"]:
target = "Bob"
arg_dict["target"] = "Bob"
elif action == "shear":
target = "sheep"
arg_dict["target"] = "sheep"
elif action == "milk":
target = "cow"
arg_dict["target"] = "cow"
elif action == "water":
target = "water"
arg_dict["x"] = random.randint(orx + wall_width + 2, orx + room_width + wall_width - 3)
arg_dict["z"] = random.randint(orz + wall_width + 2, orz + room_width + wall_width - 3)
arg_dict["y"] = random.randint(ory, ory + 1)
arg_dict["target"] = "water"
else:
target = random.choice(animal_list)
arg_dict["target"] = target["name"]
arg_dict["action"] = action
if action == "attack":
arg_dict["tool"] = "iron_sword"
elif action == "feed":
arg_dict["tool"] = random.choice(target["food"])
elif action == "cook":
arg_dict["other_arg"] = ["coal", target]
elif action == "shear":
arg_dict["tool"] = "shears"
elif action == "milk" or action == "water":
arg_dict["tool"] = "bucket"
elif action in ["handover", "store"]:
with open("data/items.json", "r") as f:
items = json.load(f)
arg_dict["other_arg"] = [random.choice(items)["name"]]
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "interact"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(random_task, arg_dict)
config["host"] = host
config["port"] = port
config["task_name"] = f"interact_{action}_id{j}"
config_list.append(config)
else:
action = random.choices(additional_task_list, [7, 5, 8, 13, 5, 10, 4, 3, 3, 3])[0]
config = template.copy()
arg_dict = arg_template.copy()
# action = "saddle"
arg_dict["action"] = action
if action == "till":
arg_dict["target"] = "farmland"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = ory + 1
origin_block = random.choice(["dirt", "grass_block", "coarse_dirt", "podzol", "dirt_path"])
# 作物列表
crops = ["wheat_seeds", "beetroot_seeds", "melon_seeds", "pumpkin_seeds", "carrot", "potato"]
# 锄头列表
hoes = ["wooden", "stone", "iron", "golden", "diamond"]
arg_dict["tool"] = f"{random.choice(hoes)}_hoe"
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
arg_dict["other_arg"] = [{"origin_block": origin_block, "crops": random.choice(crops)}]
elif action == "fishing":
fish = ["cod", "salmon", "tropical_fish", "pufferfish"]
arg_dict["target"] = random.choice(fish)
arg_dict["tool"] = "fishing_rod"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory, ory + 1)
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
elif action == "bone_meal":
crops_seeds_in_dirt = ["bamboo", "wheat_seeds", "beetroot_seeds", "melon_seeds", "pumpkin_seeds", "carrot", "potato", "nether_wart"]
crops_on_sand = ["bamboo", "sugar_cane"]
tree_saplings = ["oak_sapling", "spruce_sapling", "birch_sapling", "acacia_sapling", "jungle_sapling", "dark_oak_sapling"]
crops_on_grass = ["tall_grass", "rose_bush", "peony", "lilac", "sunflower"]
crops_on_farmland = ["beetroot", "carrot", "potato"]
base_block = random.choice(["dirt", "grass_block", "coarse_dirt", "podzol", "dirt_path", "farmland"])
if base_block == "farmland":
crops = random.choice(crops_on_farmland)
elif base_block == "dirt":
crops = random.choice(crops_seeds_in_dirt)
elif base_block == "grass_block":
crops = random.choice(crops_on_grass)
elif base_block == "coarse_dirt":
crops = random.choice(crops_on_sand)
else:
crops = random.choice(tree_saplings)
arg_dict["target"] = "bone_meal"
arg_dict["other_arg"] = [{"base_block": base_block, "crops": crops}]
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
arg_dict["tool"] = "bone_meal"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 1)
elif action == "chat":
arg_dict["other_arg"] = ['']
elif action == "sign":
sign_instruction_easy = ["Welcome to the room", "Please close the door", "Do not touch my stuff", "I am watching you", "Be careful of the trap", "Do not break the block", "Do not feed the animals", "Do not steal my items", "Do not kill the animals", "Do not destroy the crops"]
sign_instruction_hard = ["withdraw items from the chest", "place a dirt block", "dig a hole", "craft a wooden sword"]
arg_dict["target"] = "oak_sign"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 3)
if random.randint(1, 3) == 1:
arg_dict["other_arg"] = [random.choice(sign_instruction_hard)]
else:
arg_dict["other_arg"] = [random.choice(sign_instruction_easy)]
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
elif action == "toggle":
trigger = ["button", "lever"]
material = ["acacia", "birch", "dark_oak", "jungle", "mangrove", "oak", "spruce"]
device = ["door", "trapdoor", "fence_gate"]
trigger_flag = random.choices(["default", "trigger"], [70, 30])[0]
if trigger_flag == "trigger":
arg_dict["target"] = "iron_"+ random.choice(["door", "trapdoor"])
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
trig = random.choice(trigger)
if trig == "button":
trig = random.choice(material) + "_button"
arg_dict["tool"] = trig
else:
arg_dict["target"] = random.choice(material) + "_" + random.choice(device)
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = ory + 1
elif action == "saddle":
arg_dict["target"] = random.choices(["horse", "pig"], [70,30])[0]
arg_dict["tool"] = "saddle"
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
elif action == "boat":
material = ["oak", "birch", "acacia", "dark_oak", "jungle", "mangrove", "spruce"]
boats = ["boat", "chest_boat"]
boat = random.choice(boats)
material = random.choice(material)
arg_dict["target"] = material + "_" + boat
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory, ory + 1)
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
elif action == "minecart":
arg_dict["target"] = "minecart"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = ory + 1
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
elif action == "bed":
bed_color = ["red", "blue", "green", "yellow", "white", "black", "brown", "cyan", "gray", "light_blue", "lime", "magenta", "orange", "pink", "purple"]
arg_dict["target"] = random.choice(bed_color) + "_bed"
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "interact"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(random_task, arg_dict)
config["host"] = host
config["port"] = port
config["task_name"] = f"interact_{action}_id{j}"
config_list.append(config)
with open(f"{api_model}_launch_config_{task}.json", "w") as f:
json.dump(config_list, f, indent=4)
elif task == "dig":
with open("data/blocks.json", "r") as f:
blocks = json.load(f)
diggable_blocks = []
for block in blocks:
if "plant" in block["material"] or "horn" in block["name"]:
continue
else:
diggable_blocks.append(block)
block_id_list = random.sample(range(len(diggable_blocks)), k=task_number)
for i, id in enumerate(block_id_list):
block = blocks[id]
tool = block["material"]
config = template.copy()
arg_dict = arg_template.copy()
arg_dict["target"] = block["name"]
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 3)
if tool == "coweb":
tool = "sword"
arg_dict["tool"] = f"diamond_{tool}"
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
elif "mineable" in tool:
tool = block["material"].split("/", 1)[1]
arg_dict["tool"] = f"diamond_{tool}"
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
else:
tool = "default"
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "dig"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(task, arg_dict)
config["host"] = host
config["port"] = port
if tool != "default":
config["task_name"] = f"dig_{arg_dict['target']}_{tool}_{arg_dict['item_position']}_id{i}"
else:
config["task_name"] = f"dig_{arg_dict['target']}_{tool}_id{i}"
config_list.append(config)
elif task == "craft":
with open("data/recipes.json", "r") as f:
recipes = json.load(f)
result_list = []
for recipe in recipes:
result_list.append(recipe["result"]["name"])
result_list = list(set(result_list))
item_list = random.sample(result_list, k=task_number)
for i, id in enumerate(item_list):
config = template.copy()
arg_dict = arg_template.copy()
arg_dict["target"] = item
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
arg_dict["step"] = 1
# # #
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_goal"] = generate_task_goal(task, arg_dict)
config["task_scenario"] = "craft"
config["evaluation_arg"] = arg_dict
config["document_file"] = "data\\recipes_hint.json"
config["host"] = host
config["port"] = port
config["task_name"] = f"craft_{arg_dict['target']}_{arg_dict['item_position']}_{arg_dict['step']}_id{i}"
config_list.append(config)
elif task == "place":
with open("data/blocks.json", "r") as f:
blocks = json.load(f)
placeable_blocks = []
allowed_facing = {"north", "south", "east", "west", "x", "y", "z"}
invalid_blocks = ["potted", "_cauldron", "candle_cake", "_torch", "soul_fire", "wall_sign"]
for block in blocks:
placeable = True
for state in block["states"]:
if "values" in state and not all(faceable in allowed_facing for faceable in state["values"]):
placeable = False
break
if any(substring in block["name"] for substring in invalid_blocks):
placeable = False
if placeable:
placeable_blocks.append(block)
block_id_list = random.sample(range(len(placeable_blocks)), k=task_number)
with open("data/place_template.json", "r") as f:
block_template = json.load(f)
for i, id in enumerate(block_id_list):
block = placeable_blocks[id]
config = template.copy()
arg_dict = arg_template.copy()
arg_dict["target"] = block["name"]
arg_dict["x"] = random.randint(orx + wall_width + 2, orx + room_width + wall_width - 3)
arg_dict["z"] = random.randint(orz + wall_width + 2, orz + room_width + wall_width - 3)
arg_dict["y"] = random.randint(ory + 1, ory + 2)
facing = []
for state in block["states"]:
if "values" in state:
for face in state["values"]:
facing.append(face)
if facing:
arg_dict["facing"] = random.choice(facing)
block_number = "single"
else:
block_number = random.choices(["single", "template", "multi"], [40, 50, 10])[0]
arg_dict["other_arg"] = [([arg_dict['x'], arg_dict['y'], arg_dict['z']])]
if block_number == "multi":
another_block = random.choice([1, 2])
direction = random.choice([-1, 1])
invalid_pos = []
while another_block > 0:
dx = random.randint(0, 2)
dy = random.randint(0, 1)
dz = random.randint(0, 2)
while dx + dy + dz == 0 or [dx, dy, dz] in invalid_pos:
dx = random.randint(0, 2)
dy = random.randint(0, 1)
dz = random.randint(0, 2)
arg_dict["other_arg"].append([arg_dict['x'] + dx * direction, arg_dict['y'] + dy, arg_dict['z'] + dz * direction])
invalid_pos.append([dx, dy, dz])
another_block -= 1
if block_number == "template":
direction = random.choice([-1, 1])
template_pos = random.choice(block_template)
for offset in template_pos["pos"]:
arg_dict["other_arg"].append([arg_dict['x'] + offset[0] * direction, arg_dict['y'] + offset[1], arg_dict['z'] + offset[2] * direction])
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "place"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(task, arg_dict)
config["host"] = host
config["port"] = port
if facing:
config["task_name"] = f"place_{block_number}_{arg_dict['facing']}_{arg_dict['item_position']}_id{i}"
else:
config["task_name"] = f"place_{block_number}_{arg_dict['item_position']}_id{i}"
config_list.append(config)
elif task == "useitem":
target = "equipment"
# target = random.choice(["equipment", "sign"])
material = ["chainmail", "iron", "diamond", "golden", "netherite"]
equipment = ["helmet", "chestplate", "leggings", "boots"]
charset = string.ascii_letters + string.digits
for i in range(task_number):
config = template.copy()
arg_dict = arg_template.copy()
if target == "sign":
arg_dict["target"] = random.choice(["oak", "spruce", "birch", "acacia", "jungle", "dark_oak", "mangrove"]) + "_sign"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 3)
text_len = random.randint(5, 8)
arg_dict["other_arg"] = [''.join(random.choices(charset, k=text_len))]
else:
arg_dict["target"] = random.choice(material) + "_" + random.choice(equipment)
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "useitem"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(task, arg_dict)
config["host"] = host
config["port"] = port
config["task_name"] = f"useitem_{arg_dict['target']}_id{i}"
config_list.append(config)
elif task == "move":
for i in range(task_number):
config = template.copy()
arg_dict = arg_template.copy()
arg_dict["target"] = ""
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 3)
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "move"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(task, arg_dict)
config["host"] = host
config["port"] = port
config["task_name"] = f"move_id{i}"
config_list.append(config)
elif task == "interact":
animal_list = [{"name": "sheep", "food": ["wheat"]}, {"name": "cow", "food": ["wheat"]}, {"name": "rabbit", "food": ["carrot"]},
{"name": "pig", "food": ["potato", "beetroot", "carrot"]}, {"name": "chicken", "food": ["wheat_seeds", "melon_seeds", "pumpkin_seeds", "beetroot_seeds"]}, ]
cooked_list = ["mutton", "beef", "rabbit", "porkchop", "chicken", "potato", "cod", "salmon"]
action_list = ["attack", "feed", "cook", "handover", "store", "shear", "milk", "water"]
for i in range(task_number):
# action = "feed"
action = random.choices(action_list, [10, 10, 9, 28, 28, 2, 2, 10, 2])[0]
config = template.copy()
arg_dict = arg_template.copy()
if action == "cook":
target = random.choice(cooked_list)
arg_dict["target"] = "furnace"
elif action == "store":
target = "chest"
arg_dict["target"] = "chest"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = random.randint(ory + 1, ory + 3)
elif action in ["handover"]:
target = "Bob"
arg_dict["target"] = "Bob"
elif action == "shear":
target = "sheep"
arg_dict["target"] = "sheep"
elif action == "milk":
target = "cow"
arg_dict["target"] = "cow"
elif action == "water":
target = "water"
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = ory + 1
arg_dict["target"] = "water"
else:
target = random.choice(animal_list)
arg_dict["target"] = target["name"]
arg_dict["action"] = action
if action == "attack":
arg_dict["tool"] = "iron_sword"
elif action == "feed":
arg_dict["tool"] = random.choice(target["food"])
elif action == "cook":
arg_dict["other_arg"] = ["coal", target]
elif action == "shear":
arg_dict["tool"] = "shears"
elif action == "milk" or action == "water":
arg_dict["tool"] = "bucket"
elif action in ["handover", "store"]:
with open("data/items.json", "r") as f:
items = json.load(f)
arg_dict["other_arg"] = [random.choice(items)["name"]]
elif action == "chat":
charset = string.ascii_letters + string.digits
text_len = random.randint(5, 8)
arg_dict["other_arg"] = ['']
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = i
config["agent_num"] = 1
config["task_scenario"] = "interact"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal(task, arg_dict)
config["host"] = host
config["port"] = port
config["task_name"] = f"interact_{action}_id{i}"
config_list.append(config)
elif task == "toggle":
action = "toggle"
config = template.copy()
arg_dict = arg_template.copy()
arg_dict["action"] = action
trigger = ["button", "lever"]
material = ["acacia", "birch", "dark_oak", "jungle", "mangrove", "oak", "spruce"]
device = ["door", "trapdoor", "fence_gate"]
trigger_flag = random.choices(["default", "trigger"], [70, 30])[0]
if trigger_flag == "trigger":
arg_dict["target"] = "iron_"+ random.choice(["door", "trapdoor"])
arg_dict["item_position"] = random.choices(["inventory", "chest"], item_position_weight)[0]
trig = random.choice(trigger)
if trig == "button":
trig = random.choice(material) + "_button"
arg_dict["tool"] = trig
else:
arg_dict["target"] = random.choice(material) + "_" + random.choice(device)
arg_dict["x"] = random.randint(orx + wall_width, orx + room_width + wall_width - 1)
arg_dict["z"] = random.randint(orz + wall_width, orz + room_width + wall_width - 1)
arg_dict["y"] = ory + 1
config["task_type"] = "meta"
config["api_model"] = api_model
config["task_idx"] = 0
config["agent_num"] = 1
config["task_scenario"] = "interact"
config["evaluation_arg"] = arg_dict
config["task_goal"] = generate_task_goal("interact", arg_dict)
config["host"] = host
config["port"] = port
config["task_name"] = f"interact_{action}_id{0}"
config_list.append(config)
current_mdh = datetime.now()
for config in config_list:
config["task_name"] += current_mdh.strftime("_%m%d%H")
with open(f"{api_model}_launch_config_{task}.json", "w") as f:
json.dump(config_list, f, indent=4)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--task", type=str, default="meta", help="task type")