Zach Wentz commited on
Commit
7843e97
·
1 Parent(s): 67a5ae3

🤖 Deploy chat_env environment - 2025-10-19 22:54:41

Browse files
src/core/env_server/web_interface.py CHANGED
@@ -168,7 +168,29 @@ class WebInterfaceManager:
168
  def _deserialize_action(self, action_data: Dict[str, Any]) -> Action:
169
  """Convert JSON dict to Action instance."""
170
  metadata = action_data.pop("metadata", {})
171
- action = self.action_cls(**action_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  action.metadata = metadata
173
  return action
174
 
@@ -250,6 +272,8 @@ def get_web_interface_html(action_cls: Type[Action]) -> str:
250
  input_type = "number"
251
  elif field_type == bool:
252
  input_type = "checkbox"
 
 
253
  else:
254
  input_type = "text"
255
 
@@ -618,7 +642,17 @@ def get_web_interface_html(action_cls: Type[Action]) -> str:
618
  // Collect form data
619
  for (const [key, value] of formData.entries()) {{
620
  if (value !== '') {{
621
- action[key] = value;
 
 
 
 
 
 
 
 
 
 
622
  }}
623
  }}
624
 
@@ -746,6 +780,14 @@ def _generate_action_form_fields(action_fields: List[Dict[str, Any]]) -> str:
746
  </label>
747
  </div>
748
  ''')
 
 
 
 
 
 
 
 
749
  elif field['type'] == 'text' and 'message' in field['name'].lower():
750
  fields_html.append(f'''
751
  <div class="form-group">
 
168
  def _deserialize_action(self, action_data: Dict[str, Any]) -> Action:
169
  """Convert JSON dict to Action instance."""
170
  metadata = action_data.pop("metadata", {})
171
+
172
+ # Handle tensor fields that come from JSON as lists
173
+ processed_data = {}
174
+ for key, value in action_data.items():
175
+ if key == "tokens" and isinstance(value, (list, str)):
176
+ # Convert list or string to tensor
177
+ if isinstance(value, str):
178
+ # If it's a string, try to parse it as a list of numbers
179
+ try:
180
+ import json
181
+ value = json.loads(value)
182
+ except:
183
+ # If parsing fails, treat as empty list
184
+ value = []
185
+ if isinstance(value, list):
186
+ import torch
187
+ processed_data[key] = torch.tensor(value, dtype=torch.long)
188
+ else:
189
+ processed_data[key] = value
190
+ else:
191
+ processed_data[key] = value
192
+
193
+ action = self.action_cls(**processed_data)
194
  action.metadata = metadata
195
  return action
196
 
 
272
  input_type = "number"
273
  elif field_type == bool:
274
  input_type = "checkbox"
275
+ elif hasattr(field_type, '__name__') and 'Tensor' in field_type.__name__:
276
+ input_type = "tensor"
277
  else:
278
  input_type = "text"
279
 
 
642
  // Collect form data
643
  for (const [key, value] of formData.entries()) {{
644
  if (value !== '') {{
645
+ // Handle tensor fields (tokens) - convert comma-separated string to array
646
+ if (key === 'tokens') {{
647
+ try {{
648
+ action[key] = value.split(',').map(x => parseInt(x.trim())).filter(x => !isNaN(x));
649
+ }} catch (e) {{
650
+ console.error('Error parsing tokens:', e);
651
+ action[key] = [];
652
+ }}
653
+ }} else {{
654
+ action[key] = value;
655
+ }}
656
  }}
657
  }}
658
 
 
780
  </label>
781
  </div>
782
  ''')
783
+ elif field['type'] == 'tensor':
784
+ fields_html.append(f'''
785
+ <div class="form-group">
786
+ <label for="{field['name']}">{field['name']} (comma-separated integers):</label>
787
+ <input type="text" name="{field['name']}" id="{field['name']}" placeholder="e.g., 1,2,3,4,5" {"required" if field['required'] else ""}>
788
+ <small>Enter token IDs as comma-separated integers</small>
789
+ </div>
790
+ ''')
791
  elif field['type'] == 'text' and 'message' in field['name'].lower():
792
  fields_html.append(f'''
793
  <div class="form-group">