Skip to content

Commit c7e20d3

Browse files
committed
Add strftime_now function into Jinja2ChatFormatter Class for gpt-oss and gemma3 chat_template need
1 parent b5068ae commit c7e20d3

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
import ctypes
77
import dataclasses
8+
import datetime
89
import random
910
import string
1011

@@ -60,6 +61,11 @@
6061
LLAMA4_INSTRUCT_BOS_TOKEN = "<|begin_of_text|>"
6162
LLAMA4_INSTRUCT_EOS_TOKEN = "<|eot|>"
6263

64+
# Source: https://huggingface.co/openai/gpt-oss-20b/blob/main/tokenizer_config.json
65+
GPT_OSS_BOS_TOKEN = "<|startoftext|>"
66+
GPT_OSS_EOS_TOKEN = "<|return|>"
67+
GPT_OSS_PAD_TOKEN = "<|endoftext|>"
68+
6369
### Chat Completion Handler ###
6470

6571

@@ -240,11 +246,18 @@ def __call__(
240246
def raise_exception(message: str):
241247
raise ValueError(message)
242248

249+
def strftime_now(format_string="%Y-%m-%d %H:%M:%S"):
250+
"""
251+
Returns the current time formatted as a string.
252+
"""
253+
return datetime.datetime.now().strftime(format_string)
254+
243255
prompt = self._environment.render(
244256
messages=messages,
245257
eos_token=self.eos_token,
246258
bos_token=self.bos_token,
247259
raise_exception=raise_exception,
260+
strftime_now=strftime_now,
248261
add_generation_prompt=self.add_generation_prompt,
249262
functions=functions,
250263
function_call=function_call,

0 commit comments

Comments
 (0)