@@ -33,12 +33,11 @@ def __init__(self) -> None:
33
33
super ().__init__ (uuid .UUID ("b664a4a9-d86f-5a5f-95cb-e8353a7e8356" ))
34
34
self .run_options : Optional [RunOptions ] = None
35
35
36
- @staticmethod
37
- def __hash (key : str , data : str ) -> str :
36
+ @classmethod
37
+ def __hash (cls , data : str ) -> str :
38
38
res = hmac .new (
39
- key .encode ("utf-8" ), data .encode ("utf-8" ), hashlib .sha256
39
+ cls . __vendorKey .encode ("utf-8" ), data .encode ("utf-8" ), hashlib .sha256
40
40
).hexdigest ()
41
- print (res )
42
41
return res
43
42
44
43
def on_message_received (self , msg : IncomingMessage ) -> None :
@@ -47,36 +46,31 @@ def on_message_received(self, msg: IncomingMessage) -> None:
47
46
+ "this should not have happened."
48
47
)
49
48
50
- @staticmethod
51
- def __sanitize_run_options (config : RunOptions ) -> Dict [str , Any ]:
49
+ @classmethod
50
+ def __sanitize_run_options (cls , config : RunOptions ) -> Dict [str , Any ]:
52
51
res = copy .deepcopy (config .as_dict ())
53
52
54
- def hash (value : str ) -> str :
55
- return TrainingAnalyticsSideChannel .__hash (
56
- TrainingAnalyticsSideChannel .__vendorKey , value
57
- )
58
-
59
53
# Filter potentially PII behavior names
60
54
if "behaviors" in res and res ["behaviors" ]:
61
- res ["behaviors" ] = {hash (k ): v for (k , v ) in res ["behaviors" ].items ()}
55
+ res ["behaviors" ] = {cls . __hash (k ): v for (k , v ) in res ["behaviors" ].items ()}
62
56
for (k , v ) in res ["behaviors" ].items ():
63
57
if "init_path" in v and v ["init_path" ] is not None :
64
- hashed_path = hash (v ["init_path" ])
58
+ hashed_path = cls . __hash (v ["init_path" ])
65
59
res ["behaviors" ][k ]["init_path" ] = hashed_path
66
60
67
61
# Filter potentially PII curriculum and behavior names from Checkpoint Settings
68
62
if "environment_parameters" in res and res ["environment_parameters" ]:
69
63
res ["environment_parameters" ] = {
70
- hash (k ): v for (k , v ) in res ["environment_parameters" ].items ()
64
+ cls . __hash (k ): v for (k , v ) in res ["environment_parameters" ].items ()
71
65
}
72
66
for (curriculumName , curriculum ) in res ["environment_parameters" ].items ():
73
67
updated_lessons = []
74
68
for lesson in curriculum ["curriculum" ]:
75
69
new_lesson = copy .deepcopy (lesson )
76
70
if lesson .has_keys ("name" ):
77
- new_lesson ["name" ] = hash (lesson ["name" ])
71
+ new_lesson ["name" ] = cls . __hash (lesson ["name" ])
78
72
if lesson .has_keys ("completion_criteria" ):
79
- new_lesson ["completion_criteria" ]["behavior" ] = hash (
73
+ new_lesson ["completion_criteria" ]["behavior" ] = cls . __hash (
80
74
new_lesson ["completion_criteria" ]["behavior" ]
81
75
)
82
76
updated_lessons .append (new_lesson )
@@ -90,7 +84,7 @@ def hash(value: str) -> str:
90
84
"initialize_from" in res ["checkpoint_settings" ]
91
85
and res ["checkpoint_settings" ]["initialize_from" ] is not None
92
86
):
93
- res ["checkpoint_settings" ]["initialize_from" ] = hash (
87
+ res ["checkpoint_settings" ]["initialize_from" ] = cls . __hash (
94
88
res ["checkpoint_settings" ]["initialize_from" ]
95
89
)
96
90
if (
@@ -123,31 +117,25 @@ def environment_initialized(self, run_options: RunOptions) -> None:
123
117
run_options = json .dumps (sanitized_run_options ),
124
118
)
125
119
126
- print (msg )
127
-
128
120
any_message = Any ()
129
121
any_message .Pack (msg )
130
122
131
123
env_init_msg = OutgoingMessage ()
132
124
env_init_msg .set_raw_bytes (any_message .SerializeToString ())
133
125
super ().queue_message_to_send (env_init_msg )
134
126
135
- @staticmethod
136
- def __sanitize_trainer_settings (config : TrainerSettings ) -> Dict [str , Any ]:
127
+ @classmethod
128
+ def __sanitize_trainer_settings (cls , config : TrainerSettings ) -> Dict [str , Any ]:
137
129
config_dict = copy .deepcopy (config .as_dict ())
138
130
if "init_path" in config_dict and config_dict ["init_path" ] is not None :
139
- hashed_path = TrainingAnalyticsSideChannel .__hash (
140
- TrainingAnalyticsSideChannel .__vendorKey , config_dict ["init_path" ]
141
- )
131
+ hashed_path = cls .__hash (config_dict ["init_path" ])
142
132
config_dict ["init_path" ] = hashed_path
143
133
return config_dict
144
134
145
135
def training_started (self , behavior_name : str , config : TrainerSettings ) -> None :
146
- raw_config = TrainingAnalyticsSideChannel .__sanitize_trainer_settings (config )
136
+ raw_config = self .__sanitize_trainer_settings (config )
147
137
msg = TrainingBehaviorInitialized (
148
- behavior_name = TrainingAnalyticsSideChannel .__hash (
149
- self .__vendorKey , behavior_name
150
- ),
138
+ behavior_name = self .__hash (behavior_name ),
151
139
trainer_type = config .trainer_type .value ,
152
140
extrinsic_reward_enabled = (
153
141
RewardSignalType .EXTRINSIC in config .reward_signals
0 commit comments