Joseph Pollack commited on
Commit
ed0bc6e
·
unverified ·
1 Parent(s): cccf604

return string when string directly without encoding tokens

Browse files
Files changed (1) hide show
  1. app.py +14 -5
app.py CHANGED
@@ -107,15 +107,24 @@ class LOperatorDemo:
107
  )
108
  logger.info(f"Processor output type: {type(inputs)}")
109
 
110
- # Ensure inputs is a tensor and move to correct device
111
- if not isinstance(inputs, torch.Tensor):
 
 
 
 
 
 
 
 
 
112
  logger.warning("apply_chat_template did not return a tensor, attempting to convert...")
113
  if isinstance(inputs, (list, tuple)):
114
  inputs = torch.tensor(inputs)
115
  else:
116
- # If it's a string or other type, we need to handle it differently
117
- logger.error(f"Unexpected input type: {type(inputs)}, value: {inputs}")
118
- return "❌ Error: Processor returned unexpected format"
119
 
120
  inputs = inputs.to(self.model.device)
121
  logger.info(f"Inputs shape: {inputs.shape}, device: {inputs.device}")
 
107
  )
108
  logger.info(f"Processor output type: {type(inputs)}")
109
 
110
+ # If processor returns a string, just return it directly
111
+ if isinstance(inputs, str):
112
+ logger.info("Processor returned string, returning directly...")
113
+ return inputs
114
+
115
+ # Handle other return types
116
+ if isinstance(inputs, dict):
117
+ # If processor returns a dict, extract input_ids
118
+ logger.info("Processor returned dict, extracting input_ids...")
119
+ inputs = inputs["input_ids"]
120
+ elif not isinstance(inputs, torch.Tensor):
121
  logger.warning("apply_chat_template did not return a tensor, attempting to convert...")
122
  if isinstance(inputs, (list, tuple)):
123
  inputs = torch.tensor(inputs)
124
  else:
125
+ # If it's an unexpected type, return the string directly
126
+ logger.warning(f"Unexpected input type: {type(inputs)}, returning as string")
127
+ return str(inputs)
128
 
129
  inputs = inputs.to(self.model.device)
130
  logger.info(f"Inputs shape: {inputs.shape}, device: {inputs.device}")