Skip to content

Commit 0f278d9

Browse files
committed
better image handling in jinja
1 parent b962335 commit 0f278d9

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

koboldcpp.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,6 +3314,31 @@ def raise_exception(msg):
33143314
for m in messages:
33153315
if m.get("content") is None:
33163316
m["content"] = ""
3317+
# fix image placeholders, erase them and slap a reference onto the turn text message
3318+
mediacount = 1
3319+
for m in messages:
3320+
if isinstance(m.get("content"), list):
3321+
normalized = []
3322+
turn_text = ""
3323+
media_text = ""
3324+
for item in m["content"]:
3325+
if item.get("type")=="text":
3326+
turn_text += item.get("text","")
3327+
for item in m["content"]:
3328+
if item.get("type")=="text":
3329+
pass
3330+
elif item.get("type")=="image_url" or item.get("type")=="image":
3331+
media_text += f"\n(Attached Image {mediacount})\n"
3332+
mediacount += 1
3333+
elif item.get("type")=="input_audio":
3334+
media_text += f"\n(Attached Audio {mediacount})\n"
3335+
mediacount += 1
3336+
else:
3337+
normalized.append(item)
3338+
turn_text = media_text + turn_text
3339+
if turn_text:
3340+
normalized.append({"type": "text","text": turn_text})
3341+
m["content"] = normalized
33173342
for m in messages: # Fix tool_calls arguments and content if parsable
33183343
if m.get("tool_calls"):
33193344
for tc in m["tool_calls"]:

0 commit comments

Comments
 (0)