Upload handler.py
Browse files- handler.py +8 -1
handler.py
CHANGED
|
@@ -101,11 +101,18 @@ class EndpointHandler:
|
|
| 101 |
|
| 102 |
if _is_messages(item):
|
| 103 |
# Chat template path exists in repo; tokenizer.apply_chat_template will use it if configured
|
| 104 |
-
|
| 105 |
item,
|
| 106 |
return_tensors="pt",
|
| 107 |
add_generation_prompt=True,
|
| 108 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
else:
|
| 110 |
if not isinstance(item, str):
|
| 111 |
item = str(item)
|
|
|
|
| 101 |
|
| 102 |
if _is_messages(item):
|
| 103 |
# Chat template path exists in repo; tokenizer.apply_chat_template will use it if configured
|
| 104 |
+
result = self.tokenizer.apply_chat_template(
|
| 105 |
item,
|
| 106 |
return_tensors="pt",
|
| 107 |
add_generation_prompt=True,
|
| 108 |
)
|
| 109 |
+
# Handle both single tensor and tuple/dict returns
|
| 110 |
+
if isinstance(result, dict):
|
| 111 |
+
input_ids = result["input_ids"]
|
| 112 |
+
elif isinstance(result, tuple):
|
| 113 |
+
input_ids = result[0]
|
| 114 |
+
else:
|
| 115 |
+
input_ids = result
|
| 116 |
else:
|
| 117 |
if not isinstance(item, str):
|
| 118 |
item = str(item)
|