Skip to content

Commit dec983d

Browse files
kossumokaris
authored andcommitted
fix: modify the gemma3 chat template to be compatible with openai api
1 parent 252266f commit dec983d

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,7 +3573,7 @@ class Gemma3ChatHandler(Llava15ChatHandler):
35733573
"{{ message['content'] | trim }}"
35743574
"{%- elif message['content'] is iterable -%}"
35753575
"{%- for item in message['content'] -%}"
3576-
"{%- if item['type'] == 'image' -%}"
3576+
"{%- if item['type'] == 'image_url' -%}"
35773577
"{{ '<start_of_image>' }}"
35783578
"{%- elif item['type'] == 'text' -%}"
35793579
"{{ item['text'] | trim }}"
@@ -3613,21 +3613,6 @@ def split_text_on_image_urls(text: str, image_urls: List[str]):
36133613
remaining = ""
36143614
return split_text
36153615

3616-
@staticmethod
3617-
def get_image_urls(messages: List[llama_types.ChatCompletionRequestMessage]):
3618-
image_urls: List[str] = []
3619-
for message in messages:
3620-
if message["role"] == "user":
3621-
if message.get("content") is None:
3622-
continue
3623-
for content in message["content"]:
3624-
if isinstance(content, dict) and content.get("type") == "image":
3625-
if isinstance(content.get("image"), dict) and isinstance(content["image"].get("url"), str):
3626-
image_urls.append(content["image"]["url"])
3627-
elif isinstance(content.get("url"), str):
3628-
image_urls.append(content["url"])
3629-
return image_urls
3630-
36313616
def eval_image(self, llama: llama.Llama, image_url: str):
36323617
import llama_cpp
36333618

llama_cpp/llava_cpp.py

Lines changed: 2 additions & 1 deletion
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)