Datasets:
tools/auto_fmt: a text-only template that refuses image parts with raise_exception gets the text parts (Spark-X2.6)
Browse files- tools/auto_fmt.py +7 -0
tools/auto_fmt.py
CHANGED
|
@@ -179,6 +179,13 @@ def render(messages: Sequence[dict],
|
|
| 179 |
# a text-only template (Kolibri-1) cannot take content given as a list of parts: keep the text
|
| 180 |
# parts, drop the rest. Templates that take lists never get here, so their renders do not change
|
| 181 |
text = apply(_flatten(_clean(messages)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
if add_bos and tok.bos_token and not text.startswith(tok.bos_token):
|
| 184 |
text = tok.bos_token + text
|
|
|
|
| 179 |
# a text-only template (Kolibri-1) cannot take content given as a list of parts: keep the text
|
| 180 |
# parts, drop the rest. Templates that take lists never get here, so their renders do not change
|
| 181 |
text = apply(_flatten(_clean(messages)))
|
| 182 |
+
except Exception as e: # noqa: BLE001
|
| 183 |
+
# the same for a text-only template that refuses the other parts with raise_exception (Spark-X2.6:
|
| 184 |
+
# "Unsupported user content block type: image"), a jinja2 TemplateError; only when some content
|
| 185 |
+
# is a list of parts, so any other template error still stops the build
|
| 186 |
+
if type(e).__name__ != "TemplateError" or not any(isinstance(m.get("content"), list) for m in messages):
|
| 187 |
+
raise
|
| 188 |
+
text = apply(_flatten(_clean(messages)))
|
| 189 |
|
| 190 |
if add_bos and tok.bos_token and not text.startswith(tok.bos_token):
|
| 191 |
text = tok.bos_token + text
|