Skip to content

Commit 5d52b03

Browse files
kossumokaris
authored andcommitted
fix: modify the gemma3 chat template to be compatible with openai api
1 parent 60443dd commit 5d52b03

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
@@ -3564,7 +3564,7 @@ class Gemma3ChatHandler(Llava15ChatHandler):
35643564
"{{ message['content'] | trim }}"
35653565
"{%- elif message['content'] is iterable -%}"
35663566
"{%- for item in message['content'] -%}"
3567-
"{%- if item['type'] == 'image' -%}"
3567+
"{%- if item['type'] == 'image_url' -%}"
35683568
"{{ '<start_of_image>' }}"
35693569
"{%- elif item['type'] == 'text' -%}"
35703570
"{{ item['text'] | trim }}"
@@ -3604,21 +3604,6 @@ def split_text_on_image_urls(text: str, image_urls: List[str]):
36043604
remaining = ""
36053605
return split_text
36063606

3607-
@staticmethod
3608-
def get_image_urls(messages: List[llama_types.ChatCompletionRequestMessage]):
3609-
image_urls: List[str] = []
3610-
for message in messages:
3611-
if message["role"] == "user":
3612-
if message.get("content") is None:
3613-
continue
3614-
for content in message["content"]:
3615-
if isinstance(content, dict) and content.get("type") == "image":
3616-
if isinstance(content.get("image"), dict) and isinstance(content["image"].get("url"), str):
3617-
image_urls.append(content["image"]["url"])
3618-
elif isinstance(content.get("url"), str):
3619-
image_urls.append(content["url"])
3620-
return image_urls
3621-
36223607
def eval_image(self, llama: llama.Llama, image_url: str):
36233608
import llama_cpp
36243609

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)