Skip to content

Commit 025e7fa

Browse files
committed
fix: modify the gemma3 chat template to be compatible with openai api
1 parent 1b45588 commit 025e7fa

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

llama_cpp/llama_chat_format.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -3409,7 +3409,7 @@ class Gemma3ChatHandler(Llava15ChatHandler):
34093409
"{{ message['content'] | trim }}"
34103410
"{%- elif message['content'] is iterable -%}"
34113411
"{%- for item in message['content'] -%}"
3412-
"{%- if item['type'] == 'image' -%}"
3412+
"{%- if item['type'] == 'image_url' -%}"
34133413
"{{ '<start_of_image>' }}"
34143414
"{%- elif item['type'] == 'text' -%}"
34153415
"{{ item['text'] | trim }}"
@@ -3449,21 +3449,6 @@ def split_text_on_image_urls(text: str, image_urls: List[str]):
34493449
remaining = ""
34503450
return split_text
34513451

3452-
@staticmethod
3453-
def get_image_urls(messages: List[llama_types.ChatCompletionRequestMessage]):
3454-
image_urls: List[str] = []
3455-
for message in messages:
3456-
if message["role"] == "user":
3457-
if message.get("content") is None:
3458-
continue
3459-
for content in message["content"]:
3460-
if isinstance(content, dict) and content.get("type") == "image":
3461-
if isinstance(content.get("image"), dict) and isinstance(content["image"].get("url"), str):
3462-
image_urls.append(content["image"]["url"])
3463-
elif isinstance(content.get("url"), str):
3464-
image_urls.append(content["url"])
3465-
return image_urls
3466-
34673452
def eval_image(self, llama: llama.Llama, image_url: str):
34683453
import llama_cpp
34693454

llama_cpp/llava_cpp.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ def clip_image_batch_encode(
245245
ctx: clip_ctx_p,
246246
n_threads: c_int,
247247
imgs: "_Pointer[clip_image_f32_batch]",
248-
vec: c_void_p
248+
vec: c_void_p,
249+
/,
249250
) -> bool:
250251
...
251252

0 commit comments

Comments
 (0)